{"id":18859990,"url":"https://github.com/stanfordnlp/treelstm","last_synced_at":"2025-05-13T15:39:20.845Z","repository":{"id":29779454,"uuid":"33323486","full_name":"stanfordnlp/treelstm","owner":"stanfordnlp","description":"Tree-structured Long Short-Term Memory networks (http://arxiv.org/abs/1503.00075)","archived":false,"fork":false,"pushed_at":"2017-07-30T21:01:43.000Z","size":71,"stargazers_count":880,"open_issues_count":9,"forks_count":233,"subscribers_count":46,"default_branch":"master","last_synced_at":"2025-04-04T09:09:51.617Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stanfordnlp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-02T17:56:31.000Z","updated_at":"2025-04-04T03:26:46.000Z","dependencies_parsed_at":"2022-09-01T04:12:00.493Z","dependency_job_id":null,"html_url":"https://github.com/stanfordnlp/treelstm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanfordnlp%2Ftreelstm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanfordnlp%2Ftreelstm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanfordnlp%2Ftreelstm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stanfordnlp%2Ftreelstm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stanfordnlp","download_url":"https://codeload.github.com/stanfordnlp/treelstm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253971332,"owners_count":21992689,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T04:20:17.106Z","updated_at":"2025-05-13T15:39:20.783Z","avatar_url":"https://github.com/stanfordnlp.png","language":"Lua","funding_links":[],"categories":["Uncategorized","Model Zoo"],"sub_categories":["Uncategorized","Recurrent Networks"],"readme":"Tree-Structured Long Short-Term Memory Networks\n===============================================\n\nAn implementation of the Tree-LSTM architectures described in the paper \n[Improved Semantic Representations From Tree-Structured Long Short-Term Memory\nNetworks](http://arxiv.org/abs/1503.00075) by Kai Sheng Tai, Richard Socher, and \nChristopher Manning.\n\n## Requirements\n\n- [Torch7](https://github.com/torch/torch7)\n- [penlight](https://github.com/stevedonovan/Penlight)\n- [nn](https://github.com/torch/nn)\n- [nngraph](https://github.com/torch/nngraph)\n- [optim](https://github.com/torch/optim)\n- Java \u003e= 8 (for Stanford CoreNLP utilities)\n- Python \u003e= 2.7\n\nThe Torch/Lua dependencies can be installed using [luarocks](http://luarocks.org). For example:\n\n```\nluarocks install nngraph\n```\n\n## Usage\n\nFirst run the following script:\n\n```\n./fetch_and_preprocess.sh\n```\n\nThis downloads the following data:\n\n  - [SICK dataset](http://alt.qcri.org/semeval2014/task1/index.php?id=data-and-tools) (semantic relatedness task)\n  - [Stanford Sentiment Treebank](http://nlp.stanford.edu/sentiment/index.html) (sentiment classification task)\n  - [Glove word vectors](http://nlp.stanford.edu/projects/glove/) (Common Crawl 840B) -- **Warning:** this is a 2GB download!\n\nand the following libraries:\n\n  - [Stanford Parser](http://nlp.stanford.edu/software/lex-parser.shtml)\n  - [Stanford POS Tagger](http://nlp.stanford.edu/software/tagger.shtml)\n\nThe preprocessing script generates dependency parses of the SICK dataset using the\n[Stanford Neural Network Dependency Parser](http://nlp.stanford.edu/software/nndep.shtml).\n\nAlternatively, the download and preprocessing scripts can be called individually.\n\n### Semantic Relatedness\n\nThe goal of this task is to predict similarity ratings for pairs of sentences. We train and evaluate our models on the [Sentences Involving Compositional Knowledge (SICK)](http://alt.qcri.org/semeval2014/task1/index.php?id=data-and-tools) dataset.\n\nTo train models for the semantic relatedness prediction task on the SICK dataset,\nrun:\n\n```\nth relatedness/main.lua --model \u003cdependency|constituency|lstm|bilstm\u003e --layers \u003cnum_layers\u003e --dim \u003cmem_dim\u003e --epochs \u003cnum_epochs\u003e\n```\n\nwhere:\n\n  - `model`: the LSTM variant to train (default: dependency, i.e. the Dependency Tree-LSTM)\n  - `layers`: the number of layers (default: 1, ignored for Tree-LSTMs)\n  - `dim`: the LSTM memory dimension (default: 150)\n  - `epochs`: the number of training epochs (default: 10)\n\n### Sentiment Classification\n\nThe goal of this task is to predict sentiment labels for sentences. For this task, we use the [Stanford Sentiment Treebank](http://nlp.stanford.edu/sentiment/index.html) dataset. Here, there are two sub-tasks: binary and fine-grained. In the binary sub-task, the sentences are labeled `positive` or `negative`. In the fine-grained sub-task, the sentences are labeled `very positive`, `positive`, `neutral`, `negative` or `very negative`.\n\nTo train models for the sentiment classification task on the Stanford Sentiment Treebank, run:\n\n```\nth sentiment/main.lua --model \u003cconstituency|dependency|lstm|bilstm\u003e --layers \u003cnum_layers\u003e --dim \u003cmem_dim\u003e --epochs \u003cnum_epochs\u003e\n```\n\nThis trains a Constituency Tree-LSTM model for the \"fine-grained\" 5-class classification sub-task.\n\nFor the binary classification sub-task, run with the `-b` or `--binary` flag, for example:\n\n```\nth sentiment/main.lua -m constituency -b\n```\n\nPredictions are written to the `predictions` directory and trained model parameters are saved to the `trained_models` directory.\n\nSee the [paper](http://arxiv.org/abs/1503.00075) for more details on these experiments.\n\n## Third-party Implementations\n\n- A Tensorflow Fold [re-implementation](https://github.com/tensorflow/fold/blob/master/tensorflow_fold/g3doc/sentiment.ipynb) of the Tree-LSTM for sentiment classification\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstanfordnlp%2Ftreelstm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstanfordnlp%2Ftreelstm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstanfordnlp%2Ftreelstm/lists"}