-
Notifications
You must be signed in to change notification settings - Fork 1
/
AI-Lab2.html
332 lines (305 loc) · 16.7 KB
/
AI-Lab2.html
1
2
3
4
5
6
7
8
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
43
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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-154262640-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-154262640-1');
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>The Black Prism</title>
<meta name="description" content="some very important website">
<meta name="author" content="TheBlackPrism">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="./css/styles.css">
<link rel="stylesheet" href="css/fancybox.min.css">
<link rel="stylesheet" href="./css/gallery-style.css">
<link rel="stylesheet" href="css/magnific-popup.css">
<link href='https://fonts.googleapis.com/css?family=Nunito' rel='stylesheet' type='text/css'>
<link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
<meta property="og:title" content="The Black Prism" />
<meta property="og:url" content="https://theblackprism.ch" />
<meta property="og:image" content="https://theblackprism.ch/images/Black-Prism_Logo_V05_Black.png" />
</head>
<body>
<!-- Preloader -->
<div class="preloader d-flex align-items-center justify-content-center">
<div class="lds-ellipsis">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
<!-- ##### Header Area Start ##### -->
<!-- ##### Header Area Start ##### -->
<header class="header-area">
<!-- Navbar Area -->
<div class="newsbox-main-menu">
<div class="classy-nav-container breakpoint-off">
<div class="container-fluid">
<!-- Menu -->
<nav class="classy-navbar justify-content-between" id="newsboxNav">
<!-- Nav brand -->
<a href="index.html" class="nav-brand">The Black Prism</a>
<!-- Navbar Toggler -->
<div class="classy-navbar-toggler">
<span class="navbarToggler"><span></span><span></span><span></span></span>
</div>
<!-- Menu -->
<div class="classy-menu">
<!-- Close Button -->
<div class="classycloseIcon">
<div class="cross-wrap"><span class="top"></span><span class="bottom"></span></div>
</div>
<!-- Nav Start -->
<div class="classynav">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="blogs.html">Blog</a>
<ul class="dropdown">
<li><a href="blogs.html">All Blogs</a></li>
<li><a href="AI-Lab3.html">AI Lab3</a></li>
<li><a href="AI-Lab2.html">AI Lab2</a></li>
<li><a href="AI-Lab1.html">AI Lab1</a></li>
<li><a href="2048-AI.html">Artificial Intelligence</a></li>
<li><a href="dragnet.html">CSP & Datalog</a></li>
</ul>
</li>
<li><a href="photos.html">Photos</a>
<ul class="dropdown">
<li><a href="photos.html">All Photos</a></li>
<li><a href="africa.html">Africa</a></li>
<li><a href="mountains.html">Mountains</a></li>
<li><a href="diverse.html">Diverse</a></li>
</ul>
</li>
<li><a href="https://github.com/TheBlackPrism.html">Github</a></li>
<li><a href="about.html">About</a></li>
</ul>
</div>
<!-- Nav End -->
</div>
</nav>
</div>
</div>
</div>
</header>
<!-- ##### Header Area End ##### -->
<!-- ##### Hero Area Start ##### -->
<section class="section-padding-200">
<div class="container">
<h2>AI-Lab2 — Supervised Learning</h2>
<h5 class="author">By Dano Roost, Jennifer Schürch & Yves Lütjens</h5>
<h5 class="author">04.05.2020</h5>
<div class="blogpost">
<p>
The aim of this lab is to train a binary classifier that labels text with hate speech or not hate speech.
The baseline already achieves an accuracy of 90% but with a very unbalanced set,
meaning 11% are hate speeches and the rest are non-hate speeches.
</p>
<h4>Approach</h4>
<p>
We tried different approaches to achieve the highest possible score and compared them against each other.
Furthermore, we created a balanced dataset that has a 50-50 ratio of hate speeches versus non-hate speeches,
thus giving a less biased view how well the classifiers perform.
In total we implemented four different approaches:
</p>
<ul>
<li>Two different fully connected Neural Network with different layer sizes and TFIDF-Vectors</li>
<li>A Recurrent Neural Network (RNN) with pretrained word embeddings (GloVe)</li>
<li>A Convolutional Neural Network (CNN) with pretrained word embeddings (GloVe)</li>
</ul>
<p>
The two fully connected NNs are implemented in Keras, the RNN and the CNN are implemented in PyTorch.
These two networks use TorchText for pre-processing and word embedding/padding/etc.
</p>
<h4>Evaluation</h4>
<p>
All evaluations are performed on a separate test set. As seen in the following plots,
using a balanced or unbalanced dataset heavily impacts the performance of the classifiers.
The baseline as well as the fully connected 2 NN struggle with the unbalanced dataset in class 1.
The RNN and the CNN on the other hand, are performing better but still perform quite far from perfect,
at least in the unbalanced case.
</p>
<figure>
<div class="single-slide">
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<a href="images/blogs/ai/lab2_f1_score_unbalanced.png" class="d-block photo-item" data-fancybox="gallery">
<img src="images/blogs/ai/lab2_f1_score_unbalanced.png" alt="F1-Score Unbalanced" class="img-fluid">
<div class="photo-text-more">
<span class="icon icon-search"></span>
</div>
</a>
</div>
<div class="col-md-6">
<a href="images/blogs/ai/lab2_f1_score_balanced.png" class="d-block photo-item" data-fancybox="gallery">
<img src="images/blogs/ai/lab2_f1_score_balanced.png" alt="F1-Score Balanced" class="img-fluid">
<div class="photo-text-more">
<span class="icon icon-search"></span>
</div>
</a>
</div>
</div>
</div>
</div>
</figure>
<p>
Analysing the accuracy of the classifiers as seen in the following plot,
the CNN performs the best, followed by the RNN.
Surprisingly the baseline algorithm loses the least accuracy if comparing the balanced dataset with the unbalanced one,
but all proposed solutions outrun the baseline in terms of accuracy.
This leads to the conclusion that a CNN is best suited for the task at hand,
but all of the applied techniques perform well for the given problem statement.
</p>
<figure>
<div class="single-slide">
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<a href="images/blogs/ai/lab2_accuracy.png" class="d-block photo-item" data-fancybox="gallery">
<img src="images/blogs/ai/lab2_accuracy.png" alt="Accuracy" class="img-fluid">
<div class="photo-text-more">
<span class="icon icon-search"></span>
</div>
</a>
</div>
</div>
</div>
</div>
</figure>
<h4>Learning Curve CNN</h4>
<p>
To verify our CNN approach we analysed the learning curves of the accuracy and the loss function from the CNN.
We conclude, that the loss curve settles after 800 batches, which means that the amount of training data is right.
Furthermore we can say that the Model doesn’t over- or underfit as the train and test data curves are very similar.
</p>
<figure>
<div class="single-slide">
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<a href="images/blogs/ai/lab2_learning_curve_cnn_acc.png" class="d-block photo-item" data-fancybox="gallery">
<img src="images/blogs/ai/lab2_learning_curve_cnn_acc.png" alt="Learning Curve CNN Accuracy" class="img-fluid">
<div class="photo-text-more">
<span class="icon icon-search"></span>
</div>
</a>
</div>
<div class="col-md-6">
<a href="images/blogs/ai/lab2_learning_curve_cnn_loss.png" class="d-block photo-item" data-fancybox="gallery">
<img src="images/blogs/ai/lab2_learning_curve_cnn_loss.png" alt="Learning Curve CNN Loss" class="img-fluid">
<div class="photo-text-more">
<span class="icon icon-search"></span>
</div>
</a>
</div>
</div>
</div>
</div>
</figure>
<h4>Console Application</h4>
<p>
Additionally, we made a small console application, which returns the hate speech score and up to three words hate words from a given sentence.
There is a pool of words, which strongly correlate with hate speech for example: faggot, ass, stupid, idiot, shit, gay, hell, screw etc.
When these words are present in a given sentence, the hate speech score gets automatically boosted regardless of the context used in the sentence.
Below is an example with the word "gay" and "stupid":
</p>
<div class="col-md-12">
<table class="article-statistic">
<tr>
<th>Example</th>
<th>Score</th>
<th>Example</th>
<th>Score</th>
</tr>
<tr>
<td>gay</td>
<td>0.34</td>
<td>stupid</td>
<td>0.86</td>
</tr>
<tr>
<td>You are gay</td>
<td>0.55</td>
<td>You are stupid</td>
<td>0.94</td>
</tr>
<tr>
<td>I am gay</td>
<td>0.55</td>
<td>I am stupid</td>
<td>0.94</td>
</tr>
<tr>
<td>The word gay had originally a different meaning</td>
<td>0.54</td>
<td>I have never felt so stupid in my life</td>
<td>0.90</td>
</tr>
</table>
</div>
</div>
<div id="disqus_thread"></div>
<script>
/**
* RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
* LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
/**
var disqus_config = function () {
this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
**/
(function() { // DON'T EDIT BELOW THIS LINE
var d = document,
s = d.createElement('script');
s.src = 'https://blackprism.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
</section>
<!-- ##### Footer Area Start ##### -->
<footer class="footer-area">
<!-- Footer Logo -->
<div class="footer-logo mb-100">
<a href="index.html">The Black Prism</a>
</div>
</footer>
<!-- ##### Footer Area Start ##### -->
<div id="particles-js"></div>
<!-- ##### All Javascript Script ##### -->
<!-- jQuery-2.2.4 js -->
<script src="js/jquery/jquery-2.2.4.min.js"></script>
<!-- Popper js -->
<script src="js/bootstrap/popper.min.js"></script>
<!-- Bootstrap js -->
<script src="js/bootstrap/bootstrap.min.js"></script>
<!-- All Plugins js -->
<script src="js/plugins/plugins.js"></script>
<!-- Active js -->
<script src="js/active.js"></script>
<!-- Gallery js -->
<script src="js/jquery/jquery.fancybox.min.js"></script>
<script src="js/jquery/jquery.magnific-popup.min.js"></script>
<script src="js/gallery-main.js"></script>
<script src="https://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
<script src="js/main.js"></script>
</body>
</html>