APP下载

基于双向多层转换编解码的诗自动生成

2021-04-18杨泰康杨婉霞刘燕胡智喻王巧珍徐明杰

软件工程 2021年4期

杨泰康 杨婉霞 刘燕 胡智喻 王巧珍 徐明杰

摘  要:中国古诗因其严谨的平仄、押韵结构,精练传神的用词成为文本自动生成领域的挑战问题之一。本文基于双向多层转换编解码的空间向量,结合Attention机制建立了循环神经网络结构的诗自动生成模型。为解决自动生成诗的主题发散性问题,模型在生成每句诗时均增加了关键词约束。此外,为了增强诗句之间的对仗性和语义的连贯性,模型双向多层转换编解码的词嵌入式输入添加了诗句的对齐向量。实验结果表明,相比于以词转换为向量的词嵌入式的诗自动生成模型,本文设计的基于BERT的对齐向量输入模型生成的诗不仅在机器评估和人工评估中性能较优,而且生成诗句相邻句子的相关性也最好。这也进一步说明,当模型的输入向量能充分表达诗词的格式、内容和语义时,双向多层转换编解码的向量表示,即Attention机制+循环神经网络构建的诗生成模型可以生成较接近人工作的诗。

关键词:Attention机制;双向多层转换编解码;诗;自动生成;循环神经网络

中图分类号:TP391     文献标识码:A

文章编号:2096-1472(2021)-04-15-07

Abstract: Chinese ancient poems have become one of the challenges in the field of automatic text generation because of their tonal patterns, rhyming structure, and vivid words. This paper proposes to establish an automatic poem generation model with a recurrent neural network structure. This model is combined with Attention and is based on space vector of two-way multi-layer conversion codec. In order to solve the problem of divergence of automatically generated poems, the model adds keyword constraints when generating each poem. In addition, in order to enhance antithesis between verses and semantic coherence, word embedded input of the model's two-way multi-layer conversion encoding and decoding adds alignment vector of the poem. The experimental results show that compared with word-embedded poem automatic generation model in which words are converted into vectors, poems generated by BERT-based aligned vector input model proposed in this paper, not only perform better in machine and manual evaluation, but also generate poetic sentences. The correlation between adjacent sentences and the generated verse is also the best. This also further shows that when input vector of the model can fully express the format, content and semantics of the poem, vector representation of the two-way multi-layer conversion codec, the Attention Mechanism + cyclic neural network construction of poem generation model can generate poems closer to human's works.

Keywords: Attention Mechanism; two-way multi-layer conversion codec; poem; automatic generation; Recurrent Neural Network

1   引言(Introduction)

中國古诗词源远流长,大约有2000多年的历史,是中国古典文学中最璀璨的明珠。不同时期的中国古诗词主要发展为唐诗、宋词和元曲等不同类型。这些古典诗词中,以格律诗为主,主要是五言和七言的绝句和律诗,其突出特点是结构严谨,字数、行数、平仄、用韵都有一定的限制。例如,律诗一般讲究平仄和押韵、押韵和对仗,其中最核心的是它的韵律,即所谓的押韵,就是在诗词中的规定位置(一般在句末)放置相同韵部的字,以使声韵和谐。……

登录APP查看全文