All Projects → nicklashansen → Rnn_lstm_from_scratch

nicklashansen / Rnn_lstm_from_scratch

Licence: gpl-3.0
How to build RNNs and LSTMs from scratch with NumPy.

Projects that are alternatives of or similar to Rnn lstm from scratch

Pytorch Sentiment Analysis
Tutorials on getting started with PyTorch and TorchText for sentiment analysis.
Stars: ✭ 3,209 (+1957.05%)
Mutual labels:  jupyter-notebook, natural-language-processing, recurrent-neural-networks
Image Caption Generator
[DEPRECATED] A Neural Network based generative model for captioning images using Tensorflow
Stars: ✭ 141 (-9.62%)
Mutual labels:  jupyter-notebook, recurrent-neural-networks, lstm-neural-networks
Lstm anomaly thesis
Anomaly detection for temporal data using LSTMs
Stars: ✭ 178 (+14.1%)
Mutual labels:  jupyter-notebook, recurrent-neural-networks, lstm-neural-networks
Awesome Tensorlayer
A curated list of dedicated resources and applications
Stars: ✭ 248 (+58.97%)
Mutual labels:  natural-language-processing, recurrent-neural-networks, lstm-neural-networks
Stock Price Predictor
This project seeks to utilize Deep Learning models, Long-Short Term Memory (LSTM) Neural Network algorithm, to predict stock prices.
Stars: ✭ 146 (-6.41%)
Mutual labels:  jupyter-notebook, recurrent-neural-networks, numpy
Zhihu
This repo contains the source code in my personal column (https://zhuanlan.zhihu.com/zhaoyeyu), implemented using Python 3.6. Including Natural Language Processing and Computer Vision projects, such as text generation, machine translation, deep convolution GAN and other actual combat code.
Stars: ✭ 3,307 (+2019.87%)
Mutual labels:  jupyter-notebook, natural-language-processing, recurrent-neural-networks
Da Rnn
📃 **Unofficial** PyTorch Implementation of DA-RNN (arXiv:1704.02971)
Stars: ✭ 256 (+64.1%)
Mutual labels:  jupyter-notebook, recurrent-neural-networks, lstm-neural-networks
Pytorch Pos Tagging
A tutorial on how to implement models for part-of-speech tagging using PyTorch and TorchText.
Stars: ✭ 96 (-38.46%)
Mutual labels:  jupyter-notebook, natural-language-processing, recurrent-neural-networks
Deep Learning Time Series
List of papers, code and experiments using deep learning for time series forecasting
Stars: ✭ 796 (+410.26%)
Mutual labels:  jupyter-notebook, recurrent-neural-networks, lstm-neural-networks
Deep learning nlp
Keras, PyTorch, and NumPy Implementations of Deep Learning Architectures for NLP
Stars: ✭ 407 (+160.9%)
Mutual labels:  jupyter-notebook, recurrent-neural-networks, numpy
Bitcoin Price Prediction Using Lstm
Bitcoin price Prediction ( Time Series ) using LSTM Recurrent neural network
Stars: ✭ 67 (-57.05%)
Mutual labels:  jupyter-notebook, recurrent-neural-networks, lstm-neural-networks
Pytorch Learners Tutorial
PyTorch tutorial for learners
Stars: ✭ 97 (-37.82%)
Mutual labels:  jupyter-notebook, recurrent-neural-networks, lstm-neural-networks
Deep Lyrics
Lyrics Generator aka Character-level Language Modeling with Multi-layer LSTM Recurrent Neural Network
Stars: ✭ 127 (-18.59%)
Mutual labels:  natural-language-processing, recurrent-neural-networks
Data Science For Marketing Analytics
Achieve your marketing goals with the data analytics power of Python
Stars: ✭ 127 (-18.59%)
Mutual labels:  jupyter-notebook, numpy
Machine Learning Projects
This repository consists of all my Machine Learning Projects.
Stars: ✭ 135 (-13.46%)
Mutual labels:  jupyter-notebook, numpy
Practical Machine Learning With Python
Master the essential skills needed to recognize and solve complex real-world problems with Machine Learning and Deep Learning by leveraging the highly popular Python Machine Learning Eco-system.
Stars: ✭ 1,868 (+1097.44%)
Mutual labels:  jupyter-notebook, natural-language-processing
Teaching Monolith
Data science teaching materials
Stars: ✭ 126 (-19.23%)
Mutual labels:  jupyter-notebook, numpy
Crypto Rnn
Learning the Enigma with Recurrent Neural Networks
Stars: ✭ 139 (-10.9%)
Mutual labels:  jupyter-notebook, recurrent-neural-networks
Nlpaug
Data augmentation for NLP
Stars: ✭ 2,761 (+1669.87%)
Mutual labels:  jupyter-notebook, natural-language-processing
Understanding Pytorch Batching Lstm
Understanding and visualizing PyTorch Batching with LSTM
Stars: ✭ 125 (-19.87%)
Mutual labels:  jupyter-notebook, lstm-neural-networks

How to build RNNs and LSTMs from scratch with NumPy

[Update 08/18/2020] Improvements to dataset; exercises and descriptions have been made more clear.

Originally developed by me (Nicklas Hansen), Peter E. Christensen and Alexander R. Johansen as educational material for the graduate deep learning course at the Technical University of Denmark (DTU). You can access the full course material here. Inspired by the great Andrej Karpathy.


In this lab we will introduce different ways of learning from sequential data. As an example, we will train a neural network to do language modelling, i.e. predict the next token in a sentence. In the context of natural language processing a token could be a character or a word, but mind you that the concepts introduced here apply to all kinds of sequential data, such as e.g. protein sequences, weather measurements, audio signals or monetary transaction history, just to name a few.

To really get a grasp of what is going on inside the recurrent neural networks that we are about to teach you, we will carry out a substantial part of this exercise in NumPy rather than PyTorch. Once you get a hold of it, we will proceed to the PyTorch implementation.

In this notebook we will show you:

  • How to represent categorical variables in networks
  • How to build a recurrent neural network (RNN) from scratch
  • How to build a LSTM network from scratch
  • How to build a LSTM network in PyTorch

Dataset

For this exercise we will create a simple dataset that we can learn from. We generate sequences of the form:

a b EOS,

a a b b EOS,

a a a a a b b b b b EOS

where EOS is a special character denoting the end of a sequence. The task is to predict the next token t_n, i.e. a, b, EOS or the unknown token UNK given the sequence of tokens t_1, t_2, ..., t_n-1 and we are to process sequences in a sequential manner. As such, the network will need to learn that e.g. 5 bs and an EOS token will follow 5 as.

Results

The RNN takes considerable effort to converge to a nice solution:

RNN loss

The LSTM learns much faster than the RNN:

LSTM loss

And finally, the PyTorch LSTM learns even faster and converges to a better local minimum:

PyTorch LSTM loss

After working your way through these exercises, you should have a better understanding of how RNNs work, how to train them, and what they can be used for. And the conclusion? - use PyTorch.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].