1
00:00:02,210 --> 00:00:09,330
In this video, you learn how to do sentiment analysis with Python sentiment analysis.

2
00:00:09,350 --> 00:00:14,870
In other word is finding the mood of a piece of text.

3
00:00:15,830 --> 00:00:18,530
So if it is positive or negative?

4
00:00:19,500 --> 00:00:26,160
Let's suppose you want to analyze a tweet or tweet or a Facebook post.

5
00:00:27,360 --> 00:00:35,460
So you can write a program which tells you if that text has a positive attitude or a negative attitude.

6
00:00:35,890 --> 00:00:38,550
And this is known as sentiment analysis.

7
00:00:39,450 --> 00:00:42,730
We're going to work on a Jupyter notebook.

8
00:00:42,750 --> 00:00:47,280
I'm specifically on deep notes here, deep notes, dot com.

9
00:00:48,270 --> 00:00:51,900
And we're going to use analytics for this.

10
00:00:54,980 --> 00:01:05,870
I'm going to use any of the key beakers, and now Turkey has a database which is trained, so it has

11
00:01:06,350 --> 00:01:10,370
all the words and it knows the moods of each word.

12
00:01:12,180 --> 00:01:16,470
That is known as the Vodka Lexicon database.

13
00:01:16,590 --> 00:01:22,470
So first, you need to download that database using analytics of Typekit downloads.

14
00:01:23,810 --> 00:01:31,940
If you're curious, vowed to means valance a word dictionary and sentiments of reason or.

15
00:01:33,050 --> 00:01:37,160
So that is a dataset that you need to download, so execute that cell.

16
00:01:38,890 --> 00:01:48,670
And then creates another code cell, and I'm going to use a variable here and then use a class which

17
00:01:48,670 --> 00:01:53,470
you need to imports from, and I'll take the sentiment.

18
00:01:55,480 --> 00:02:01,060
Imports sentiment, intensity analyzer.

19
00:02:01,480 --> 00:02:06,190
So that is a class that handles all these analyses.

20
00:02:07,030 --> 00:02:14,230
So you want to instantiate that class once you execute that, so then we have access to that class in

21
00:02:14,230 --> 00:02:15,010
this session.

22
00:02:16,210 --> 00:02:22,750
So I'm going to create a new sense of that storage and analyze their variable and then I'm ready to

23
00:02:23,230 --> 00:02:26,140
find the moods of a text.

24
00:02:27,370 --> 00:02:35,800
For example, let's say text one is equal to, Hey, what's a beer food t?

25
00:02:38,280 --> 00:02:40,670
How amazing it is.

26
00:02:41,550 --> 00:02:51,030
So that is the text we want to analyze now, and to do that, you want to point to analyzer that polarity

27
00:02:51,030 --> 00:02:58,260
scores polarity schools will calculate the positivity score and also the negativity coefficient.

28
00:02:58,440 --> 00:03:05,220
So positivity coefficient and negative coefficients or scores, if you want to call it like that.

29
00:03:06,330 --> 00:03:12,570
Inside this goes the text you want to analyze text one in this case and executes.

30
00:03:15,150 --> 00:03:19,890
I've got an error analyzer, it's not defined that I forgot to execute the analyzer definition.

31
00:03:22,690 --> 00:03:25,270
And the Texas well, so there we go.

32
00:03:25,780 --> 00:03:28,190
The output of this is a dictionary.

33
00:03:28,780 --> 00:03:31,390
So let's see what this dictionary is made of.

34
00:03:31,900 --> 00:03:32,890
It has.

35
00:03:33,910 --> 00:03:34,600
These.

36
00:03:35,930 --> 00:03:42,110
Pair of key and value, another pair of keys in value, a third one and the fourth one.

37
00:03:43,130 --> 00:03:51,950
The first one shows the negativity coefficient and in this sense, it's zero, so there's no negativity

38
00:03:51,950 --> 00:03:52,700
in that sentence.

39
00:03:53,060 --> 00:03:56,960
The no child seat coefficient is 0.42.

40
00:03:58,180 --> 00:04:07,960
So the analyzer judges so that this sentence is that percentage of food now translated and actually

41
00:04:07,960 --> 00:04:11,680
for some of these three coefficients is always equal to one.

42
00:04:12,340 --> 00:04:18,610
So in this case, zero point zero plus 0.42 plus 0.58 is equal to one.

43
00:04:19,839 --> 00:04:27,400
So if the coefficient of positivity was less than we would have more in here or more in there so that

44
00:04:27,400 --> 00:04:29,290
we end up with one in total.

45
00:04:30,250 --> 00:04:37,030
So as you can see, this sentence is more positive than neutral and more positive, of course, than

46
00:04:37,030 --> 00:04:37,630
negative.

47
00:04:37,940 --> 00:04:39,760
And then we have this compounds.

48
00:04:39,760 --> 00:04:43,030
Compounds can range from minus one to one.

49
00:04:43,610 --> 00:04:49,600
And the closer it is to one, the more positive the text is.

50
00:04:49,990 --> 00:04:54,070
So that is another way to judge the positivity or text.

51
00:04:54,460 --> 00:05:02,890
You can basically create a conditional nom, such as if the value of compound.

52
00:05:02,980 --> 00:05:09,130
So in accessing the value of the compounds key here so that it will be equal to.

53
00:05:10,510 --> 00:05:12,640
That's coefficient of a compound.

54
00:05:12,850 --> 00:05:17,620
So if that coefficient is greater than zero, then we print out.

55
00:05:19,880 --> 00:05:31,100
Positive text else, print out negative text and then we're going to get positive text since compound

56
00:05:31,100 --> 00:05:33,140
was greater than zero.

57
00:05:33,410 --> 00:05:43,740
If you want to go further and practice this, you can use the suite to samples which are available from

58
00:05:43,740 --> 00:05:45,740
an case, so you need to download them.

59
00:05:48,660 --> 00:05:52,860
Using Twitter samples here.

60
00:05:53,220 --> 00:05:54,120
So Exec. that.

61
00:05:56,370 --> 00:05:59,220
I'll fix the typo download.

62
00:06:00,920 --> 00:06:01,550
There we go.

63
00:06:01,790 --> 00:06:12,790
Then down here, you can access Twitter samples using an L T K Dot corpus.

64
00:06:13,360 --> 00:06:19,870
Twitter samples so the dataset, we have just downloaded the strings.

65
00:06:20,840 --> 00:06:25,520
This method will give us a big list of tweets.

66
00:06:28,290 --> 00:06:29,710
So that's a lot of them.

67
00:06:29,730 --> 00:06:37,650
You can check the length of this and we see the total number of tweets in this list.

68
00:06:37,950 --> 00:06:40,020
So that is a list of strings.

69
00:06:40,380 --> 00:06:42,870
We have 30000 tweets in here.

70
00:06:43,390 --> 00:06:51,150
So if you want to extract a single tweet, so tweets one, for example, is equal to that.

71
00:06:54,410 --> 00:07:04,430
And just gets, for example, the tweets exposition fully to and that will give us one single tweet.

72
00:07:08,690 --> 00:07:17,840
So that is the tweets, and you can analyze these tweets now using the same analyzer, so an analyzer

73
00:07:18,690 --> 00:07:21,050
dot polarity scores.

74
00:07:22,370 --> 00:07:30,860
And here goes the tweet tweet the one in this case, and then we see whether the negativity is 0.2 here.

75
00:07:31,190 --> 00:07:40,340
Neutrality 0.56 and positivity is a bit higher than negativity.

76
00:07:40,340 --> 00:07:40,580
Sort of.

77
00:07:40,580 --> 00:07:45,470
The compound's coefficient is more towards positivity.

78
00:07:46,370 --> 00:07:47,900
Let's try another one.

79
00:07:48,320 --> 00:07:51,020
One thousand forty five.

80
00:07:52,800 --> 00:08:00,330
So you can go up to 3000 and say, hmm, this should be quite negative.

81
00:08:00,840 --> 00:08:02,700
I expect, so let's try.

82
00:08:03,600 --> 00:08:08,410
Yeah, so the compound coefficient is minus zero point eight.

83
00:08:08,920 --> 00:08:18,630
Obviously, that is how you can analyze the moods of texts, and this can have many, many applications.

84
00:08:18,870 --> 00:08:25,500
So I just give you an example, a general example, but you can do different things like you can even

85
00:08:25,500 --> 00:08:31,290
analyze old you in the course you have a lecture on speech recognition.

86
00:08:31,290 --> 00:08:37,950
So you can you can convert the old you to text and then find the moods of texts.

87
00:08:38,520 --> 00:08:43,260
So technically, you're finding the moods of the speech in the old you.

88
00:08:44,390 --> 00:08:45,830
That's one more example.

89
00:08:45,880 --> 00:08:51,830
But it's up to you what you can do with this analyzer, so I hope this works for you.

90
00:08:51,830 --> 00:08:54,080
I hope you like it and I'll talk to you later.

91
00:08:54,130 --> 00:08:54,410
See you!

