当前位置:   article > 正文

一键安装tansformer_runtimeerror: failed to import transformers.pipeli

runtimeerror: failed to import transformers.pipelines because of the followi

视频链接: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
  • 1

2、启动虚拟环境

conda activate transformer
  • 1

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 
  • 1
  • 2

若失败,则使用以下命令

conda install -c huggingface transformers
  • 1

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))

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

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

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
  • 1
  • 2

解决方案:

pip3 install farm-haystack
  • 1

6、开源项目

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

7、conda移除环境

conda remove -n transformer --all
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/887051
推荐阅读
相关标签
  

闽ICP备14008679号