Skip to content

Train a recurrent neural network with the corpus of a given author to generate poems imitating his/her style.

Notifications You must be signed in to change notification settings

PabloVD/PoemGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PoemGenerator

Train a recurrent neural network with the corpus of a given author to generate poems imitating his/her style.

It makes use of a LSTM architecture implemented in pytorch, trained with a compilation of poems by a writer. Given the relatively short corpus that are used, character tokenization is employed.

The network is able to replicate the style, the metre (if a regular corpus is employed, e.g., sonnets), and also sometimes assonant rhymes. It is a simple generator though, it may show nonexistent words, and verses with little semantical sense.

Based on a tutorial from the Udacity course Intro to Deep Learning with PyTorch.

Usage

Here is a brief description of the codes included:

  • samples.ipynb: jupyter notebook to generate sample poems with pretrained models.

  • main.py: main code to train the network and generate samples.

  • preprocess_texts.py: compiles and preprocess the texts of an author.

In the folder source, the architecture, parameters and several routines are defined.

Poets and sources

The network is trained with the corpus of poems of several authors writing in different languages and styles. Those currently included are:

Samples

Some samples of generated texts by the network. An initial verse provided by the user is required.

  • Lope de Vega, with the initial verse versos de amor, conceptos esparcidos,:

    versos de amor, conceptos esparcidos,

    por las espaldas del pintor del miedo.

    para escarando el mar, el rey el día,

    divina mano, en que sustenta amiga,

    y así con el camino de mis ojos

    de sangre dios el sol en los cigeros.

  • Jacint Verdaguer, with the initial verse entre'ls arbres de l'illa delitosa:

    entre'ls arbres de l'illa delitosa,

    com un plor del mirade ab la terra estelada,

    desde 'l camí de l'aygua de llur capella somniosa,

    l'altre l' amplí dels cortinatges y deus.

  • John Donne, with the initial verse no man is an island:

    no man is an island.

    if i have more then his actions by all things,

    or sense, and shall see then before.

    if then it seem'd a soule of god,

    and seest a mortine to be such a part

    with mania line, being so from her last see.

Contact

For comments, questions etc. you can reach me at pablo.villanueva.domingo@gmail.com

About

Train a recurrent neural network with the corpus of a given author to generate poems imitating his/her style.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published