supermy/c2m-mt5
313
文言文 to 现代文
Model description
How to use
使用 pipeline 调用模型:
>>> from transformers import pipeline
>>> model_checkpoint = "supermy/c2m-mt5"
>>> translator = pipeline("translation",
model=model_checkpoint,
num_return_sequences=1,
max_length=52,
truncation=True,)
>>> translator("往者不可谏,来者犹可追。")
[{'translation_text': '过 去 的 事 情 不能 劝 谏 , 未来 的 事 情 还 可以 追 回 来 。 如 果 过 去 的 事 情 不能 劝 谏 , 那 么 , 未来 的 事 情 还 可以 追 回 来 。 如 果 过 去 的 事 情'}]
>>> translator("福兮祸所伏,祸兮福所倚。",do_sample=True)
[{'translation_text': '幸 福 是 祸 患 所 隐 藏 的 , 灾 祸 是 福 祸 所 依 托 的 。 这 些 都 是 幸 福 所 依 托 的 。 这 些 都 是 幸 福 所 带 来 的 。 幸 福 啊 , 也 是 幸 福'}]
>>> translator("成事不说,遂事不谏,既往不咎。", num_return_sequences=1,do_sample=True)
[{'translation_text': '事 情 不 高 兴 , 事 情 不 劝 谏 , 过 去 的 事 就 不 会 责 怪 。 事 情 没 有 多 久 了 , 事 情 没 有 多 久 , 事 情 没 有 多 久 了 , 事 情 没 有 多'}]
>>> translator("逝者如斯夫!不舍昼夜。",num_return_sequences=1,max_length=30)
[{'translation_text': '逝 去 的 人 就 像 这 样 啊 , 不分 昼夜 地 去 追 赶 它 们 。 这 样 的 人 就 不 会 忘 记'}]
Here is how to use this model to get the features of a given text in PyTorch:
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("supermy/c2m-mt5")
model = AutoModelForSeq2SeqLM.from_pretrained("supermy/c2m-mt5")
text = "用你喜欢的任何文本替换我。"
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)Training data
非常全的文言文(古文)-现代文平行语料,基本涵盖了大部分经典古籍著作。
原始爬取的数据是篇章级对齐,经过脚本分句(按照句号分号感叹号问号划分)以及人工校对,形成共计约96万句对。目录bitext下是文言文-现代文对齐的平行数据。此外,目录source下是文言文单语数据,target下是现代文单语数据,这两个目录下的文件内容按行对齐。
以下为数据统计信息。其中,短篇章中包括了《论语》、《孟子》、《左传》等篇幅较短的古籍,已和《资治通鉴》合并。
《短篇章和资治通鉴》中各书籍统计如下(此部分数据量不完全准确):
如果您使用该语料库,请注明出处:https://github.com/NiuTrans/Classical-Modern
感谢为该语料库做出贡献的成员:丁佳鹏、杨文权、刘晓晴、曹润柘、罗应峰。
Training procedure
在英伟达16G显卡训练了 4 天整,共计68 次。
文言文数据集 训练数据. 模型 MT5
[INFO|trainer.py:1628] 2022-12-15 16:08:36,696 >> ***** Running training *****
[INFO|trainer.py:1629] 2022-12-15 16:08:36,696 >> Num examples = 967255
[INFO|trainer.py:1630] 2022-12-15 16:08:36,697 >> Num Epochs = 6
[INFO|trainer.py:1631] 2022-12-15 16:08:36,697 >> Instantaneous batch size per device = 12
[INFO|trainer.py:1632] 2022-12-15 16:08:36,697 >> Total train batch size (w. parallel, distributed & accumulation) = 12
[INFO|trainer.py:1633] 2022-12-15 16:08:36,697 >> Gradient Accumulation steps = 1
[INFO|trainer.py:1634] 2022-12-15 16:08:36,697 >> Total optimization steps = 483630
[INFO|trainer.py:1654] 2022-12-15 16:08:36,698 >> Continuing training from checkpoint, will skip to saved global_step
[INFO|trainer.py:1655] 2022-12-15 16:08:36,698 >> Continuing training from epoch 5
[INFO|trainer.py:1656] 2022-12-15 16:08:36,698 >> Continuing training from global step 465000
{'loss': 5.2906, 'learning_rate': 1.8743667679837894e-06, 'epoch': 5.78}
{'loss': 5.3196, 'learning_rate': 1.8226743584971985e-06, 'epoch': 5.78}
{'loss': 5.3467, 'learning_rate': 6.513243595310464e-08, 'epoch': 5.99}
{'loss': 5.3363, 'learning_rate': 1.344002646651366e-08, 'epoch': 6.0}
{'train_runtime': 6277.5234, 'train_samples_per_second': 924.494, 'train_steps_per_second': 77.042, 'train_loss': 0.2044413571775476, 'epoch': 6.0}
***** train metrics *****
epoch = 6.0
train_loss = 0.2044
train_runtime = 1:44:37.52
train_samples = 967255
train_samples_per_second = 924.494
train_steps_per_second = 77.042
12/15/2022 17:53:23 - INFO - __main__ - *** Evaluate ***
[INFO|trainer.py:2920] 2022-12-15 17:53:23,729 >> ***** Running Evaluation *****
[INFO|trainer.py:2922] 2022-12-15 17:53:23,729 >> Num examples = 200
[INFO|trainer.py:2925] 2022-12-15 17:53:23,729 >> Batch size = 12
100%|██████████| 17/17 [00:07<00:00, 2.29it/s]
[INFO|modelcard.py:443] 2022-12-15 17:53:32,737 >> Dropping the following result as it does not have all the necessary fields:
{'task': {'name': 'Translation', 'type': 'translation'}, 'metrics': [{'name': 'Bleu', 'type': 'bleu', 'value': 0.7225}]}
***** eval metrics *****
epoch = 6.0
eval_bleu = 0.7225
eval_gen_len = 12.285
eval_loss = 6.6782
eval_runtime = 0:00:07.77
eval_samples = 200
eval_samples_per_second = 25.721
eval_steps_per_second = 2.186