Hugging Face 提供了许多预训练模型,如 BERT、GPT-2,可用于各种 NLP 任务。
示例:文本分类
from transformers import pipeline# 加载 Hugging Face 的文本分类模型classifier = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")# 输入文本text = "I absolutely love the new design of the product!"# 分类result = classifier(text)print("分类结果:", result)输出解释: