All Projects → cpury → lstm-math

cpury / lstm-math

Licence: MIT license
Neural network that solves math equations on the character level

Programming Languages

Jupyter Notebook
11667 projects
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to lstm-math

fiction generator
Fiction generator with Tensorflow. 模仿王小波的风格的小说生成器
Stars: ✭ 27 (+3.85%)
Mutual labels:  lstm, seq2seq
Nspm
🤖 Neural SPARQL Machines for Knowledge Graph Question Answering.
Stars: ✭ 156 (+500%)
Mutual labels:  lstm, seq2seq
Pointer Networks Experiments
Sorting numbers with pointer networks
Stars: ✭ 53 (+103.85%)
Mutual labels:  lstm, seq2seq
dts
A Keras library for multi-step time-series forecasting.
Stars: ✭ 130 (+400%)
Mutual labels:  lstm, seq2seq
Screenshot To Code
A neural network that transforms a design mock-up into a static website.
Stars: ✭ 13,561 (+52057.69%)
Mutual labels:  lstm, seq2seq
Stock Prediction Models
Gathers machine learning and deep learning models for Stock forecasting including trading bots and simulations
Stars: ✭ 4,660 (+17823.08%)
Mutual labels:  lstm, seq2seq
Chinese Chatbot
中文聊天机器人,基于10万组对白训练而成,采用注意力机制,对一般问题都会生成一个有意义的答复。已上传模型,可直接运行,跑不起来直播吃键盘。
Stars: ✭ 124 (+376.92%)
Mutual labels:  lstm, seq2seq
2D-LSTM-Seq2Seq
PyTorch implementation of a 2D-LSTM Seq2Seq Model for NMT.
Stars: ✭ 25 (-3.85%)
Mutual labels:  lstm, seq2seq
Deep Time Series Prediction
Seq2Seq, Bert, Transformer, WaveNet for time series prediction.
Stars: ✭ 183 (+603.85%)
Mutual labels:  lstm, seq2seq
Deep News Summarization
News summarization using sequence to sequence model with attention in TensorFlow.
Stars: ✭ 167 (+542.31%)
Mutual labels:  lstm, seq2seq
Base-On-Relation-Method-Extract-News-DA-RNN-Model-For-Stock-Prediction--Pytorch
基於關聯式新聞提取方法之雙階段注意力機制模型用於股票預測
Stars: ✭ 33 (+26.92%)
Mutual labels:  lstm, seq2seq
Tensorflow novelist
模仿莎士比亚创作戏剧!屌炸天的是还能创作金庸武侠小说!快star,保持更新!!
Stars: ✭ 244 (+838.46%)
Mutual labels:  lstm, seq2seq
Tensorflow seq2seq chatbot
Stars: ✭ 81 (+211.54%)
Mutual labels:  lstm, seq2seq
Poetry Seq2seq
Chinese Poetry Generation
Stars: ✭ 159 (+511.54%)
Mutual labels:  lstm, seq2seq
Natural Language Processing With Tensorflow
Natural Language Processing with TensorFlow, published by Packt
Stars: ✭ 222 (+753.85%)
Mutual labels:  lstm, seq2seq
Pytorch Seq2seq
Tutorials on implementing a few sequence-to-sequence (seq2seq) models with PyTorch and TorchText.
Stars: ✭ 3,418 (+13046.15%)
Mutual labels:  lstm, seq2seq
deep-keyphrase
seq2seq based keyphrase generation model sets, including copyrnn copycnn and copytransfomer
Stars: ✭ 51 (+96.15%)
Mutual labels:  seq2seq
traffic-prediction
Predict traffic flow with LSTM. For experimental purposes only, unsupported!
Stars: ✭ 47 (+80.77%)
Mutual labels:  lstm
theano-recurrence
Recurrent Neural Networks (RNN, GRU, LSTM) and their Bidirectional versions (BiRNN, BiGRU, BiLSTM) for word & character level language modelling in Theano
Stars: ✭ 40 (+53.85%)
Mutual labels:  lstm
Reuters-21578-Classification
Text classification with Reuters-21578 datasets using Gensim Word2Vec and Keras LSTM
Stars: ✭ 44 (+69.23%)
Mutual labels:  lstm

lstm-math

See the accompanying blog post here: http://cpury.github.io/learning-math/

Simply try it yourself in Google Colab: https://colab.research.google.com/github/cpury/lstm-math/blob/master/lstm_math.ipynb (NEW)

Train a LSTM-based Seq2Seq network to predict the result of math equations on the character level. Configuration through global variables because I'm lazy.

Written by Max Schumacher (@cpury) in Summer 2017. Updated in Summer 2019.

Preview

Will learn how to complete simple math formulas. E.g. during training, you will get samples like this:

Examples:
  67 + 38 =  108   (expected:  105)
  15 + 49 =   69   (expected:   64)
  84 - 91 =   -5   (expected:   -7)
  71 + 53 =  123   (expected:  124)
  72 -  1 =   75   (expected:   71)

And ideally, after an half an hour CPU-time or so, it will learn (almost) perfectly to get the right results :)

Maybe something like:

Examples:
  36 + 55 =  91   (expected:  91)
  32 + 45 =  77   (expected:  77)
  15 + 93 = 108   (expected: 108)
  41 + 82 = 123   (expected: 123)
   4 + 89 =  93   (expected:  93)

Details

This uses a Seq2Seq model based on LSTMs in Keras. Depending on the complexity of equations you choose, it will train on some small percentage of the complete equation space and validate on another small percentage. So all the equations you see in the example above have not been seen by the network before.

Running it yourself

Please note that I wrote this for Python 3.6+. It will probably work with 2.7+, but I don't offer any guarantees on that.

  1. Set up a virtual env: virtualenv venv; source venv/bin/activate
  2. Install the requirements: pip install -r requirements.txt
  3. Optional: Open main.py and play around with the global config values.
  4. python main.py

You can cancel the training any time with ctrl+c. It will always output some examples at the end and store the model in model.h5, even if you cancel.

Actually, since it's not stopping when overfitting has begun, it might actually be good to hit ctr+c once you're happy with the results.

Playing with the config

All the config values at the top of main.py should be fairly self-explanatory. You could e.g.

  • Change the math formulas to be trained on:
    • Change MAX_NUMBER to allow higher values in the equations
    • Work with negative numbers by setting MIN_NUMBER to something negative
    • Add multiplication by adding '*' to OPERATIONS
    • Have more operations per equation by increasing N_OPERATIONS
    • etc.
  • Change the model to be trained:
    • Change the size of the hidden layer(s) with HIDDEN_SIZE
    • Make the encoder deeper with ENCODER_DEPTH
    • Make the decoder deeper with DECODER_DEPTH
    • Use dropout with DROPOUT
    • etc.
  • Reverse all strings to overcome the digit ordering problem with REVERSE (see the blog post for more info)

Feedback

Feel free to submit issues if you find bugs or room for improvement.

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].