Python package for loading Stanford Sentiment Treebank corpus
Utilities for downloading, importing, and visualizing the Stanford Sentiment Treebank, a dataset capturing fine-grained sentiment over movie reviews.
See examples below for usage. Tested in Python
Lines and Labels
To use the corpus to output spans from the different trees you can call the
to_lines method of a
LabeledTree. The first returned sentence in those lists is always the root sentence:
import pytreebank dataset = pytreebank.load_sst() example = dataset["train"] # extract spans from the tree. for label, sentence in example.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 for
test.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")
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.