Skip to main content

Python package for loading Stanford Sentiment Treebank corpus

Project description

SST Utils

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 3.4.3 and 2.7.12.

Jonathan Raiman, author

Javascript code by Jason Chuang and Stanford NLP modified and taken from Stanford NLP Sentiment Analysis demo.

PyPI version Build Status License

Visualization

Allows for visualization using Jason Chuang's Javascript and CSS within an IPython notebook:

import pytreebank
# 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 notebook
pytreebank.LabeledTree.inject_visualization_javascript()
# select and example to visualize
example = dataset["train"][0]
# display it in the page
example.display()

Example visualization using pytreebank

Lines and Labels

To use the corpus to output spans from the different trees you can call the to_labeled_lines and 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"][0]

# 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]
	))

Download/Loading control:

Change the save/load directory by passing a path (this will look for train.txt, dev.txt and 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")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytreebank-0.2.7.tar.gz (34.6 kB view details)

Uploaded Source

File details

Details for the file pytreebank-0.2.7.tar.gz.

File metadata

  • Download URL: pytreebank-0.2.7.tar.gz
  • Upload date:
  • Size: 34.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.6

File hashes

Hashes for pytreebank-0.2.7.tar.gz
Algorithm Hash digest
SHA256 f0c6fde639739d356d4994d432476903421d216b3e2f11a620c3118e47aa675f
MD5 3edc17f6f2e18c775bb65cfc77dc15fe
BLAKE2b-256 e012626ead6f6c0a0a9617396796b965961e9dfa5e78b36c17a81ea4c43554b1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page