- Notifications
You must be signed in to change notification settings - Fork23
😡😇 Stanford Sentiment Treebank loader in Python
License
JonathanRaiman/pytreebank
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Utilities for downloading, importing, and visualizing theStanford Sentiment Treebank, a dataset capturing fine-grained sentiment over movie reviews.See examples below for usage. Tested in Python3.4.3 and2.7.12.
Javascript code by Jason Chuang and Stanford NLP modified and taken fromStanford NLP Sentiment Analysis demo.
Allows for visualization using Jason Chuang's Javascript and CSS within an IPython notebook:
importpytreebank# load the sentiment treebank corpus in the parenthesis format,# e.g. "(4 (2 very ) (3 good))"dataset=pytreebank.load_sst()# add Javascript and CSS to the Ipython notebookpytreebank.LabeledTree.inject_visualization_javascript()# select and example to visualizeexample=dataset["train"][0]# display it in the pageexample.display()
To use the corpus to output spans from the different trees you can call theto_labeled_lines andto_lines method of aLabeledTree. The first returned sentence in those lists is always the root sentence:
importpytreebankdataset=pytreebank.load_sst()example=dataset["train"][0]# extract spans from the tree.forlabel,sentenceinexample.to_labeled_lines():print("%s has sentiment label %s"% (sentence,["very negative","negative","neutral","positive","very positive"][label]))
Change the save/load directory by passing a path (this will look fortrain.txt,dev.txt andtest.txt files under the directory).
dataset = pytreebank.load_sst("/path/to/sentiment/")To just load a single dataset file:
train_data = pytreebank.import_tree_corpus("/path/to/sentiment/train.txt")About
😡😇 Stanford Sentiment Treebank loader in Python
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
