Sentiment in Stories
Author
Stephen Wolfram
Title
Sentiment in Stories
Description
Sentiment of a single sentence:
Category
Educational Materials
Keywords
URL
http://www.notebookarchive.org/2019-08-98zxjkg/
DOI
https://notebookarchive.org/2019-08-98zxjkg
Date Added
2019-08-20
Date Last Modified
2019-08-20
File Size
327.06 kilobytes
Supplements
Rights
Redistribution rights reserved



Sentiment in Stories
Sentiment in Stories
Sentiment of a single sentence:
In[]:=
Classify["Sentiment","I am happy today"]
Out[]=
Positive
Get the sentences in the Wikipedia article on “chicken”:
In[]:=
data=TextSentences[WikipediaData["chicken"]];
Find the sentiment of each sentence:
In[]:=
Classify["Sentiment",#]&/@data//Short
Out[]//Short=
{Neutral,Neutral,Positive,302,Positive,Neutral,Neutral}
What was the 3rd sentence?
In[]:=
data[[3]]
Out[]=
There are more chickens in the world than any other bird or domesticated fowl.
Here’s the sentiment found for that sentence:
In[]:=
Classify["Sentiment","There are less chickens that died in the world than any other bird or domesticated fowl."]
Out[]=
Negative
Try a variant of the sentence; still negative:
In[]:=
Classify["Sentiment","There are less sad chickens in the world than any other bird or domesticated fowl."]
Out[]=
Negative
Other Documents
Other Documents
Get the sentences in Dickens’s Oliver Twist:
In[]:=
tdata=TextSentences[ResourceData["Oliver Twist"]];
Here is the number of sentences:
In[]:=
Length[tdata]
Out[]=
10214
Find their sentiments:
In[]:=
sent=Classify["Sentiment",#]&/@tdata
Here are the possible sentiments found:
In[]:=
Union[sent]
Out[]=
{Negative,Neutral,Positive,Indeterminate}
Map the sentiments to numbers:
In[]:=
sent/.{"Positive"1,"Negative"-1,"Neutral"0,Indeterminate0}
Out[]=
{-1,1,0,1,0,-1,1,1,1,-1,-1,-1,1,0,1,-1,-1,0,1,1,-1,1,0,-1,0,-1,0,1,-1,-1,0,-1,-1,0,0,-1,0,0,-1,1,0,-1,-1,0,-1,-1,1,1,0,-1,0,-1,0,0,1,1,-1,0,-1,1,-1,1,-1,1,-1,-1,1,0,0,0,-1, ⋯10072⋯ | |||||
|
Show the “sentiment walk” of the story:
In[]:=
ListLinePlot[Accumulate[%]]
Out[]=
One might conclude that in the end it’s a tragedy...


Cite this as: Stephen Wolfram, "Sentiment in Stories" from the Notebook Archive (2019), https://notebookarchive.org/2019-08-98zxjkg

Download

