Member-only story

Code Review: Character Level LSTM in PyTorch

Crystal X
5 min readApr 13, 2021

--

I have been studying PyTorch for the past several weeks and in the penultimate lesson have been studying recurrent neural networks, or RNNs. The RNN in this post is goint ti focus on character level long short term memory, or LSTM.

I have worked om several datasets concerning sentiment analysis usIng sklearn, but this type of text based work is quite different. A text document is loaded into the program, tokenised, trained, and the words in the text document are predicted on. The text for the exercise I was working on was the Leo Tolstoy’s tome, Anna Karenina. Having read the book and watched the movie, I can say the text was a good choice indeed.

Because I did not have a text copy of Anna Karenina and I did not want to download a copy off the internet, I created a small document of a few paragraphs in Google docs and then downloaded the document into a text file, which I copied into my personal Google drive for testing purposes.I have been advised that the way to improve accuracy is to use more data, so mperhaps the small text document I created was not enough to make an accurate prediction. Perhahs a larger document would have yielded better results. Nevertheless, I will endeavour to carry out a code review for this program and any people wanting to experiment with this program can use another text file of their choosing to see if the…

--

--

Crystal X
Crystal X

Written by Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.

No responses yet