Visualizing Text Sentiments in RGBColor and ChromaticityPlot

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”

  1. Typical “Positive + Negative” (maybe more dramatic) sentiments: Shakespeares “Hamlet”
    ,“Sonnets”

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

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

Viusalizing Text Sentiment_V1.nb (1.32 MB)

6 Likes

@FrederickWu, This is a really nice post.

2 Likes

2015-11-02_10-07-11.png