安装Transformers框架分为以下几个步骤:
- Environmental Preparation:要求Python 3.9+环境,推荐使用虚拟环境
- Create a virtual environment:
Windows.python -m venv transformers_env
Linux/Mac.source transformers_env/bin/activate
- 基础安装:
pip install transformers
- 可选安装:
开发版:pip install git+https://github.com/huggingface/transformers
GPU支持:需安装CUDA驱动
验证安装可以执行以下测试代码:
from transformers import pipeline
print(pipeline('sentiment-analysis')('hugging face is awesome'))
预期输出类似:{‘label’: ‘POSITIVE’, ‘score’: 0.9998}
This answer comes from the articleTransformers: open source machine learning modeling framework with support for text, image and multimodal tasksThe