metadata
language:
- zh
tags:
- songnet
- pytorch
- zh
- Text2Text-Generation
license: apache-2.0
widget:
- text: 丹枫江冷人初去
SongNet for Chinese Couplet(songnet-base-chinese-couplet) Model
SongNet中文对联生成模型
songnet-base-chinese-couplet
evaluate couplet test data:
The overall performance of T5 on couplet test:
input_text | target_text | pred |
---|---|---|
春回大地,对对黄莺鸣暖树 | 日照神州,群群紫燕衔新泥 | 福至人间,家家紫燕舞和风 |
在Couplet测试集上生成结果满足字数相同、词性对齐、词面对齐、形似要求,针对性的SongNet网络结构,在语义对仗工整和平仄合律上的效果明显优于T5和GPT2等模型。
SongNet的网络结构:
Usage
本项目开源在文本生成项目:textgen,可支持SongNet模型,通过如下命令调用:
Install package:
pip install -U textgen
import sys
sys.path.append('..')
from textgen.language_modeling import SongNetModel
model = SongNetModel(model_type='songnet', model_name='songnet-base-chinese-couplet')
sentences = [
"严蕊<s1>如梦令<s2>道是梨花不是。</s>道是杏花不是。</s>白白与红红,别是东风情味。</s>曾记。</s>曾记。</s>人在武陵微醉。",
"<s1><s2>一句相思吟岁月</s>千杯美酒醉风情",
"<s1><s2>几树梅花数竿竹</s>一潭秋水半屏山"
"<s1><s2>未舍东江开口咏</s>且施妙手点睛来",
"<s1><s2>一去二三里</s>烟村四五家",
]
print("inputs:", sentences)
print("outputs:", model.generate(sentences))
sentences = [
"<s1><s2>一句____月</s>千杯美酒__情",
"<s1><s2>一去二三里</s>烟村__家</s>亭台__座</s>八__枝花",
]
print("inputs:", sentences)
print("outputs:", model.fill_mask(sentences))
模型文件组成:
t5-chinese-couplet
├── pytorch_model.bin
└── vocab.txt
训练数据集
中文对联数据集
数据格式:
head -n 1 couplet_files/couplet/train/in.txt
晚 风 摇 树 树 还 挺
head -n 1 couplet_files/couplet/train/out.txt
晨 露 润 花 花 更 红
如果需要训练SongNet模型,请参考https://github.com/shibing624/textgen/blob/main/examples/language_generation/training_zh_songnet_demo.py
Citation
@software{textgen,
author = {Xu Ming},
title = {textgen: Implementation of Text Generation models},
year = {2022},
url = {https://github.com/shibing624/textgen},
}