Sentiment Analysis extracting emotion through machine learning

[Music]

[Laughter]

[Applause]

reaching your pockets

hopefully your phone’s still there

our phones do a lot for us they check

the weather

they remind us to turn on our alarm just

in case we don’t

wake up the next morning but there’s one

thing

our phones can’t do yet tell us how we

are

hey siri how am i doing today

okay google how are my emotions today

see these seem like ridiculous questions

but with advancements in sentiment

analysis and machine learning

our machines are becoming closer to

answering

these very questions let me give you a

sentence

i love that movie and i asked you to

rate it out of the 10

with 0 being negative and 10 being

positive

now we’d all agree that this is a pretty

positive sentence

and give it around to 10. let’s change

the verb a bit

i liked that movie here

still pretty positive but clearly lower

on the scale

now let’s go to the other end of the

spectrum

i hated that movie now whoever said this

clearly feels negatively about the

subject and so we’d probably give this

around a zero now sentiment analysis

is simply using machine learning to

teach computers

to do just this extract

the sentiments out of our sentences

now how does this work what is machine

learning

machine learning is simply like a

function in math

you give it one or many numbers and it

spits out another

in machine learning these functions are

called

models now these models are often neural

networks

that simulate the structures of our

brains

to set to get inputs and their

associations

to build models predicting future inputs

now here’s joe who’s joe you might ask

joe’s our friendly neighborhood machine

learning model of course

now we want joe to tell us whether or

not this

image is a tiger see

joe’s pretty sad right now because he

has no clue what to do

here is where we train our model

in order for joe to tell us what a tiger

is and what a tiger isn’t

we as humans must need to first tell him

what a tiger looks like and what it

doesn’t

there’s a slight problem here however

joe doesn’t see this image like we do

the one thing joe can do however is

interpret numbers

so what we can do is give these images

to joe

as a list of numbers of rgb vectors

for each pixel now let me break that

down

rgb vectors are red green blue vectors

for each pixel

denoting the color of each pixel in an

image

now what that effectively allows us to

do is convert these images

into numbers that’s great joe can now

understand what we’re trying to give him

he knows what he’s trying to do

now what we can do when given an

unfamiliar image

is turn this into rgb vectors

give it to joe and hey what do you know

he thinks it’s a tiger he’s 97 sure

actually

so this was the case with pictures with

images

but we’re talking about sentences the

thing is

it’s exactly the same how

do we turn words into numbers

now some of you might be thinking let’s

just slap a number on each word and

call it a day but the thing is if we

train

our models using those vector inputs

we’d run into a problem this method

struggles to recognize the semantic

similarity

between words for example this method

fails to recognize

similarity between a word such as loved

and liked

as opposed to a low similarity between

loved

and hated here is where we run

into one of the most fundamental

concepts in sentiment analysis

word vectors now what are verb vectors

well they’re exactly as they would seem

they’re vectors corresponding to each

word

much like the rgb vectors for each pixel

now unlike the rgb vectors however

these word vectors can span from 25 up

to a thousand components

now conveniently as these vectors are

still simply a list of numbers

they can be plotted on an n dimensional

space

but for the sake of visualization and

your brains let’s reduce that down

to two

on this coordinate plane what word

vectors allow

us to do is to demonstrate and evaluate

the relationships between words as

distances

between points now somewhere on this

coordinate plane

lion and cat would be near each other

related by their fellini

while somewhere else on the plane honda

and

ford would be clustered together related

by their car manufacturing status

now this seems to be working great

what’s the problem

well the problem comes in when we add in

more words

what would we do about the word jaguar

now it is a feline so does it

go somewhere near cat and lion no but it

is a car manufacturer

somewhere in the middle we have no clue

we’ve run into the dilemma which makes

it possible for word vectors to be

multi-dimensional

by adding more vectors by adding more

dimensions to these vectors

we’re able to express the relationships

between

words in the english language with more

nuance

great now we have these word vectors and

we can associate them

to the words in our sentence converting

them to numbers

that joe loves theoretically now

we can feed these numbers to joe and joe

will now be able to predict the

sentiment of any sentence we give it

so naturally i decided to put that to

the test

where would i get my data to train this

model

well after some searching i decided to

go with kaggle’s twitter sentiment data

set

consisting of 1.5 million tweets

manually categorized by either zero for

negative

or one for positive now you might be

thinking hold up 1.5

million tweets it’s a lot of tweets and

that is true it is a lot

of tweets but just as you and i

will be better at identifying something

the more examples you got of it

joe can benefit from as much data as we

can give it as for our word vectors

however

i went with stanford university’s glove

stand for global

vectors now this word vector set

was pre-created which means that these

researchers had to go through

thousands and thousands of sentences

look at instances for each word

and evaluate their context to create

word vectors

for each and every word

there was one more step i had to take

before i could train

joe however let’s look at this tweet

stopped at mcdonald’s for lunch i’m

excited

nuggets now if we fed this

right to our model we’d see a problem

see us as humans can see through the

twitter clutter can

see through the various distractions

in this tweet but for joe joe needs a

bit

of help and that’s why we need to clean

this data set show you what i mean

the first things to go were punctuation

along with punctuation when twitter

artifacts such as mentions hashtags and

links

second went are what recalled in natural

language processing

as stop words words such as as

if i and that don’t necessarily add to

the meaning of the sentence

now finally and arguably the most

tricky part of cleaning this data set

was how to deal with internet

slang now it’s impossible to go anywhere

on the internet without encountering

some sort of abbreviation some sort of

slang

the tough part about dealing with this

is that there is no set

way of evaluating these words

now to be fair common words such as

law or lmao all have their individual

entries in word vector sets such as

glove

now misspellings such as the one we see

in this tweet here

can be caught with a spell check but

some

words and phrases do end up slipping

through our fingers

and that does make or break some

sentiment analysis models

now regardless we’ve caught that

and now we were able to condense that

original tweet

into the four words that you see on the

bottom there

now that we’ve cleaned our tweets we can

associate the word vectors

in gloves to each word and now

again we have our numbers to word

association

and can now train our model

that’s exactly what i did now

how is my model you might be asking how

good was it

well luckily for the safety of the

internet world as we know it

i wasn’t that successful my model

reached around a 60

accuracy which meant that it was able to

correctly identify the sentiments of

around 60 percent of the sentences that

i gave it

however considering that this is a

problem that has yet to be solved

this number is a sign of hope for things

to come

now throughout this talk you might have

been asking yourself why do we care who

asked andy what’s next

and i’m here to tell you this it’s true

this technology is bringing us ever so

closer

to our inevitable robot overlord

world but i still believe that this

technology

is imperative and essential to our

technological

development for the benefits that it can

provide

now currently the applications of

sentiment analysis

are purely commercial we see movie

producers using sentiment analysis

to evaluate audience feedback on their

recent projects

we see corporations including this

technology

to assess how consumers are reacting to

their products

but in the future as this technology

gets better we can see

that this technology can be applied to a

myriad

of problems for example sentiment

analysis could be used

to provide help for people with mental

health issues

many people with these issues find

refuge

in the internet and so with this

technology we’ll be able to provide

help for people that might have been

reluctant to seek it

furthermore this technology could be

used to gauge radicalism on the internet

as the internet has become a hub for

radicalization

we can see that this technology can be

used by governments

to make the internet safer for us all

and hey if that didn’t reach all of you

then maybe our phones can become a

therapist one day

hey siri how am i doing thank you

[Applause]

you