Message Boards Message Boards

Visualizing Text Sentiments in RGBColor and ChromaticityPlot

Posted 6 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?

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

Be respectful. Review our Community Guidelines to understand your role and responsibilities. Community Terms of Use