一键安装tansformer

目录

视频链接:https://www.bilibili.com/video/BV1Sd4y1v7hb/?spm_id_from=333.999.0.0&vd_source=7a32fe7f80f09236fc113c9c6bde1c81

1、conda创建虚拟环境

conda create -n transformer python=3.8.10

2、启动虚拟环境

conda activate transformer

3、!!!不要下载最新版本,使用如下命令

先使用第一种,若成功则跳到第三步

pip3 install farm-haystack -i https://pypi.tuna.tsinghua.edu.cn/simple 
pip install vit-pytorch -i https://pypi.tuna.tsinghua.edu.cn/simple 

若失败,则使用以下命令

conda install -c huggingface transformers

4、测试transformer是否安装成功

from transformers import pipeline

nlp = pipeline("question-answering")

context = "Extractive Question Answering is the task of extracting an answer from a text given a question. An example of a question answering dataset is the SQuAD dataset, which is entirely based on that task. If you would like to fine-tune a model on a SQuAD task, you may leverage the `run_squad.py`."

print(nlp(question="What is extractive question answering?", context=context))
print(nlp(question="What is a good example of a question answering dataset?", context=context))

若输出如下结果,则安装正确
在这里插入图片描述

5、若出现如下图所示错误
错误一

RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback):
libssl.so.10: cannot open shared object file: No such file or directory

解决方案:

pip3 install farm-haystack

6、开源项目

https://github.com/lucidrains/vit-pytorch

7、conda移除环境

conda remove -n transformer --all

你可能感兴趣的:(transformer,ubuntu,python,pytorch,transformer)