所以我没有标签的单词很少,但我需要将它们分为 4-5 类。 我可以明显地说这个测试集可以分类。虽然我没有训练数据所以我需要使用预训练模型来对这些词进行分类。哪种模型适合这种范式?它已经在哪个数据集上接受过训练?
谢谢
最佳答案
我们正在执行的任务称为零样本主题分类 - 预测模型尚未接受过训练的主题。此范式由 Hugging Face 库支持,您可以阅读更多 here .最常见的预训练模型是 Bart Large MNLI - bart-large 的检查点在接受 MNLI dataset 训练后. 这是一个简单的例子,显示了短语“我喜欢热狗”的分类,没有任何初步训练:
首先,请安装 transformers 库:
pip install --upgrade transformers
然后导入并初始化管道:
from transformers import pipeline classifier = pipeline('zero-shot-classification', model='facebook/bart-large-mnli')
输入我们的玩具数据集:
labels = ["artifacts", "animals", "food", "birds"] hypothesis_template = 'This text is about {}.' sequence = "I like hot dogs"
预测标签:
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]}`
可以解释为,模型将最高概率 (0.997..) 分配给标签“食物”,这是正确答案。
关于python - 用于文本分类的预训练模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65262832/