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:**
- Typical “Neutral” sentiments: “Origin of Species”,“Declaration of Independence”
- Typical “Positive + Negative” (maybe more dramatic) sentiments: Shakespeares “Hamlet”
,“Sonnets”
- 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)







