{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# For tips on running notebooks in Google Colab, see\n",
"# https://pytorch.org/tutorials/beginner/colab\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"NLP From Scratch: Classifying Names with a Character-Level RNN\n",
"==============================================================\n",
"\n",
"**Author**: [Sean Robertson](https://github.com/spro)\n",
"\n",
"We will be building and training a basic character-level Recurrent\n",
"Neural Network (RNN) to classify words. This tutorial, along with two\n",
"other Natural Language Processing (NLP) \\\"from scratch\\\" tutorials\n",
"`/intermediate/char_rnn_generation_tutorial`{.interpreted-text\n",
"role=\"doc\"} and\n",
"`/intermediate/seq2seq_translation_tutorial`{.interpreted-text\n",
"role=\"doc\"}, show how to preprocess data to model NLP. In particular\n",
"these tutorials do not use many of the convenience functions of\n",
"[torchtext]{.title-ref}, so you can see how preprocessing to model NLP\n",
"works at a low level.\n",
"\n",
"A character-level RNN reads words as a series of characters -outputting\n",
"a prediction and \\\"hidden state\\\" at each step, feeding its previous\n",
"hidden state into each next step. We take the final prediction to be the\n",
"output, i.e. which class the word belongs to.\n",
"\n",
"Specifically, we\\'ll train on a few thousand surnames from 18 languages\n",
"of origin, and predict which language a name is from based on the\n",
"spelling:\n",
"\n",
"``` {.sourceCode .sh}\n",
"$ python predict.py Hinton\n",
"(-0.47) Scottish\n",
"(-1.52) English\n",
"(-3.57) Irish\n",
"\n",
"$ python predict.py Schmidhuber\n",
"(-0.19) German\n",
"(-2.48) Czech\n",
"(-2.68) Dutch\n",
"```\n",
"\n",
"Recommended Preparation\n",
"-----------------------\n",
"\n",
"Before starting this tutorial it is recommended that you have installed\n",
"PyTorch, and have a basic understanding of Python programming language\n",
"and Tensors:\n",
"\n",
"-
Download the data fromhereand extract it to the current directory.
\n", "