• This repository has been archived on 11/Apr/2021
  • Stars
    star
    657
  • Rank 68,589 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 8 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ“– Some language modeling tools for Keras

keras-language-modeling

Some code for doing language modeling with Keras, in particular for question-answering tasks. I wrote a very long blog post that explains how a lot of this works, which can be found here.

Stuff that might be of interest

  • attention_lstm.py: Attentional LSTM, based on one of the papers referenced in the blog post and others. One application used it for image captioning. It is initialized with an attention vector which provides the attention component for the neural network.
  • insurance_qa_eval.py: Evaluation framework for the InsuranceQA dataset. To get this working, clone the data repository and set the INSURANCE_QA environment variable to the cloned repository. Changing config will adjust how the model is trained.
  • keras-language-model.py: The LanguageModel class uses the config settings to generate a training model and a testing model. The model can be trained by passing a question vector, a ground truth answer vector, and a bad answer vector to fit. Then predict calculates the similarity between a question and answer. Override the build method with whatever language model you want to get a trainable model. Examples are provided at the bottom, including the EmbeddingModel, ConvolutionModel, and RecurrentModel.

Getting Started

# Install Keras (may also need dependencies)
git clone https://github.com/fchollet/keras
cd keras
sudo python setup.py install

# Clone InsuranceQA dataset
git clone https://github.com/codekansas/insurance_qa_python
export INSURANCE_QA=$(pwd)/insurance_qa_python

# Run insurance_qa_eval.py
git clone https://github.com/codekansas/keras-language-modeling
cd keras-language-modeling/
python insurance_qa_eval.py

Alternatively, I wrote a script to get started on a Google Cloud Platform instance (Ubuntu 16.04) which can be run via

cd ~
git clone https://github.com/codekansas/keras-language-modeling
cd keras-language-modeling
source install.py

I've been working on making these models available out-of-the-box. You need to install the Git branch of Keras (and maybe make some modifications) in order to run some of these models; the Keras project can be found here.

The runnable program is insurance_qa_eval.py. This will create a models/ directory which will store a history of the model's weights as it is created. You need to set an environment variable to tell it where the INSURANCE_QA dataset is.

Finally, my setup (which I think is pretty common) is to have an SSD with my operating system, and an HDD with larger data files. So I would recommend creating a models/ symlink from the project directory to somewhere in your HDD, if you have a similar setup.

Serving to a port

I added a command line argument that uses Flask to serve to a port. Once you've installed Flask, you can run:

python insurance_qa_eval.py serve

This is useful in combination with ngrok for monitoring training progress away from your desktop.

Additionally

  • The official implementation can be found here

Data

More Repositories

1

seqgan-text-tensorflow

🍑 SeqGAN implementation for generating text using an RNN.
Python
99
star
2

tinier-nn

πŸ“± Binarized Neural Network TF training code + C matrix / eval library.
C
98
star
3

insurance_qa_python

Python-formatted InsuranceQA data
46
star
4

gandlf

Generative Adversarial Networks in Keras
Python
45
star
5

rwkv

RWKV model implementation
Python
38
star
6

pydata-carolinas-2016

πŸ“Š My tutorial for PyData Carolinas 2016
Jupyter Notebook
30
star
7

keras-resnet

πŸš„ Residual wrapper for Keras
Python
23
star
8

usa

Language-based navigation project
Python
22
star
9

theano-rnn

πŸ” Some RNN implementations in Theano
Python
17
star
10

ml-starter

A template for quickly implementing ML ideas 🧠⚑
Python
9
star
11

bojo

Command-line bullet journal tool
Python
7
star
12

reinforcement-tetris

Using reinforcement learning and Keras to learn to play Tetris
Python
7
star
13

monotonic-attention

Monotonic attention implementation
Python
4
star
14

calcium-gan

Tutorial on building a GAN model to calcium imaging.
Jupyter Notebook
3
star
15

codekansas.github.io

πŸ’» Personal blog
JavaScript
3
star
16

gibberish-decoder

Experiment with using a recurrent neural network to predict word embeddings.
Python
3
star
17

covid-cough-prediction

Cough prediction bot for MIT Covid-19 hackathon
JavaScript
3
star
18

liveqa2017

Live QA submission, 2017
Python
3
star
19

mnist-domain-adaptation

Domain adaptation experiment on MNIST digits
Python
2
star
20

llama-inference

LLaMa model inference
Python
2
star
21

language_conv_visualizations

Visualizations of convolutional layers in NLP tasks
Python
2
star
22

torchscript-cmake-example

Example CMake project for TorchScript
Python
1
star
23

teiwords

Summarize different aspects of a TEI document using nltk, an open source language processing toolbox.
Python
1
star
24

agihouse.nyc

HTML
1
star
25

CNeuralNetworks

Neural networks written in C++, for practice
C++
1
star
26

dotbot-crontab

Crontab plugin for Dotbot
Python
1
star
27

ml-project-template

Empty template repository for ML projects
Python
1
star
28

tmesh

Fast boolean operations for triangular meshes
C++
1
star
29

spikefinder

Spikefinder submission
Python
1
star
30

generative-modeling

Python
1
star
31

personalized-chatbot

Fine-tuning a personalized chatbot
Python
1
star
32

ml-pretrained

Implementations of various pre-trained models
Python
1
star
33

super-simple-stretch-api

Super simple API for the Stretch robot
Python
1
star
34

jobs

Stuff for my job searches
TeX
1
star
35

ros-blog-post

Accompanying repository for a blog post
Python
1
star
36

sarfile

Like tarfile, but streamable
Python
1
star