我有一些没有标签的词语,需要将它们分类成4-5个类别。虽然我没有训练数据,但我可以使用预训练模型对这些单词进行分类。哪个模型适用于这种情况,并且已经在哪个数据集上进行了训练?
谢谢。
我有一些没有标签的词语,需要将它们分类成4-5个类别。虽然我没有训练数据,但我可以使用预训练模型对这些单词进行分类。哪个模型适用于这种情况,并且已经在哪个数据集上进行了训练?
谢谢。
First of all, please install the transformers library:
pip install --upgrade transformers
Then import and initialize the pipeline:
from transformers import pipeline
classifier = pipeline('zero-shot-classification', model='facebook/bart-large-mnli')
Enter our toy dataset:
labels = ["artifacts", "animals", "food", "birds"]
hypothesis_template = 'This text is about {}.'
sequence = "I like hot dogs"
Predict the label:
prediction = classifier(sequence, labels, hypothesis_template=hypothesis_template, multi_class=True)
print(prediction)
`{'sequence': 'i like hot dogs',
'labels': ['food', 'animals', 'artifacts', 'birds'],
'scores': [0.9971900582313538, 0.00529429130256176, 0.0020991512574255466,
0.00023589911870658398]}`