1 of 28

SENTIMENT ANALYSIS

Unit 2, Module 2.6

1

2 of 28

HOW DO COMPUTERS KNOW HOW PEOPLE FEEL?

2

2

3 of 28

NATURAL LANGUAGE PROCESSING

  • Natural Language Processing (NLP) is how computers process and understand human language
    • This allows computers to communicate with us via written and spoken language
  • NLP techniques can be used to analyze text or speech the user inputs, and can also use machine learning to train models on text or spoken language
    • These models must be trained on large amounts of text

3

4 of 28

MODULE OBJECTIVES

Students should be able to:

  • Define what Natural Language Processing is
  • Describe the difference between subjectivity and polarity in sentiment analysis
  • Describe limitations of sentiment analysis tools

4

5 of 28

ACTIVITY: GOOGLE TALK TO BOOKS

  • Natural Language Processing is fundamental to tools we use on a daily basis
    • NLP is integral to search engines, allowing users to type natural language queries and get relevant results
  • Google Talk to Books - search engine that gives results as complete sentences from books that best answer your question
  • Try asking questions and seeing what answers you get here versus when searching on Google
    • Try some abstract/subjective questions like “How can I find happiness?”

REFLECTION: What are some challenges you think search engines run into when trying to understand and answer user’s questions?

5

6 of 28

6

6

Sentiment Analysis With Machine Learning

© AI4ALL, 2019. May be reproduced with permission.

Credit to this article for activity idea

7 of 28

7

7

Sentiment: a view or opinion of something (Oxford)

Sentiment Analysis: a process that a computer performs to measure the positivity or negativity of a text

There are two aspects of sentiment analysis:

  • Determine subjectivity of text (factual vs opinion)
  • Determine polarity of opinion (positive vs negative)

Sentiment

© AI4ALL, 2019. May be reproduced with permission.

8 of 28

8

8

  • Subjectivity - how much of an opinion vs fact something is
  • In our activities, the subjectivity rating will be somewhere between 0 Some articles are just informational articles. Others are opinion pieces.
  • (entirely informational) and 1 (entirely subjective).

Subjectivity

© AI4ALL, 2019. May be reproduced with permission.

9 of 28

9

9

Understanding Check

The subjectivity of each description of the puppy.

0 = Fact

0.5 = somewhat subjective

1 = Entirely Subjective

  • Cute
  • 4-legged
  • Small
  • That dog is 1 foot tall.
  • My neighbor’s dog is so annoying!

© AI4ALL, 2019. May be reproduced with permission.

10 of 28

10

10

  • Polarity - positivity or negativity of opinion
  • May be strong or weak
  • Numerical range from -1 (very negative opinion) to 0 (neutral) to 1 (very positive)

Polarity

© AI4ALL, 2019. May be reproduced with permission.

11 of 28

11

11

Rate the polarity of each description of the puppy.

-1 = very negative opinion

0 = neutral

1 = very positive opinion

  • Adorable
  • Fluffy
  • This puppy destroys everything.
  • It can be hard to take care of a puppy, but often worth it
  • Puppies are the best!
  • Puppies require feeding and exercise.

© AI4ALL, 2019. May be reproduced with permission.

Understanding Check

12 of 28

12

12

DISCUSSION

  • In the next activity we will do sentiment analysis ourselves on songs
  • What do you think gives a song a positive, negative, or neutral sentiment?

© AI4ALL, 2019. May be reproduced with permission.

13 of 28

13

13

Song Sentiment

  • Examples:
    • A song with positive sentiment might be happy, or talk excitedly/fondly about love or friendship
    • A song with a negative sentiment might be sad or angry
    • A song with a neutral sentiment might have an equal mix of lyrics with positive and negative sentiments, or not have lyrics with strong emotions

© AI4ALL, 2019. May be reproduced with permission.

14 of 28

14

Key:

Sentiment score [-1...1]

Polarity - [positive, negative, neutral], [-1...1]

Magnitude - [0 - infinity]

Volume of sentiment conveyed

Subjectivity - subjective, objective, unknown

Twitter-like content == shorter, unformatted text, slang, missing punctuation

15 of 28

15

15

Try It #1 - Song Sentiment Analysis

Activity Overview

  • Google the lyrics of a song that you think have different sentiments (positive, neutral, or negative)
  • Analyze the sentiment of the lyrics, and pick out specific words or phrases that highlight the sentiment
  • Recall that:
    • Subjectivity is how much of an opinion vs fact something is (0 - 1)
    • Polarity is the positive or negative strength of opinion (-1 to 1)
  • On a piece of paper,
    • Prediction - write your song name and prediction
    • Actual - and your answers for them, and then
  • Discussion
    • Share results

© AI4ALL, 2019. May be reproduced with permission.

16 of 28

STUDENT NAME

Song Title

Artist

16

Predicted

Actual

Overall Sentiment Score [-1 to 1]

Polarity [-1 to 1]�Positive, Negative, Neutral

Subjectivity�Subjective, Objective, Unknown

Magnitude [0-infinity]

Use Insert Video to add a quick thumbnail to the song

Make a copy of this slide and complete!

17 of 28

STUDENT NAME

Song Title

Artist

17

Predicted

Actual

Overall Sentiment Score [-1 to 1]

Negative [-.25]

Polarity [-1 to 1]�Positive, Negative, Neutral

Negative [-.25]

Subjectivity�Subjective, Objective, Unknown

Subjective

Magnitude intensity [0-infinity]

1

18 of 28

18

18

DISCUSSION

  • Give a brief introduction to your songs
  • How did you rate your songs in terms of subjective and polarity?
  • What words or phrases in particular lead you to believe that the songs are positive or negative?
  • Did others rate your songs similarly? If not, why do you think they disagreed?

© AI4ALL, 2019. May be reproduced with permission.

19 of 28

TRY IT #2 - COMPARISON OF SENTIMENT ANALYSIS TOOLS

Try out these three online demos and compare the outputs.

19

Not sure you agreed with the sentiment ratings of the other tool.

Let’s try out some other tools …

Goal: Explore

Ratings of song lyrics

  • Look for similarities and differences in the ratings
  • Explain why there are differences
  • Do you agree with the rating?

Representations of Sentiment

  • How does this tool represent sentiment?

20 of 28

20

21 of 28

21

22 of 28

STUDENT NAME

Song Title

Artist

22

Monekeylearn.com�Sentiment Analyzer

Predicted

Actual

Actual

Actual

Overall Sentiment Score [-1 to 1]

Polarity [-1 to 1]�Positive, Negative, Neutral

Subjectivity�Subjective, Objective, Unknown

Other representations of sentiment & ratings

Agreement with Rating

Use Insert Video to add a quick thumbnail to the song

23 of 28

23

23

DISCUSSION

  • Do you disagree with any of the sentiment scores? Why? What do you think made the tool rate the song the way it did?
  • Do you think the average polarity is a good measure of the overall polarity of an artist’s songs? Why or why not?
  • Besides song lyrics, what types of applications can you think of for sentiment analysis?

© AI4ALL, 2019. May be reproduced with permission.

24 of 28

24

24

Takeaways

  • Tools are trained on different datasets which effects what they will recognize or not recognize as positive or negative
  • The dataset used to train these models must label the data. Biases or preferences from labelers might impact the ratings of words. [Note: there should be processes and procedures in place to prevent this.]
  • Ambiguity and context of word use will affect its ratings.

© AI4ALL, 2019. May be reproduced with permission.

25 of 28

APPLICATION ACTIVITY

25

25

26 of 28

CONNECTING TO STUDENTS LIVES

Possible Applications of Sentiment Analysis

  • Cyber-Bullying
  • Misphrased Text Messages
  • Measuring the impact of your words and others
  • Signs of mental health concerns

26

27 of 28

  • HOW BAD IS IT?

  • IS IT INTENTIONAL OR UNINTENTIONAL?

  • IS THIS AN IMPORTANT ISSUES WE SHOULD TRY TO PREVENT?

27

WHAT IS CYBER BULLYING?

28 of 28

DETECTING CYBER BULLYING

28