{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# For tips on running notebooks in Google Colab, see\n# https://codelin.vip/beginner/colab\n%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"NLP From Scratch: Generating Names with a Character-Level RNN\n=============================================================\n\n**Author**: [Sean Robertson](https://github.com/spro)\n\nThis tutorials is part of a three-part series:\n\n- [NLP From Scratch: Classifying Names with a Character-Level\n RNN](https://pytorch.org/tutorials/intermediate/char_rnn_classification_tutorial.html)\n- [NLP From Scratch: Generating Names with a Character-Level\n RNN](https://pytorch.org/tutorials/intermediate/char_rnn_generation_tutorial.html)\n- [NLP From Scratch: Translation with a Sequence to Sequence Network\n and\n Attention](https://pytorch.org/tutorials/intermediate/seq2seq_translation_tutorial.html)\n\nThis is our second of three tutorials on \\\"NLP From Scratch\\\". In the\n[first\ntutorial](/tutorials/intermediate/char_rnn_classification_tutorial) we\nused a RNN to classify names into their language of origin. This time\nwe\\'ll turn around and generate names from languages.\n\n``` {.sh}\n> python sample.py Russian RUS\nRovakov\nUantov\nShavakov\n\n> python sample.py German GER\nGerren\nEreng\nRosher\n\n> python sample.py Spanish SPA\nSalla\nParer\nAllan\n\n> python sample.py Chinese CHI\nChan\nHang\nIun\n```\n\nWe are still hand-crafting a small RNN with a few linear layers. The big\ndifference is instead of predicting a category after reading in all the\nletters of a name, we input a category and output one letter at a time.\nRecurrently predicting characters to form language (this could also be\ndone with words or other higher order constructs) is often referred to\nas a \\\"language model\\\".\n\n**Recommended Reading:**\n\nI assume you have at least installed PyTorch, know Python, and\nunderstand Tensors:\n\n-
Download the data fromhereand extract it to the current directory.
\n```\n```{=html}\nRather than having to give it a starting letter, anotherstrategy would have been to include a \"start of string\" token intraining and have the network choose its own starting letter.
\n```\n```{=html}\n