# Visualizing Text Sentiments in RGBColor and ChromaticityPlot

Posted 2 years ago
4471 Views
|
2 Replies
|
8 Total Likes
|

Today, I got an idea, Why not show text sentiments value from different author in just one-shot all together? So I write a few lines of code in Mathematica 11.3, see attached Notebook.

The idea is very nature. As people said, every color represents an emotion, and vice versa. So I use "warm" red to represent positive, "cool" blue for negative, and green for neutral. Let's start an example from Alice.

sentence = TextSentences[ExampleData[{"Text", "AliceInWonderland"}]];
sentiment = Classify["Sentiment", #, "Probabilities"] & /@ sentence;
width = Floor[N[Sqrt[Length@sentiment]], 1];
plot = ArrayPlot[
Partition[Take[RGBColor @@@ sentiment, width^2], width],
ImageSize -> 300, PlotLabel -> "Alice in Wonderland"]


Then I got all texts plot in various color.

## Result Discussion:**

1. Typical "Neutral" sentiments: "Origin of Species","Declaration of Independence"

2. Typical "Positive + Negative" (maybe more dramatic) sentiments: Shakespeares "Hamlet" ,"Sonnets"

3. Non-English Text: Sentiments classify may not be very accurate.

# Take a glance, if the text-color match the color in your mind?

Attachments:
Answer
2 Replies
Sort By:
Posted 2 years ago
 @FrederickWu, This is a really nice post.
Answer
Posted 2 years ago
 - Congratulations! This post is now a Staff Pick as distinguished by a badge on your profile! Thank you, keep it coming, and consider contributing your work to the The Notebook Archive!
Answer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments