The PyTorch Parts of Speech LSTM Example

For the past several weeks I’ve been exploring LSTM networks using the PyTorch code library. My ultimate goal is to create a PyTorch demo for the IMDB movie review sentiment analysis example. In that example, you train an LSTM recurrent neural network model using 50,000 actual movie reviews so that it will predict if a review is positive (“This was a great movie”) or negative (“Not a great movie by any means”).

Any LSTM problem is very difficult. I found a nice LSTM example in the PyTorch documentation. Everyone I know learns coding technology in the same way. First, get an example program up and running. Then make changes to the program and observe what each change does so that you eventually understand everything about the example. And then you can write code for a new program.

The example program I found does parts of speech prediction. The input is a sentence like “The dog chased the cat” and the output is the parts of speech for each word. The example limits itself to just three parts of speech: DET (determiner aka article), NN (noun), V (verb).

After I got the example running, I started making changes. In my edited version, I mostly added print statements to clarify what was going on at a relatively high level. My next step will be to dissect the code at a low level.

Lots of fun.



An Internet image search for “girls having fun” and “guys having fun” suggests that girls tend to have fun in social and verbal ways and guys have fun in competitive and non-verbal ways.

This entry was posted in Machine Learning, PyTorch. Bookmark the permalink.