Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/daoyuanli2816/transformer-tutorial-cn
一个transformer模型的简单的中文教程
https://github.com/daoyuanli2816/transformer-tutorial-cn
chinese-simplified huggingface nlp transformer tutorial-code
Last synced: 6 days ago
JSON representation
一个transformer模型的简单的中文教程
- Host: GitHub
- URL: https://github.com/daoyuanli2816/transformer-tutorial-cn
- Owner: DaoyuanLi2816
- Created: 2024-06-20T19:38:14.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-07-12T21:05:30.000Z (4 months ago)
- Last Synced: 2024-11-08T18:07:05.984Z (6 days ago)
- Topics: chinese-simplified, huggingface, nlp, transformer, tutorial-code
- Language: Jupyter Notebook
- Homepage:
- Size: 1.15 MB
- Stars: 17
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Transformer教程
Hi!这是一个transformer模型的简单的中文教程,仓库中包含一个Jupyter Notebook: [Transformer教程.ipynb](transformer教程.ipynb),演示了如何使用Transformer模型,例如GPT-2,进行文本分类任务,使用了Hugging Face的Transformers库。
## 内容
- Transformer模型的介绍和背景
- 模型加载和初始设置
- 使用GPT-2进行文本分类的示例
- 输出结果的解释
- 可视化展示模型结构和训练过程![Intro](./238353467-897cd757-ea1f-492d-aaf9-6d1674177e08.gif)
## Requirement
- Python 3.6+
- Jupyter Notebook
- Hugging Face Transformers 库## 示例
以下是教程中一个使用GPT-2分类单个句子的示例:
```python
from transformers import AutoModelForSequenceClassification, AutoTokenizer, TextClassificationPipeline# 指定模型和分词器
model_name = "gpt2"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)# 创建文本分类管道
text_classifier = TextClassificationPipeline(model=model, tokenizer=tokenizer, return_all_scores=True)# 对单个句子进行分类
result = text_classifier("I love machine learning!")# 输出结果
print(result)
```## 联系方式
如有任何问题或反馈,请随时联系我: [email protected]。
![Intro](./238201079-e379a33a-b428-4385-b44f-3da16e7bac9f.gif)