Journal of Frontiers of Computer Science and Technology ›› 2020, Vol. 14 ›› Issue (6): 1028-1035.DOI: 10.3778/j.issn.1673-9418.1905016

Previous Articles     Next Articles

Custom Generation of Poetry Based on Seq2Seq Model

WANG Lewei, YU Ying, ZHANG Yinglong   

  1. College of Software, East China Jiaotong University, Nanchang 330013, China
  • Online:2020-06-01 Published:2020-06-04

基于Seq2Seq模型的自定义古诗生成

王乐为余鹰张应龙   

  1. 华东交通大学 软件学院,南昌 330013

Abstract:

At present, the generation of ancient poems is mostly based on a single recurrent neural network (RNN) structure. When generating, a starting word needs to be given in advance, and then the starting word is used as the starting point to generate ancient poems. The generation process is poorly controllable and the expected results often fail. Aiming at the above problems, the attention mechanism is introduced into the Seq2Seq model, and training is performed through a self-built data set to implement keyword-based custom ancient poem generation. In the genera-tion phase, a descriptive content is input and the keywords are extracted from it. When the keywords are insu-fficient, word2vec is used to complete keywords effectively. In addition, in view of the difficulty in controlling the ancient poetry genre, a format control character is added to the Encoder of the Seq2Seq model, which effectively solves the randomness of genre selection caused by previous model when generating ancient poems. Experiments show that the proposed model achieves the expected generation effect well.

Key words: sequence-to-sequence model, recurrent neural network (RNN), poetry generation, attention mechanism

摘要:

当前,古诗句生成任务大多基于单一的循环神经网络(RNN)结构,在生成时需事先给定一个起始字,然后以该起始字为基础进行古诗句生成,生成过程的可控性较差,往往达不到预期效果。针对以上问题,将注意力机制引入Seq2Seq模型,通过自建的数据集进行训练,实现了基于关键字的自定义古诗句生成。在生成阶段,首先输入一段描述性内容,并从中提取出关键字。当关键字不足时,使用word2vec进行有效的关键字补全操作。此外,针对古诗体裁难以控制问题,在Seq2Seq模型中的Encoder端增加格式控制符,有效解决了以往模型在生成古诗时,体裁选择的随机性问题。实验表明,所提出的模型较好地达到了预期的生成效果。

关键词: Seq2Seq模型, 循环神经网络(RNN), 古诗生成, 注意力机制