Predicting On New Text With Fine-Tuned Multi-Label Model
This is very much a beginner question. I am trying to load a  fine tuned model for multi-label text classification. Fine-tuned on 11 labels, bert-base-uncased.I just want to feed new text to the model and get the labels predicted to be associated with the text.I have looked everywhere and cannot find an example of how to actually load and use a fine-tuned model on new data after fine tuning is complete.I have the model saved via:model.save_pretrained("fine_tuned_model")I can load the model back with:model = AutoModelForSequenceClassification.from_pretrained("fine_tuned_model", from_tf=False, config=config)From here I am stuck. I have been told to usemodel.predict("text")but when I do I get the following error:'BertForSequenceClassification' object has no attribute 'predict'I hope this makes sense and any help would be greatly appreciated.
2021-12-22T19:32:37Z
Hello and welcome to our ForumI’d suggest you to use theText Classification pipelineinstead.from transformers import pipeline
clf = pipeline("text-classification", fine_tuned_model)
answer = clf("text)
2021-12-23T13:17:37Z
Hey@merve, thank you so much for the suggestion and assistance! The code you provided works but only returns one of my 11 labels per text entered:#Output: [{'label': 'LABEL_7', 'score': 0.9935219883918762}]Is there a way to get the scores for all labels (I have 11) and have the label values mapped to their respective labels? So the output would include 11 returns with scores?For instance, instead of ‘LABEL_7’ it would say ‘Technology’ and so on and so forth.
2021-12-23T14:33:49Z
To get all scores,pipelinehas a parameterclf("text", return_all_scores=True)For the label being LABEL_7, you need to check out theconfig.jsonin your repo. See for exampleid2labelandlabel2idinconfig.json · distilbert-base-uncased-finetuned-sst-2-english at main.
2021-12-23T15:15:31Z
Hey@osanseviero, thank you so much! I really appreciate the kind response!