【发布时间】:2021-08-23 08:09:10
【问题描述】:
我已按照本教程使用 BERT 从 Hugging Face 进行掩码语言建模,但我不确定如何实际部署模型。
教程:https://github.com/huggingface/notebooks/blob/master/examples/language_modeling.ipynb
我已经使用自己的数据集训练了模型,效果很好,但我不知道如何实际使用该模型,因为笔记本没有包含如何执行此操作的示例,很遗憾。
Example of what I want to do with my trained model
在 Hugging Face 网站上,这是示例中使用的代码;因此,我想用我的模型做这件事:
>>> 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'}
任何关于如何做到这一点的帮助都会很棒。
【问题讨论】:
标签: python nlp bert-language-model huggingface-transformers