Skip to main content

Python package for loading Stanford Sentiment Treebank corpus

Project description

SST Utils
---------

Utilities for loading and visualizing Stanford Sentiment Treebank.
See examples below for usage.

@author Jonathan Raiman

Javascript code by Jason Chuang and Stanford NLP modified and taken from [Stanford NLP Sentiment Analysis demo](http://nlp.stanford.edu:8080/sentiment/rntnDemo.html).

### Visualization

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

```python
import pytreebank
# load the sentiment treebank corpus in the parenthesis format,
# e.g. "(4 (2 very ) (3 good))"
dataset = pytreebank.import_tree_corpus("train.txt")
# add Javascript and CSS to the Ipython notebook
pytreebank.LabeledTree.inject_visualization_javascript()
# select and example to visualize
example = dataset[0]
# display it in the page
example.display()
```

![Example visualization using pytreebank](visualization_example.png)

### 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:

```python
import pytreebank
dataset = pytreebank.import_tree_corpus("train.txt")
example = dataset[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]
))
```

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.1.7.tar.gz (31.2 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: pytreebank-0.1.7.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pytreebank-0.1.7.tar.gz
Algorithm Hash digest
SHA256 680fffc9d0b0e866eac5c84e7c7de61346ec2d7c944c7257324083b7cd5fb9f4
MD5 2734978e7a43c73e3c020ba5c91a7ad1
BLAKE2b-256 1ff63d4a80d9f1183c0d31d07d09e3de21ec72d88d5dc224243ed52e4a528788

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