Downloads · 30 days
156
1% of all-time downloads
yuanzhoulvpi/gpt2_chinese
gpt2_chinese is a text generation model from yuanzhoulvpi. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
1. 15G的中文语料 2. 31亿个tokens 3. 一张3090显卡 4. 训练60多个小时
Downloads · 30 days
156
1% of all-time downloads
All-time downloads
30.4K
Public
Repo size
1.7 GB
Likes
22
Public
Click a slice to open those files.
.pt817 MB · 66%
From the Hugging Face model README
最终训练出一个中文版本的gpt2,如果有想了解如何训练中文gpt2的,可以查看这个教程
https://github.com/yuanzhoulvpi2017/zero_nlp/tree/main/chinese_gpt2
from transformers import GPT2LMHeadModel, AutoTokenizer
model_name_or_path = "yuanzhoulvpi/gpt2_chinese"#"checkpoint-36000"
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
# add the EOS token as PAD token to avoid warnings
model = GPT2LMHeadModel.from_pretrained(model_name_or_path, pad_token_id=tokenizer.eos_token_id)
txt = """\
你是谁
"""
# encode context the generation is conditioned on
input_ids = tokenizer.encode(txt, return_tensors='pt')
# set no_repeat_ngram_size to 2
beam_output = model.generate(
input_ids,
max_length=200,
num_beams=5,
no_repeat_ngram_size=2,
early_stopping=True
)
print("Output:\n" + 100 * '-')
print(tokenizer.decode(beam_output[0], skip_special_tokens=True))
Output:
----------------------------------------------------------------------------------------------------
你 是 谁?, 简 单 的 描 述 是, 答 案 是 你 好 , 我 叫 , 是 一 名 美 籍 华 裔 女 演 员 , 出 生 于 美 国 加 利 福 尼 亚 州 的 一 个 犹 太 人 家 庭 。 她 的 父 母 都 是 工 程 师 , 母 亲 是 医 生 , 父 亲 则 是 律 师 。 是 加 州 大 学 伯 克 利 分 校 的 教 授 , 也 是 的 创 始 人 之 一 , 曾 在 《 纽 约 时 报 》 上 发 表 过 一 篇 文 章 , 引 起 了 广 泛 的 关 注 。 文 中 写 道 : 我 从 小 就 喜 欢 音 乐 , 并 且 在 学 校 里 学 到 了 很 多 乐 理 知 识 , 但 是 我 并 不 知 道 自 己 到 底 想 要 什 么 , 因 为 我 觉 得 这 个 世 界 上 没 有 任 何 东 西 可 以 比 得 上 它 。