sa_bayes.tex 20.2 KB
Newer Older
1
2
3
4
5
6
7
% !TEX root = text_processing.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{}

\vfill
\centering
Loïc Barrault's avatar
Loïc Barrault committed
8
\Huge{\edinred{[Sentiment Analysis]\\Corpus-based / Machine Learning}}
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Sentiment Analysis: 2 main approaches}

\begin{itemize}
\item {\bf \color{lightgray} Lexicon based}
\begin{itemize}
	\item {\bf \color{lightgray} Binary}
	\item {\bf \color{lightgray} Gradable}
\end{itemize}
\item \textbf{Corpus based}
\begin{itemize}
	\item \textbf{Naive Bayes}
	\item Deep Learning 
\end{itemize}
\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Bayes classifier}

\begin{block}{Principle}
Assign the \myemph{sentiment} or \myemph{class} having the highest \textbf{posterior probability}.\\
Namely, determine the sentiment $\vm{s^*}$ of text $T$ such that:\\
\begin{equation*}
\vm{s^*} = \argmax_{s_i} p(s_i | T) \mathrm{~for~} s_i \in  \{\red{\bf negative}, \green{\bf positive}, \orange{\bf neutral}\}
\end{equation*}
\end{block}

Loïc Barrault's avatar
Loïc Barrault committed
43
$p(s_i | T)$ cannot be directly estimated correctly \ra\ use the Bayes rule:
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
\begin{equation*}
p(s_i | T) = \frac{p(T|s_i)p(s_i)}{p(T)}
\end{equation*}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Bayes classifier}

Bayes rule:
\begin{equation*}
\vm{s^*} = \argmax_{s_i} \frac{p(T|s_i)p(s_i)}{p(T)} %\mathrm{~for~} s_i \in  \{\red{\bf negative}, \green{\bf positive}, \orange{\bf neutral}\}
\end{equation*}

Since \textbf{evidence} $p(T)$ is independent of $s_i$, we can ignore it
\begin{equation*}
\vm{s^*} = \argmax_{s_i} p(T|s_i)p(s_i) %\mathrm{~for~} s_i \in  \{\red{\bf negative}, \green{\bf positive}, \orange{\bf neutral}\}
\end{equation*}

\begin{itemize}
\item $p(s_i | T)$ is the \textbf{posterior probability}
\item $p(T|s_i)$ is the \textbf{likelihood}
\item $p(s_i)$ is the \textbf{prior probability}
\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes classifier}

\textbf{How to compute the likelihood?}\\
Assume that $T$ is described by a number of \myemph{features} or attributes $t_1, t_2, ..., t_N$\\
\textbf{Naive} assumption: \myemph{features} are \textbf{independent}
\begin{equation*}
p(T|s_i) = p(t_1, t_2, ..., t_N|s_i) \approx \prod_{j=1}^{N} p(t_j|s_i)
\end{equation*}

\Ra\ product of probabilities of each \myemph{feature} value of text occurring with class $s_i$

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes classifier}

\textbf{How to compute the prior probability?}\\
\ra\ corresponds to the safest decision when no other information is given $\sim$ majority voting

Requires an \textbf{annotated corpus} (text along with their sentiment)\\
Compute \textbf{prior probability} by simple relative frequency
\begin{equation*}
p(s_i) = \frac{count(s_i)}{\ds \sum_{j=0}^J  count(s_j)}
\end{equation*}
with $J$ the number of different classes and $count(.)$ is the counting function


\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Digression: corpus based machine learning}

Corpora:
\begin{itemize}
\item \myemph{training} set \ra\ used to \textbf{estimate probabilities}
\begin{itemize}
\item input data along with the ground truth (correct labels)
\end{itemize}

\item \myemph{development} set, also called \myemph{validation} set \ra\ used to \textbf{design} the model
\begin{itemize}
\item e.g. feature selection, set meta-parameters (could be some weights)
\item ground truth (correct labels) available
\item used to select the best model
\end{itemize}

\item \myemph{test} set \ra\ used to \textbf{evaluate generalisation} power 
\begin{itemize}
\item unseen examples
\item best case: no access to the ground truth
\end{itemize}
\end{itemize}

\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes classifier}

\vfill

\begin{block}{Final decision}
\begin{equation*}
\vm{s^*} = \argmax_{s_i} p(s_i)\prod_{j=1}^{N} p(t_j|s_i) 
\end{equation*}
\end{block}

\begin{enumerate}
\item Compute prior probability of each class
\item For each class:
\begin{itemize}
	\item Compute likelihood of each feature
\end{itemize}
\item Calculate the posterior probability by product of previous components
\item Select sentiment having maximum posterior probability
\item[\ra] \red{\bf negative}, \green{\bf positive} or \orange{\bf neutral}
\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis - Example}

Consider the following dummy \myemph{training} corpus of 7 movie reviews:
\vfill
\begin{tabular}{lll}
Doc & Words & Class  \\ \toprule
1 & Great movie, excellent plot, renowned actors  & \green{\bf positive} \\
2 & I had not seen a fantastic plot like this in good 5 years. Amazing!!! &  \green{\bf positive} \\ 
3 & Lovely plot, amazing cast, somehow I am in love with the bad guy & \green{\bf positive} \\ 
4 & Bad movie with great cast, but very poor plot and unimaginative ending  &  \red{\bf negative} \\ 
5 & I hate this film, it has nothing original &  \red{\bf negative} \\ 
6 & Great movie, but not... & \red{\bf negative}  \\ 
7 & Very bad movie, I have no words to express how I dislike it & \red{\bf negative} \\
\bottomrule
\end{tabular}
\vfill
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis - Example}

\textbf{Compute prior probability of each class by relative frequency}

\begin{equation*}
p(\green{\bf positive}) = \frac{count(\green{\bf positive})}{\ds \sum_{s \in \{\green{\bf positive}, \red{\bf negative}\}}^J  count(s)} = \frac{3}{7} = 0.43
\end{equation*}
\vfill
\begin{equation*}
p(\red{\bf negative}) = \frac{count(\red{\bf negative})}{\ds \sum_{s \in \{\green{\bf positive}, \red{\bf negative}\}}^J  count(s)} = \frac{4}{7} = 0.57
\end{equation*}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis - Example}

What \textbf{features} should we consider?

\begin{itemize}
\item could use \textbf{all} words
\begin{itemize}
\item but some might not be relevant \ra\ we are interested in the \myemph{emotion words}
\item use the \myemph{development} corpus to decide!
\end{itemize}
\item in this example: focus on \textbf{adjectives} (\textbf{bag-of-word} representation)
\end{itemize}

\vfill
\only<1>{
\small{
\begin{center} 
\begin{tabular}{lp{.7\textwidth}l}
Doc & Words & Class  \\ \toprule
1 & \textbf{Great} movie, \textbf{excellent} plot, \textbf{renowned} actors  & \green{\bf positive} \\
2 & I had not seen a \textbf{fantastic} plot like this in \textbf{good} 5 years. \textbf{Amazing !!!} &  \green{\bf positive} \\ 
3 & \textbf{Lovely} plot, \textbf{amazing} cast, somehow I am in love with the \textbf{bad} guy & \green{\bf positive} \\ 
4 & \textbf{Bad} movie with \textbf{great} cast, but very \textbf{poor} plot and \textbf{unimaginative} ending  &  \red{\bf negative} \\ 
5 & I hate this film, it has nothing \textbf{original} &  \red{\bf negative} \\ 
6 & \textbf{Great} movie, but not... & \red{\bf negative}  \\ 
7 & Very \textbf{bad} movie, I have no words to express how I dislike it & \red{\bf negative} \\
\bottomrule
\end{tabular}
\end{center}}}

\only<2>{
\small{
\begin{center} 
\begin{tabular}{lp{.7\textwidth}l}
Doc & Words & Class  \\ \toprule
1 & \textbf{Great} \textbf{excellent} \textbf{renowned}  & \green{\bf positive} \\
2 & \textbf{fantastic} \textbf{good} \textbf{Amazing !!!} &  \green{\bf positive} \\ 
3 & \textbf{Lovely} \textbf{amazing} \textbf{bad} & \green{\bf positive} \\ 
4 & \textbf{Bad} \textbf{great} \textbf{poor} \textbf{unimaginative} &  \red{\bf negative} \\ 
5 & \textbf{original} &  \red{\bf negative} \\ 
6 & \textbf{Great} & \red{\bf negative}  \\ 
7 & \textbf{bad} & \red{\bf negative} \\
\bottomrule
\end{tabular}
\end{center}}}



\vfill
\end{frame}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis - Example}

\textbf{Compute the likelihoods for all features and given each class}

\vfill 

\begin{block}{Important}
Assume standard pre-processing: tokenisation, lowercasing, punctuation removal (but keep special punctuation, e.g. "!!!")\
\end{block}

Examples:
\begin{itemize}
\item GOOD = GooD = Good = good
\item I'll = I will (though not relevant here)
\item aren't = are not
\end{itemize}

\vfill
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis - Example}

\textbf{Compute the likelihoods for all features and given each class}

\begin{equation*}
p(t_j|s_i)  = \frac{count(t_j,s_i)}{count(s_i)} \text{~~~~~~\ra\ \textbf{relative frequency}}
\end{equation*}

\centering 
\scriptsize{
\renewcommand{\arraystretch}{0.8}% Tighter
\begin{tabular}{rl|rl}
p(amazing|\green{\bf positive})  &= 2/10	&	p(amazing|\red{\bf negative}) 		&= 0/8	\\
p(bad|\green{\bf positive}) 	&= 1/10	&		p(bad|\red{\bf negative}) 		&= 3/8 \\
p(excellent|\green{\bf positive}) &= 1/10	&		p(excellent|\red{\bf negative}) 	&= 0/8 \\
p(fantastic|\green{\bf positive}) 	&= 1/10	&		p(fantastic|\red{\bf negative}) 	&= 0/8 \\
p(good|\green{\bf positive}) 	&= 1/10	&		p(good|\red{\bf negative}) 		&= 0/8 \\
p(great|\green{\bf positive}) 	&= 1/10	&		p(great|\red{\bf negative}) 		&= 2/8 \\
p(lovely|\green{\bf positive}) 	&= 1/10	&		p(lovely|\red{\bf negative}) 	&= 0/8 \\
p(original|\green{\bf positive}) 	&= 0/10	&		p(original|\red{\bf negative}) 	&= 1/8 \\
p(poor|\green{\bf positive}) 	&= 0/10	&		p(poor|\red{\bf negative}) 		&= 1/8 \\
p(renowned|\green{\bf positive}) &= 1/10	&		p(renowned|\red{\bf negative})  &= 0/8 \\
p(unimaginative|\green{\bf positive}) &= 0/10	&	p(unimaginative|\red{\bf negative}) &= 1/8 \\
p(!!!|\green{\bf positive}) 		&= 1/10	&		p(!!!|\red{\bf negative}) 		&= 0/8 \\
\end{tabular}
}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis - Example}

\textbf{Relative frequencies} for prior and likelihoods make the model in a Naive Bayes classifier\\
\ra\ features are supposed independent (no covariance taken into account)\\
\ra\ this is an approximation of course
\vfill
\textbf{What is the model?}\\
\ra\ the set of all prior probabilities and likelihoods 
\vfill
At \myemph{test} time, this model is used to find the most likely class (sentiment) for the unknown text\\
\begin{equation*}
\vm{s^*} = \argmax_{s_i} p(s_i)\prod_{j=1}^{N} p(t_j|s_i) 
\end{equation*}
\vfill
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis - Text Ex. 1}

Consider the following test segment to classify:\\
\begin{enumerate}
\item<2-> Extract features
\item<3-> Build representation 
\end{enumerate}

\only<1>{
\begin{center} 
\begin{tabular}{lp{.7\textwidth}c}
Doc & Words & Class  \\ \toprule
8 & This was a fantastic story, great, lovely & ? \\
\bottomrule
\end{tabular}
\end{center}}

\only<2>{
\begin{center} 
\begin{tabular}{lp{.7\textwidth}c}
Doc & Words & Class  \\ \toprule
8 & This was a \textbf{fantastic} story, \textbf{great}, \textbf{lovely} & ? \\
\bottomrule
\end{tabular}
\end{center}}

\only<3->{
\begin{center} 
\begin{tabular}{lp{.7\textwidth}c}
Doc & Words & Class  \\ \toprule
8 & \textbf{fantastic} \textbf{great} \textbf{lovely} & ? \\
\bottomrule
\end{tabular}
\end{center}}

\vfill

\only<4->{
\begin{enumerate}
\setcounter{enumi}{2}
\item<4-> Get likelihoods
\end{enumerate}

\centering 
\renewcommand{\arraystretch}{0.8}% Tighter
\begin{tabular}{rl|rl}
p(fantastic|\green{\bf positive}) 	&= 1/10	&		p(fantastic|\red{\bf negative}) 	&= 0/8 \\
p(great|\green{\bf positive}) 	&= 1/10	&		p(great|\red{\bf negative}) 		&= 2/8 \\
p(lovely|\green{\bf positive}) 	&= 1/10	&		p(lovely|\red{\bf negative}) 	&= 0/8 \\
\end{tabular}
}
\vfill
\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis - Text Ex. 1}

\small{
\begin{eqnarray*}
p(\green{\bf positive}| text) & = & p(\green{\bf positive}) * p(fantastic|\green{\bf positive}) * p(great|\green{\bf positive}) * p(lovely|\green{\bf positive})\\
					& = & 3/7 * 1/10 * 1/10 * 1/10\\
					& = & \green{\bf 0.00043}
\end{eqnarray*}
}
\small{
\begin{eqnarray*}
p(\red{\bf negative}| text) & = & p(\red{\bf negative}) * p(fantastic|\red{\bf negative}) * p(great|\red{\bf negative}) * p(lovely|\red{\bf negative})\\
					& = & 4/7 * 0/8 * 2/8 * 0/8\\
					& = & \red{\bf 0}
\end{eqnarray*}
}
\vspace{-.5cm}
\begin{center}
Final decision: sentiment is \myemph{positive}
\end{center}

\vfill

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis - Text Ex. 2}

Consider the following test segment to classify:\\
\begin{enumerate}
\item<2-> Extract features
\item<2-> Build representation 
\end{enumerate}

\only<1>{
\begin{center} 
\begin{tabular}{lp{.7\textwidth}c}
Doc & Words & Class  \\ \toprule
9 & Great plot, great cast, great everything & ? \\
\bottomrule
\end{tabular}
\end{center}}

\only<2->{
\begin{center} 
\begin{tabular}{lp{.7\textwidth}c}
Doc & Words & Class  \\ \toprule
9 & \textbf{Great} \textbf{great} \textbf{great} & ? \\
\bottomrule
\end{tabular}
\end{center}}

\begin{enumerate}
\setcounter{enumi}{2}
\item<3-> Get likelihoods:
\renewcommand{\arraystretch}{0.8}% Tighter
\begin{tabular}{rl|rl}
p(great|\green{\bf positive}) 	&= 1/10	&		p(great|\red{\bf negative}) 		&= 2/8 \\
\end{tabular}
\end{enumerate}

\begin{enumerate}
\setcounter{enumi}{3}
\item<4-> Compute posteriors
\small{
\begin{eqnarray*}
p(\green{\bf positive}| text) =  3/7 * 1/10 * 1/10 * 1/10 &=& \green{\bf 0.00043}\\
p(\red{\bf negative}| text) = 4/7 * 2/8 * 2/8 * 2/8 &=& \red{\bf 0.00893}
\end{eqnarray*}
}
\begin{center}
Final decision: sentiment is \myemph{negative}
\end{center}

\end{enumerate}

\only<5->{
\begin{textblock*}{50mm}[0,0](70mm,-5mm)
\rotatebox{35}{\colorbox{lightgray}{\parbox{6cm}{\Huge{\centering \myemph{Training data} \\ \textbf{should be} \\ \textbf{representative!}}}}}
\end{textblock*}
}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis - Text Ex. 3}

Consider the following test segment to classify:\\
\begin{enumerate}
\item<2-> Extract features
\item<2-> Build representation 
\end{enumerate}

\only<1>{
\begin{center} 
\begin{tabular}{lp{.7\textwidth}c}
Doc & Words & Class  \\ \toprule
10 & Boring movie, annoying plot, unimaginative ending & ? \\
\bottomrule
\end{tabular}
\end{center}}

\only<2->{
\begin{center} 
\begin{tabular}{lp{.7\textwidth}c}
Doc & Words & Class  \\ \toprule
9 & \textbf{Boring} \textbf{annoying} \textbf{unimaginative} & ? \\
\bottomrule
\end{tabular}
\end{center}}

\begin{enumerate}
\setcounter{enumi}{2}
\item<3-> Get likelihoods:
\renewcommand{\arraystretch}{0.8}% Tighter
\begin{tabular}{rl|rl}
p(unimaginative|\green{\bf positive}) &= 0/10	&	p(unimaginative|\red{\bf negative}) &= 1/8 \\
\end{tabular}
\end{enumerate}

\begin{enumerate}
\setcounter{enumi}{3}
\item<4-> Compute posteriors
\small{
\begin{eqnarray*}
p(\green{\bf positive}| text) =  3/7 * 0/10 * 0/10 * 0/10 &=& \green{\bf 0.0}\\
p(\red{\bf negative}| text) = 4/7 * 0/8 * 0/8 * 1/8 &=& \red{\bf 0.0}
\end{eqnarray*}
}
\begin{center}
Final decision: sentiment is \myemph{???}
\end{center}
\end{enumerate}

\only<5->{
\begin{textblock*}{50mm}[0,0](70mm,-5mm)
\rotatebox{35}{\colorbox{lightgray}{\parbox{6.5cm}{\Huge{\centering \myemph{Training data} \\ \textbf{should be large!}}}}}
\end{textblock*}
}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis}

\textbf{Cannot ensure that all possible word appear in the training corpus}\\
\ra\ apply a \myemph{smoothing} technique

\begin{equation*}
p(t_j|s_i)  = \frac{count(t_j,s_i) +1}{count(s_i) + |V|} \text{~~~~~~\ra\ \textbf{Laplace} smoothing, also called \textbf{add-1} smoothing}
\end{equation*}
where $|V|$ is the number of distinct features (also called \textbf{vocabulary}) \ra\ 12 in our example\\



\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis - Text Ex. 3}

Consider the following test segment to classify:\\
\begin{enumerate}
\item Extract features
\item Build representation 
\end{enumerate}

\begin{center} 
\begin{tabular}{lp{.7\textwidth}c}
Doc & Words & Class  \\ \toprule
9 & \textbf{Boring} \textbf{annoying} \textbf{unimaginative} & ? \\
\bottomrule
\end{tabular}
\end{center}

\begin{enumerate}
\setcounter{enumi}{2}
\item<2-> \textbf{Get new likelihoods:}
\begin{center}
\scriptsize{
\renewcommand{\arraystretch}{0.8}% Tighter
\begin{tabular}{rl|rl}
p(boring|\green{\bf positive}) &= (0+1)/(10+12) = 1/22		&	p(boring|\red{\bf negative}) &= (0+1)/(8+12) = 1/20 \\
p(annoying|\green{\bf positive}) &= (0+1)/(10+12) = 1/22		&	p(annoying|\red{\bf negative}) &= (0+1)/(8+12) = 1/20 \\
p(unimaginative|\green{\bf positive}) &= (0+1)/(10+12) = 1/22	&	p(unimaginative|\red{\bf negative}) &= (1+1)/(8+12) = 2/20 \\
\end{tabular}
}
\end{center}
\end{enumerate}

\begin{enumerate}
\setcounter{enumi}{3}
\item<3-> Compute posteriors
\small{
\begin{eqnarray*}
p(\green{\bf positive}| text) =  3/7 * 1/22 * 1/22 * 1/22 &=& \green{\bf 0.000040}\\
p(\red{\bf negative}| text) = 4/7 * 1/20 * 1/20 * 2/20 &=& \red{\bf 0.000143}
\end{eqnarray*}
}
\begin{center}
Final decision: sentiment is \myemph{negative}
\end{center}
\end{enumerate}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis}

\textbf{How can be used a trained classifier?}\\
\begin{itemize}
\item Different level of granularity: 
\item document-level: 
\begin{itemize}
	\item direct classification
	\item by aggregation of sentence classification results
\end{itemize}

\item sentence or phrase-level:
\begin{itemize}
	\item select sentences focusing on some aspect (features)
	\item[\ra] provides a specific sentiment analysis for this feature
\end{itemize}
\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis - Questions}

Is this a good solution?
\begin{itemize}
	\item Simple solution. Works well if data is not sparse.
\end{itemize}

Is it robust?
\begin{itemize}
	\item Problem: what about new words?
\end{itemize}

What is the role of the prior?
\begin{itemize}
	\item reminder: safest decision \textbf{when no other information is given} $\sim$ majority voting
	\item important especially on biased cases
\end{itemize}

Can we extend to a non-binary classification?
\begin{itemize}
	\item Naive Bayes can be easily extended by considering more than 2 classes
	\item ... but beware of the \myemph{curse of dimensionality} \ra\ sparsity
\end{itemize}

\end{frame}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}
\frametitle{Naive Bayes for Sentiment Analysis - Questions}

\textbf{How can we improve this solution?}
\begin{enumerate}
\item Consider other \myemph{features}?
\begin{itemize}
	\item using all words in Naive Bayes works well for some tasks
	\item subsets of words may help \ra\ use the \myemph{development} set to that end
	\item previous examples consider only adjectives, this is limitating
	\begin{itemize}
		\item \myemph{verbs}: hate, dislike 
		\item \myemph{intensifiers}: very, much, a lot
		\item \myemph{negation}: not \la\ \textbf{very important!}
		\item \myemph{nouns}: love, creativity
	\end{itemize}
	\item[\ra] possibly people tend to mostly talk of those \myemph{nouns} in a \green{\bf positive} or \red{\bf negative} way
	\item pre-built polarity lexicons can be helpful
\end{itemize}

\item Consider other \myemph{algorithms}?
\begin{itemize}
	\item Maximum Entropy (MaxEnt), Support Vector Machines (SVM), neural networks
	\item[\ra] no assumption of statistical independence among features
	\item[\ra] more complex but tend to do better
\end{itemize}
\end{enumerate}

\end{frame}