Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

😡😇 Stanford Sentiment Treebank loader in Python

License

NotificationsYou must be signed in to change notification settings

JonathanRaiman/pytreebank

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.

Jonathan Raiman, author

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

PyPI versionBuild StatusLicense

Visualization

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

Example visualization using pytreebank

Lines and Labels

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

Download/Loading control:

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

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp