What’s Love Got To Do With It? Ruby and Sentiment Analysis

A presentation at Birmingham on Rails in January 2020 in Birmingham, AL, USA by Ben Greenberg

Slide 1

Slide 1

What’s Love Got To Do With It? Ruby and Sentiment Analysis @RABBIGREENBERG

Slide 2

Slide 2

Hello! • I 💙 Ruby • Former rabbi & community organizer • 🌎 San Diego ↝ NYC ↝ Boston ↝ Denver ↝ Tel Aviv 🌍 • Developer Advocate @ Nexmo @RABBIGREENBERG

Slide 3

Slide 3

Our Roadmap @RABBIGREENBERG A. B. C. D. E. Why does this matter? What is sentiment analysis? What can I build with it? Let’s build it! Test Run and Data Analysis

Slide 4

Slide 4

Why does this matter? @RABBIGREENBERG

Slide 5

Slide 5

Language is not only a passive vehicle for information @RABBIGREENBERG

Slide 6

Slide 6

“Last night I had dinner with… someone, it was delicious“ @RABBIGREENBERG

Slide 7

Slide 7

‫’’אתמול בערב אכלתי‬ ‫ארוחת ערב עם…‬ ‫מישהו ‪ ,‬היא‬ ‫טעיימה’’‬ ‫‪@RABBIGREENBERG‬‬

Slide 8

Slide 8

Egocentric or Geocentric? @RABBIGREENBERG

Slide 9

Slide 9

… if you saw a Guugu Yimithirr speaker pointing at himself, you would naturally assume he meant to draw attention to himself. In fact, he is pointing at a cardinal direction that happens to be behind his back. While we are always at the center of the world, a Guugu Yimithirr speaker points through himself… - Guy Deutscher, The New York Times, 2010 @RABBIGREENBERG

Slide 10

Slide 10

“When a language dies, a way of understanding the world dies with it, a way of looking at the world.” - George Steiner @RABBIGREENBERG

Slide 11

Slide 11

Language is a conduit constructor @RABBIGREENBERG

Slide 12

Slide 12

Understanding language helps us in understanding human society @RABBIGREENBERG

Slide 13

Slide 13

Algorithms can assist in getting us there @RABBIGREENBERG

Slide 14

Slide 14

What is Natural Language Understanding & Sentiment Analysis? @RABBIGREENBERG

Slide 15

Slide 15

“ I believe that at the end of the century the use of words and general educated opinion will have altered so much that one will be able to speak of machines thinking without expecting to be contradicted. “

  • Alan Turing, 1950 @RABBIGREENBERG

Slide 16

Slide 16

“Last night I had dinner with someone, it was delicious“ @RABBIGREENBERG

Slide 17

Slide 17

Natural Language Processing @RABBIGREENBERG

Slide 18

Slide 18

Formal Grammar Inflectional Endings Part-of-speech (POS) tagging Parsing sentences Sentence boundaries Root form of words @RABBIGREENBERG

Slide 19

Slide 19

Segment continuous text into separate words (prevalent in many languages) Relationships of named entities to each other (who to whom, what to what, etc.) Topic segmentation Word meaning probability @RABBIGREENBERG

Slide 20

Slide 20

What’s my polarity? “I’d really truly “I’d really “I love my mobiletruly but love going lovenot going outout inin would recommend it thiscolleagues.” weather!” to any of my this weather!” “I dislike broken cars.” *examples from Wikipedia @RABBIGREENBERG

Slide 21

Slide 21

What can I make with it? @RABBIGREENBERG

Slide 22

Slide 22

Sometimes you just need to get to the point @RABBIGREENBERG

Slide 23

Slide 23

…and just tell me What’s the mood of the news? @RABBIGREENBERG

Slide 24

Slide 24

WHAT ARE WE BUILDING (1) “topic” (2) (3) @RABBIGREENBERG

Slide 25

Slide 25

Let’s build it @RABBIGREENBERG

Slide 26

Slide 26

What APIs will we be using? NEWS API “Search worldwide news with code” Generous free access tier Ruby SDK Documentation www.newsapi.org IBM WATSON Natural Language Analyzer API Generous free access tier Ruby SDK Documentation www.ibm.com/watson/developer NEXMO Messages API Generous free access tier Ruby SDK Documentation developer.nexmo.com @RABBIGREENBERG

Slide 27

Slide 27

Gemfile @RABBIGREENBERG

Slide 28

Slide 28

@RABBIGREENBERG

Slide 29

Slide 29

Routes @RABBIGREENBERG

Slide 30

Slide 30

@RABBIGREENBERG

Slide 31

Slide 31

Environment Variables @RABBIGREENBERG

Slide 32

Slide 32

@RABBIGREENBERG

Slide 33

Slide 33

Controller @RABBIGREENBERG

Slide 34

Slide 34

Defining Methods @rabbigreenberg @RABBIGREENBERG

Slide 35

Slide 35

#inbound @RABBIGREENBERG

Slide 36

Slide 36

#analyze_headlines @RABBIGREENBERG

Slide 37

Slide 37

#get_news_headlines @RABBIGREENBERG

Slide 38

Slide 38

_ p p a s t a h w _ d n #se msg @RABBIGREENBERG

Slide 39

Slide 39

#generate_jwt_token @RABBIGREENBERG

Slide 40

Slide 40

Giving It A Go @RABBIGREENBERG

Slide 41

Slide 41

@RABBIGREENBERG

Slide 42

Slide 42

Examining the Data @RABBIGREENBERG

Slide 43

Slide 43

What were the headlines? @RABBIGREENBERG IBM, Microsoft, a medley of others sing support for Google against Oracle in Supremes Java API copyright case Future-proof your tech skills with the Ultimate Deep Learning Bundle An Illuminated Dress Made With FLORA and Neopixels from The Dressed Aesthetic #WearableWednesday @dressed_app George Cheeks Exits As Vice Chairman of NBCUniversal Content Studios To win in a shifting market, the streaming industry is bundling up How CollegeHumor lost its early lead The Rundown: Video metrics will never be totally reliable 台積電 5 奈奈⽶米即將量量產,可望獨拿蘋果、華為訂單 Sequential’s Pro 3 is a new Prophet, while the others clone – so how does it stack up? The Continental: John Wick TV Show Is ‘Moving Along,’ Says Starz Boss iOS 13.3.1 Public Beta 2 Is Back After A Long Hiatus Perfect Sense unveils Gyro to simplify cloud infrastructure management “Stargirl” Is Ready to Embrace Her Destiny – But Will She Survive The Passing of The Cosmic Staff? [TRAILER] “Crisis” Management: Yup, Grant Gustin’s The Flash Just Met [SPOILER] – Snyder Cut of “Crisis” to Follow? “Crisis” Management: What’s A Little “Universal Domination” Among Enemies – Right, Lex? [PREVIEW] Labbers of the World Unite to Write a Book in 1 Week Through a Book Sprint Instagram Makes Long-Lived Access Tokens Available for the Instagram Basic Display API Aaron Rodgers jokes he’ll ‘definitely’ shake Richard Sherman’s hand 49ers’ turnaround, win improvement has put team in exclusive company NFL rumors: 49ers’ Joe Woods finalist for Browns defensive coordinator

Slide 44

Slide 44

In Numbers 18 Headlines in Sample 7 Programming Related 38.8% of Sample Directly Related to Topic @RABBIGREENBERG

Slide 45

Slide 45

In other words… Always examine your data. @RABBIGREENBERG

Slide 46

Slide 46

Examining the Analysis @RABBIGREENBERG

Slide 47

Slide 47

What were the sentiment results? Score: -0.62093 Label: negative @RABBIGREENBERG

Slide 48

Slide 48

What were the emotion results? @RABBIGREENBERG

Slide 49

Slide 49

Why the discrepancy? @RABBIGREENBERG

Slide 50

Slide 50

To understand we return to the data What were the concepts identified? @RABBIGREENBERG

Slide 51

Slide 51

Concept Scoring Concept Relevance Board of Directors 90% Richard Sherman 87% Chairman 84% Application Programming Interface 83% @RABBIGREENBERG

Slide 52

Slide 52

Where does this leave us? @RABBIGREENBERG

Slide 53

Slide 53

“ I believe that at the end of the century the use of words and general educated opinion will have altered so much that one will be able to speak of machines thinking without expecting to be contradicted. “

  • Alan Turing, 1950 @RABBIGREENBERG

Slide 54

Slide 54

Thank you! @RABBIGREENBERG

Slide 55

Slide 55

Resources • • • • • • Deutscher, G. (2010). Through the Language Glass: Why The World Looks Different in Other Languages, Metropolitan Books Giannakidou, A. (2011). Positive polarity items and negative polarity items: variation, licensing, and compositionality, University of Chicago IBM Watson Natural Language Understanding API Reference: https://cloud.ibm.com/apidocs/natural-language-understanding/ natural-language-understanding Nexmo Messages API Reference: https://developer.nexmo.com/api/messages-olympus News API Reference: https://newsapi.org/docs “Mood of the News” GitHub Repository: https://github.com/Nexmo/mood-of-the-news @RABBIGREENBERG