Code Monkey home page Code Monkey logo

tree_rnn's Introduction

tree_rnn

Theano implementation of Tree RNNs aka Recursive Neural Networks.

Includes implementation of TreeLSTMs as described in "Improved Semantic Representations From Tree-Structured Long Short-Term Memory Networks" by Kai Sheng Tai, Richard Socher, and Christopher D. Manning.

Also includes implementation of TreeGRUs derived using similar methods.

You may immediately run "dummy" demos via simple_demo.py and modulo_demo.py.

Code for evaluation on the Standford Sentiment Treebank (used by the paper) is also available in sentiment.py. To run this, you'll need to download the relevant data.

Step-by-step for cloning this repo and getting the sentiment model running:

From your shell, run

git clone https://github.com/ofirnachum/tree_rnn.git
git clone https://github.com/stanfordnlp/treelstm.git
cd treelstm
./fetch_and_preprocess.sh

This will download the datasets, the word vectors, and do some preprocessing on the data. Once this is complete, go into the tree_rnn directory and start a Python shell. In that shell, we'll preprocess the word vectors:

import data_utils
vocab = data_utils.Vocab()
vocab.load('../treelstm/data/sst/vocab-cased.txt')
words, embeddings = \
    data_utils.read_embeddings_into_numpy(
        '../treelstm/data/glove/glove.840B.300d.txt', vocab=vocab)

import numpy as np
np.save('../treelstm/data/words.npy', words)
np.save('../treelstm/data/glove.npy', embeddings)

After exitting the Python shell, you can run the sentiment training directly

python sentiment.py

The first couple lines of output should be

train 6920
dev 872
test 1821
num emb 21701
num labels 3
epoch 0
avg loss 16.7419t example 6919 of 6920
dev score 0.586009174312
epoch 1
avg loss 13.8955t example 6919 of 6920
dev score 0.69495412844
epoch 2
avg loss 12.9191t example 6919 of 6920
dev score 0.730504587156

tree_rnn's People

Contributors

ofirnachum avatar

Watchers

James Cloos avatar Deddy Syefria avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.