End-to-end style-conditioned poetry generation: What does it take to learn from examples alone? (2021)

Abstract: In this work, we design an end-to-end model for poetry generation based on conditioned recurrent neural network (RNN) language models whose goal is to learn stylistic features (poem length, sentiment, alliteration, and rhyming) from examples alone. We show this model successfully learns the ‘meaning’ of length and sentiment, as we can control it to generate longer or shorter as well as more positive or more negative poems. However, the model does not grasp sound phenomena like alliteration and rhyming, but instead exploits low-level statistical cues. Possible reasons include the size of the training data, the relatively low frequency and difficulty of these sublexical phenomena as well as model biases. We show that more recent GPT-2 models also have problems learning sublexical phenomena such as rhyming from examples alone.

## introduction poetry is a very old form of human language use which is deeply embedded in the heritage of many cultures @xcite . it is characterized by refined, creative, and sublime expressions and linguistic structure. thus, it comes as little surprise that automatic poetry generation has long captivated artificial intelligence (ai) researchers @xcite , for any general solution to this task will have assuredly brought us a step closer to understanding human creativity. poetry generation systems may have manifold applications. for example, an ai tool that could assist songwriters in composing lyrics to a given tune, or even generate them entirely automatically, would have commercial potential. besides such entertainment-oriented applications, producing tools for poetry generation will necessarily involve the development of poetry analysis tools -since generation and analysis are complementary aspects of poetry @xcite which may prove useful in their own right. and the production and application of these analysis tools could result in insights into the structural and aesthetic features that distinguish humanpenned poetry from its artificially produced counterpart. figure 1 : example of alliteration (red), a (near) rhyme (blue), and metre (black/grey). this is the first stanza of 'i felt a funeral, in my brain' by emily dickinson. the rhyme scheme is 'abcb', the overall lexical sentiment of the stanza is negative (many words are associated with negative sentiment), and the time period is the 19th century. a crucial factor when producing poetry (either by humans or automatically) is style. while definitions of style have varied considerably over time, space, and fields of study @xcite , there is widespread agreement that the study of literary form, not (just) content, is what allows us to determine the criteria for aesthetic appreciation and impact. that is, it is formal or stylistic features that often distinguish sophisticated, effectual, or simply 'good' poetry from poetry that is pedestrian, mundane, or just plain 'bad' @xcite @xcite @xcite . in this work, we consider the problem of styleconditioned poetry generation, where the user may specify stylistic factors that the generated text has to fulfil. our stylistic factors include rhyme, alliteration, sentiment, text length, and time period. examples of some of our stylistic features (particularly rhyme and alliteration) can be found in figure 1 . (we include metre in the example, but do not consider it in the experiments.) in generating poetry conditioned upon stylistic factors, we explore a theme in the automatic gen-eration of poetry that we believe will dominate the field in the upcoming years: end-to-end generation of formal poetry from examples alone, without the need for human involvement in designing the model or filtering its output (e.g., via hard-coded stylistic constraints on rhyme, alliteration, etc.). we believe advances in this task serve as an indicator of the maturity of natural language processing (nlp) systems as they progress towards true ai. indeed, the recent success of gpt-3 @xcite with its focus on few-shot learning (i.e., learning from a few illustrative examples, even without model updating) is inspiration for our work to design poetry generation models that learn relevant stylistic features without any other form of human intervention. we find that, while our models can capture sentiment, time epoch, and text length, they have trouble learning intricate phonetic stylistic features from examples alone, instead learning low-level statistical cues that are weakly correlated with these target features. this holds both for a classical rnn language model and more recent transformer models (gpt-2). we take this as a negative result and as a challenge for future poetry generation systems, viz., to be able to produce typical relevant stylistic factors of poetry without hard-coding them into the model architecture. ## related work poetry analysis. computational analysis of poetry has been concerned largely with formal features such as metre @xcite @xcite , rhyme @xcite , and enjambment @xcite . more recently, higher-level phenomena, including semantic coherence @xcite , metaphor @xcite , and diachronic analysis of tropes @xcite have come into focus. @xcite annotate poetry for fine-grained aesthetic emotion categories elicited in readers. ## models our goal is to design an end-to-end poetry generation model that learns to associate a desired style feature vector with poetic content and form purely inductively, using examples rather than hand-coded knowledge about what rhyming, alliteration, metre, and sentiment are. to do so, we implement a conditioned language model that samples the next word +1 to be generated conditioned on the history of past words 0 , . . . , and a style constraint . that is, it samples +1 from the conditional distribution ( +1 | 0 , 1 , . . . , , ). we implement the model in this formula by a unidirectional rnn language model. at every time step, the rnn predicts the next word to be generated by sampling from a softmax distribution over the whole vocabulary, taking the current word vector w as well as the current history vector h , which summarizes all past inputs, into account. the model starts generation from a special input token, 'sos', and generates until it encounters an end-of-sentence token 'eos'. to take the context into account, we encode it as a feature vector c and concatenate it to every input representation. while there are other possible ways of including c, our way constantly 'reminds' the model of the style context, which we hope better enforces that style in the output. the model is illustrated in figure 2 . our rnn language model also uses character-level information to build input representations, which may help it to generalize to rare words or sublexical phenomena, such as rhyming. our implementation is taken from that of @xcite . for the conditions , we consider the following: rhyming: how much rhyming is present in a base unit (e.g., a stanza or full poem) of poetry? we measure the degree of rhyming by using a supervised rhyme model based on character-level siamese bidirectional long short-term memory (bi-lstm) networks @xcite , available for english and german. we count both internal and end rhymes as contributing to the rhyme level of a base unit of poetry. alliteration: alliteration is a device, often associated with humour @xcite , where consecutive words begin with the same sound or sounds. as a character does not uniquely specify a sound in most writing systems (cf. cat and chase), it is not sufficient to compare the first characters of the words. instead, we use the cmu sphinx sequence-to-sequence graphemeto-phoneme toolkit for converting words into a phonemic representation and then check whether subsequent words start with the same phoneme. we measure the degree of alliteration by counting how many alliterating word sequences occur within a base unit of poetry. sentiment: to determine the sentiment of a base unit of poetry, we use a lexicon lookup approach. for english, we use the opinion lexicon developed by @xcite and for german, we use the german polarity clues word lists by @xcite . the english lexicon consists of 2,007 positive and 4,782 negative words and the german lexicon consists of 17,627 positive and 19,962 negative words. in each base unit of poetry, we count the number of words that appear in the positive and negative lists of the lexicon, respectively, and then calculate the difference between these two numbers. the final result is normalized by dividing by the number of total matches for this unit, resulting in the @xmath0, where is the number of positive words found and is the number of negative words found. for instance, if four words of the unit were found in the positive list and six words in the negative list, the final rating is -2/10 = -0.2. https://github.com/cmusphinx/g2p-seq2seq ## concluding remarks traditional, 'formal' poetry is characterized by intricate form that often expresses itself on the sound level: among the key features are rhyme, metre, and alliteration. computational treatments typically handle these phenomena by hard-coding them as in purely symbolic ai, by exploiting datasetspecific properties @xcite , or by having models pay special attention to the phenomena in question (e.g., making the models concentrate on the character-level structure of line-ending words) @xcite . however, as we show, current models still seem unable to learn sound-level stylistic aspects from examples alone, without priming them, and even when we specifically condition on such features. this raises the question of where this discrepancy between human and machine text processing @xcite comes from and how it can be addressed in the general case. we envision several solutions for future work: it is possible that end-to-end modelling of phonetic stylistic features is an emergent phenomenon that appears once dataset sizes are large enough; it is also possible that datasets need to be sufficiently clean (e.g., containing only very few different rhyming schemes); or that new model architectures, which do not operate on words or sublexical units, are required @xcite .