Code Monkey home page Code Monkey logo

pytreebank's Introduction

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")

pytreebank's People

Contributors

jonathanraiman avatar dodoro-gw avatar

Watchers

James Cloos avatar Jingwen Hu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.