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

A presentation at RubyConf in November 2019 in Nashville, TN, USA by Ben Greenberg

Slide 1

Slide 1

“Without knowing the force of words, it is impossible to know more.” –Confucius “My dispatches are merely dry matter of fact and detail.” –Lawrence Gobright, Washington AP Chief (1856) @rabbigreenberg

Slide 2

Slide 2

What’s Love Got To Do With It? Ruby and Sentiment Analysis Ben Greenberg @rabbigreenberg

Slide 3

Slide 3

Who is talking right now? 🤔 (i.e. Hi! “) • I 💙 Ruby • Co-editor of Torah && Tech • Former rabbi & community organizer • 🌎 San Diego ↝ NYC ↝ Boston ↝ Denver ↝ NYC ↝ Tel Aviv 🌍 • Developer Advocate @ Nexmo @rabbigreenberg

Slide 4

Slide 4

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

Slide 5

Slide 5

Why does this matter? @rabbigreenberg

Slide 6

Slide 6

Language is not only a passive vehicle for information @rabbigreenberg

Slide 7

Slide 7

“Last night I had dinner with… someone, it was delicious“ ‫’’אתמול בערב‬ ‫אכלתי ארוחת ערב‬ …‫עם‬ ‫ היא‬, ‫מישהי‬ ’’‫טעיימה‬ @rabbigreenberg

Slide 8

Slide 8

Language is a conduit constructor @rabbigreenberg

Slide 9

Slide 9

What is sentiment analysis? @rabbigreenberg

Slide 10

Slide 10

“ 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 11

Slide 11

“Last night I had dinner with someone, it was delicious“ “sentiment”=>{“document”=>{“score”=>0.970908, “label”=>”positive”}} “semantic_roles”=>[{“subject”=>{“text”=>”I”}, “sentence”=>”Last night I had dinner with someone, and it was delicious.”, “object”=>{“text”=>”dinner”}, “action”=>{“verb”=>{“text”=>”have”, “tense”=>”past”}, “text”=>”had”, “normalized”=>”have”}}], “keywords”=>[{“text”=>”Last night”, “relevance”=>0.998604, “count”=>1}, {“text”=>”dinner”, “relevance”=>0.672861, “count”=>1}], “emotion”=>{“sadness”=>0.049938, “joy”=>0.857958, “fear”=>0.041413, “disgust”=>0.034346, “anger”=>0.025449}}}, “categories”=>[{“score”=>0.658246, “label”=>”/food and drink/food”, “explanation”=>{“relevant_text”=>[{“text”=>”dinner”}]}}, {“score”=>0.65732, “label”=>”/ food and drink/desserts and baking” @rabbigreenberg

Slide 12

Slide 12

Natural Language Processing • Formal Grammar • Inflectional Endings • Part-of-speech (POS) tagging • Parsing sentences • Sentence boundaries • Root form of words • 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 13

Slide 13

Slide 14

Slide 14

What’s my polarity? “I love my mobile “I’d really truly but would not “I dislike love going out in recommend it to any broken cars.” this weather!” of my colleagues.” *examples from Wikipedia @rabbigreenberg

Slide 15

Slide 15

What can I make with it? @rabbigreenberg

Slide 16

Slide 16

@rabbigreenberg

Slide 17

Slide 17

Sometimes you just need to get to the… @rabbigreenberg

Slide 18

Slide 18

@rabbigreenberg

Slide 19

Slide 19

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

Slide 20

Slide 20

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

Slide 21

Slide 21

Let’s build it! @rabbigreenberg

Slide 22

Slide 22

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

Slide 23

Slide 23

Gemfile

Slide 24

Slide 24

@rabbigreenberg

Slide 25

Slide 25

Routes

Slide 26

Slide 26

@rabbigreenberg

Slide 27

Slide 27

Environment Variables

Slide 28

Slide 28

@rabbigreenberg

Slide 29

Slide 29

Controller

Slide 30

Slide 30

Defining Methods @rabbigreenberg

Slide 31

Slide 31

#inbound @rabbigreenberg

Slide 32

Slide 32

#analyze_headlines @rabbigreenberg

Slide 33

Slide 33

#get_news_headlines @rabbigreenberg

Slide 34

Slide 34

#send_whatsapp_msg @rabbigreenberg

Slide 35

Slide 35

#send_whatsapp_msg @rabbigreenberg

Slide 36

Slide 36

#send_whatsapp_msg @rabbigreenberg

Slide 37

Slide 37

#generate_jwt_token @rabbigreenberg

Slide 38

Slide 38

Giving It A Go!

Slide 39

Slide 39

@rabbigreenberg

Slide 40

Slide 40

Thank you! @rabbigreenberg https://github.com/Nexmo/mood-of-the-news