Team Ai
Apppublic

AfaqJamshaid/Text_classification

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
inference.py16 linesDownload Raw Back to root
1from transformers import DistilBertForSequenceClassification, DistilBertTokenizerFast2import torch3import joblib4 5model = DistilBertForSequenceClassification.from_pretrained("model")6tokenizer = DistilBertTokenizerFast.from_pretrained("model")7label_encoder = joblib.load('label_encoder.joblib')8 9def predict(text):10    inputs = tokenizer(text, return_tensors="pt")11    with torch.no_grad():12        outputs = model(**inputs)13        predictions = torch.argmax(outputs.logits, dim=1).numpy()14    decoded_label = label_encoder.inverse_transform(predictions)[0]15    return decoded_label16