这个板块给出一些已经微调完全的模型示例,主要有两种方式:pipelines和tokenizer。
如果你要针对性的进行微调,可以参考示例中的run_$TASK.py
首先是 pipelines 方式。
以文本分类为例,代码如下
import time
from transformers import pipeline
nlp = pipeline("sentiment-analysis")
start = time.time()
print(nlp("I hate you"))
print(nlp("I don't know why you don't hate me"))
end = time.time()
print('It spends %s' % (end - start))
运行结果如下:
[{'label': 'NEGATIVE', 'score': 0.9991129}]
[{'label': 'POSITIVE', 'score': 0.8587495}]
It spends 0.06400585174560547
这里值得说明的是:
pipeline() 会将对应的模型下载到默认的_cache路径下,在windows系统中默认为C盘用户目录下的cache文件夹下。
暂时还没有找到如何更改pipeline方式下 模型下载路径。
如果是tokenizer方式,可以通过 cache_dir 参数修改 模型下载或者加载路径。
附:pipeline的相关说明: