From the course: Hands-On PyTorch Machine Learning

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Torchtext for translation

Torchtext for translation

- [Instructor] In this lab, we continue with the Piraeus use case. I'll walk you through the tutorial called "Classifying Names with a Character-Level RNN" by Sean Robertson. We will be building a text classifier to identify the language used in the course by the tutor. The character-level RNN reads words as a series of characters, outputting a prediction and hidden state at each step, feeding its previous hidden state into each next step. We take the final prediction to be the output, which class the word belongs to. Specifically, we'll train on a few thousand surnames from 18 languages of origin and predict which language a name is from, based on the spelling. First, we import the matplotlib. We then load the data files from the directory and build our category lines. Now we have category lines, a dictionary mapping each category, which is the language, to a list of lines, which are names. We also kept track of all…

Contents