Message Boards Message Boards

Visualizing Text Sentiments in RGBColor and ChromaticityPlot

Posted 5 years ago

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

enter image description here

Then I got all texts plot in various color. enter image description here

Result Discussion:**

  1. Typical "Neutral" sentiments: "Origin of Species","Declaration of Independence" enter image description here enter image description here

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

  3. Non-English Text: Sentiments classify may not be very accurate. enter image description here enter image description here

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

Attachments:
POSTED BY: Frederick Wu
2 Replies

enter image description here - 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!

POSTED BY: Moderation Team

@FrederickWu, This is a really nice post.

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract