我遵循了本教程,使用BERT从拥抱脸部开始进行蒙面语言建模,但我不确定如何实际部署该模型
教程:https://github.com/huggingface/notebooks/blob/master/examples/language_modeling.ipynb
我用自己的数据集训练了模型,效果很好,但我不知道如何实际使用该模型,遗憾的是,笔记本中没有关于如何使用该模型的示例
Example of what I want to do with my trained model
在拥抱脸网站上,这是示例中使用的代码;因此,我想用我的模型做这件事:
>>> from transformers import pipeline
>>> unmasker = pipeline('fill-mask', model='bert-base-uncased')
>>> unmasker("Hello I'm a [MASK] model.")
[{'sequence': "[CLS] hello i'm a fashion model. [SEP]",
'score': 0.1073106899857521,
'token': 4827,
'token_str': 'fashion'},
{'sequence': "[CLS] hello i'm a role model. [SEP]",
'score': 0.08774490654468536,
'token': 2535,
'token_str': 'role'},
{'sequence': "[CLS] hello i'm a new model. [SEP]",
'score': 0.05338378623127937,
'token': 2047,
'token_str': 'new'},
{'sequence': "[CLS] hello i'm a super model. [SEP]",
'score': 0.04667217284440994,
'token': 3565,
'token_str': 'super'},
{'sequence': "[CLS] hello i'm a fine model. [SEP]",
'score': 0.027095865458250046,
'token': 2986,
'token_str': 'fine'}
任何关于如何做到这一点的帮助都将是巨大的
这在很大程度上取决于你的任务。您的任务似乎是蒙面语言建模,即预测一个或多个蒙面单词:
今天我吃了。
(比萨饼)或(意大利面)可能同样正确,因此不能使用accuray等度量。但是(水)应该比其他两个更不“正确”。 因此,您通常要做的是检查语言模型在评估数据集上的“惊讶程度”。这个度量称为perplexity。 因此,在对特定数据集上的模型进行微调之前和之后,您会计算复杂度,并且您希望在微调之后复杂度会更低。模型应该更多地用于您的特定词汇表等,这就是您测试模型的方式
如您所见,他们计算了您提到的教程中的困惑:
要预测样本,您需要标记这些样本并准备模型的输入。填充遮罩管道可以为您执行以下操作:
这将导致以下输出:
相关问题 更多 >
编程相关推荐