语言:
许可证: apache-2.0
数据集:
小部件示例:
- 文本: "Bu yazıyı bir bilgisayar yazdı. Yazarken"
上下文: ''
- 文本: "İnternete kolay erişim sayesinde dünya daha da küçüldü. Bunun sonucunda"
上下文: ''
微调后的土耳其语GPT2模型
Türkçe GPT2 Modeli
模型描述
这是一个基于GPT2-Small英语模型的微调版本,额外使用了截至2020年10月28日的土耳其语维基百科文章进行训练。
基于本作品的实时演示见: https://www.metayazar.com/
在此模型上微调的写作器: https://huggingface.co/gorkemgoknar/gpt2-turkish-writer
工作基于Pierre Guillou的教程(见该页面):
(https://github.com/piegu/fastai-projects/blob/master/finetuning-English-GPT2-any-language-Portuguese-HuggingFace-fastaiv2.ipynb)
代码已转换为兼容Fastai 2.X版本。
使用Google Colab进行训练。
更多教程和源码将在后续发布于: https://github.com/gorkemgoknar
当前准确率33%,困惑度:51.88
可用模型:
- [gpt2-small-tuned-tr] (https://huggingface.co/gorkemgoknar/gpt2-small-turkish)
- [gpt2-small-turkish-writer] (https://huggingface.co/gorkemgoknar/gpt2-turkish-writer)
使用范围和限制
使用方法
安装
from transformers import AutoTokenizer, AutoModelWithLMHead
import torch
tokenizer = AutoTokenizer.from_pretrained("gorkemgoknar/gpt2-small-turkish")
model = AutoModelWithLMHead.from_pretrained("gorkemgoknar/gpt2-small-turkish")
tokenizer.model_max_length=1024
model.eval()
生成单个词
text = "Bu yazıyı bilgisayar yazdı."
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs, labels=inputs["input_ids"])
loss, logits = outputs[:2]
predicted_index = torch.argmax(logits[0, -1, :]).item()
predicted_text = tokenizer.decode([predicted_index])
print('输入文本:', text)
print('预测文本:', predicted_text)
生成完整序列
text = "Bu yazıyı bilgisayar yazdı."
inputs = tokenizer(text, return_tensors="pt")
sample_outputs = model.generate(inputs.input_ids,
pad_token_id=50256,
do_sample=True,
max_length=50,
top_k=40,
num_return_sequences=1)
for i, sample_output in enumerate(sample_outputs):
print(">> 生成文本 {}\\\\
\\\\
{}".format(i+1, tokenizer.decode(sample_output.tolist())))
限制与偏差
本模型的训练数据来自土耳其语维基百科。我们知道其中包含大量来自互联网的未过滤内容,远非中立。
训练数据
截至2020年10月28日的土耳其语维基百科文章转储
训练过程
评估结果
周期\\t |
训练损失\\t |
验证损失\\t |
准确率\\t |
困惑度\\t |
时间 |
0\\t |
4.777015\\t |
4.621834\\t |
0.292547\\t |
101.680367\\t |
2:42:05 |
1\\t |
4.509412\\t |
4.403999\\t |
0.305574\\t |
81.777267\\t |
1:09:38 |
2\\t |
4.169529\\t |
4.120755\\t |
0.324908\\t |
61.605747\\t |
1:07:45 |
3\\t |
4.293973\\t |
4.177899\\t |
0.317211\\t |
65.228653\\t |
1:07:02 |
4\\t |
4.049848\\t |
3.949103\\t |
0.338347\\t |
51.888783\\t |
1:05:53 |
#第0周期在Tesla T4上运行,其余在V100上运行