-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
1384 lines (979 loc) · 28.6 KB
/
index.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
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
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>AccountingNLP_slides</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<base target="_blank">
<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);
body {
font-family: 'Droid Serif';
}
h1, h2, h3 {
font-family: 'Yanone Kaffeesatz';
font-weight: 400;
margin-bottom: 0;
}
.remark-code, .remark-inline-code {
font-family: 'Ubuntu Mono';
}
}
.remark-slide-content h1 { font-size: 3em; }
.remark-slide-content h2 { font-size: 2em; }
.remark-slide-content h3 { font-size: 1.6em; }
.footnote {
position: absolute;
right: 3em;
bottom: 3em;
}
a, a > code {
color: #193a70;
text-decoration: none;
}
li p { line-height: 1.25em; }
.red { color: #fa0000; }
.large { font-size: 2em; }
code {
background: #e7e8e2;
border-radius: 5px;
}
.remark-code-line-highlighted { background-color: #373832; }
.pull-left {
float: left;
width: 47%;
}
.pull-right {
float: right;
width: 47%;
}
.pull-right ~ p {
clear: both;
}
#slideshow .slide .content code {
font-size: 0.8em;
}
#slideshow .slide .content pre code {
font-size: 0.9em;
padding: 15px;
}
.inverse {
background: #272822;
color: #777872;
text-shadow: 0 0 20px #333;
}
.inverse h1, .inverse h2 {
color: #f3f3f3;
line-height: 0.8em;
}
.mainlayout {
font-size: 20px;
}
.emphasized {
font-weight: bold;
}
/* Slide-specific styling */
#slide-how .slides {
font-size: 0.9em;
position: absolute;
top: 151px;
right: 140px;
}
#slide-how .slides h3 {
margin-top: 0.2em;
}
#slide-how .slides .first, #slide-how .slides .second {
padding: 1px 20px;
height: 90px;
width: 120px;
-moz-box-shadow: 0 0 10px #777;
-webkit-box-shadow: 0 0 10px #777;
box-shadow: 0 0 10px #777;
}
#slide-how .slides .first {
background: #fff;
position: absolute;
top: 20%;
left: 20%;
z-index: 1;
}
#slide-how .slides .second {
position: relative;
background: #fff;
z-index: 0;
}
/* Two-column layout */
.left-column {
color: #777;
width: 20%;
height: 92%;
float: left;
}
.left-column h2:last-of-type, .left-column h3:last-child {
color: #000;
}
.right-column {
width: 75%;
float: right;
padding-top: 1em;
}
.right-column-next {
width: 75%;
float: right;
display: block;
margin-top: -30px;
}
.titleslide {
background-image: url("images/campus_background.jpg");
background-size:cover
}
.titleslide h1, .titleslide h2 {
color: black;
line-height: 0.8em;
}
.tocslide {
font-size: 22px;
line-height: 150%;
}
div.custom_footer {
background-color: #d6d7d8;
position: absolute;
bottom: 0px;
left: 0px;
height: 30px;
width: 100%;
text-align: center;
}
div.custom_footer span {
font-size: 10pt;
color: black;
bottom: -2px;
position: absolute;
left: 400px;
}
span:after { content:""; display: block;}
.arrow-right:after {
display: inline-block;
width: 0;
height: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-left: 15px solid #193a70;
padding-right: 10px;
vertical-align: middle;
}
.orange-button {
background-color: #E46E2E;
border-radius: 2px;
color: white;
display: inline-block;
font-size: 16px;
padding: 13px 26px;
text-align: center;
text-decoration: none;
margin: 0px 4px 0px 4px;
}
.orange-button:hover {
background-color: #F27624;
color: white;
text-decoration: none;
}
.orange-button:active, .orange-button:focus {
background-color: #DC601C;
color: white;
text-decoration: none;
}
.install-button {
margin-top: 20px;
}
blockquote {
background: #f9f9f9;
border-left: 10px solid #ccc;
margin: 0.5em 10px;
padding: 0.5em 10px;
quotes: "\201C""\201D""\2018""\2019";
}
blockquote p {
display: inline;
}
.frame
{
width: 1920px;
height: 1080px;
border: 0;
-ms-transform: scale(0.80);
-moz-transform: scale(0.80);
-o-transform: scale(0.80);
-webkit-transform: scale(0.80);
transform: scale(0.80);
-ms-transform-origin: 0 0;
-moz-transform-origin: 0 0;
-o-transform-origin: 0 0;
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
}
.frame1
{
width: 1200px;
height: 750px;
border: 0;
-ms-transform: scale(0.60);
-moz-transform: scale(0.60);
-o-transform: scale(0.60);
-webkit-transform: scale(0.60);
transform: scale(0.60);
-ms-transform-origin: 0 0;
-moz-transform-origin: 0 0;
-o-transform-origin: 0 0;
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
}
</style>
</head>
<body>
<textarea id="source">
class: center, titleslide
<br><br>
# Text Mining Techniques
# Accounting Research
<br>
## <a href="http://www.tiesdekok.com" target="_blank">Ties de Kok</a>
## Tilburg University
---
layout: true
class: mainlayout
<div class='custom_footer'><span>Text Mining (NLP) for Accounting Research | Ties de Kok (© 2017)</span></div>
---
class: tocslide
.left-column[
## Agenda
]
.right-column[
### What are we going to discuss today?
1. Positioning session
2. Terminology
3. Language
4. Jupyter
5. NLP Python tools
6. Topics:
- Process and Clean text
- Direct feature extraction
- Represent text numerically
- Machine learning
]
---
class: tocslide
.left-column[
## Agenda
## Positioning
]
.right-column[
### Where does this session fit into the bigger scheme of NLP?
<span style="display: block; padding-top: 1px"></span>
- Determining relevance textual data
- Finding sources textual data
- Gathering textual data
<span style="padding-left: 20px" class="arrow-right"></span> .emphasized[Processing textual data]
<span style="padding-left: 20px" class="arrow-right"></span> .emphasized[Analyzing textual data]
]
---
class: tocslide
.left-column[
## Agenda
## Positioning
## Terminology
]
.right-column[
### Many inter-related names and terms:
- Computational Linguistics
- Textual Analysis
<span style="padding-left: 20px" class="arrow-right"></span> .emphasized[Text Mining]
<span style="padding-left: 20px" class="arrow-right"></span> .emphasized[Natural Language Processing]
]
---
class: tocslide
.left-column[
## Agenda
## Positioning
## Terminology
## Language
]
.right-column[
### Which programming language / software to use?
<span style="display: block; padding-top: 1px"></span>
<span style="padding-left: 20px" class="arrow-right"></span> .emphasized[Python]
- R
- PERL
<br><br>
To get started with the Python basics see my [Python Tutorial](https://github.com/TiesdeKok/LearnPythonforResearch)
]
---
class: tocslide
.left-column[
## Agenda
## Positioning
## Terminology
## Language
## Jupyter
]
.right-column[
### Project Jupyter
<div style="text-align: center;">
<img src="images/Jupyter_Screenshot.PNG", width=85%>
<a class="orange-button" href="https://try.jupyter.org/" target="_blank">Try it in your browser</a>
<a class="orange-button install-button" href="http://jupyter.org/install.html">Install the Notebook</a>
</div>
]
---
class: tocslide
.left-column[
## Agenda
## Positioning
## Terminology
## Language
## Jupyter
## NLP Python
]
.right-column[
### External NLP-relevant Python libraries
**Standard NLP libraries**:
1. [`NLTK`](http://www.nltk.org/) and the higher-level wrapper [`TextBlob`](https://textblob.readthedocs.io/en/dev/)
2. [`Spacy`](https://spacy.io/) and the higher-level wrapper [`Textacy`](https://github.com/chartbeat-labs/textacy)
**Standard machine learning library**:
1. [`scikit learn`](http://scikit-learn.org/stable/)
**Topic modelling library**:
1. [`Gensim`](https://github.com/RaRe-Technologies/gensim)
]
---
class: tocslide
.left-column[
## Agenda
## Positioning
## Terminology
## Language
## Jupyter
## NLP Python
## Topics
]
.right-column[
<img style="position: relative; top: -40px" src="images/Topic_diagram_RFA.png", width=85%>
]
---
class: tocslide
.left-column[
## Process <br> & Clean
]
.right-column[
<img style="position: relative; top: -40px" src="images/ProcClean_topic_diagram.png", width=85%>
]
---
class: tocslide
.left-column[
## Process <br> & Clean
]
.right-column[
### Text normalization
- Sentence segmentation
> i.e. split text up into sentences
- Word tokenization
> i.e. split sentence up into tokens (i.e. words)
- Entity normalization
> i.e. "http://www.google.com" → "URL"
- Lemmatization & Stemming
> Convert tokens to a base representation
]
---
class: tocslide
.left-column[
## Process <br> & Clean
]
.right-column[
###Lemmatization & Stemming
Stemming:
> Crude heuristic process that chops off the ends of words
**Lemmatizing:**
> Use vocabulary and morphological analysis of words to return the base or dictionary form
]
--
.right-column-next[
<div style="position: relative; top: 20px" >
<br>Example: <br>
<img style="position: relative; left: +60px; padding-top: 10px" src="images/StemmingvsLemma.PNG", width=60%> <br>
</div>
]
---
class: tocslide
.left-column[
## Process <br> & Clean
]
.right-column[
### Language modelling
Text has a complex underlying structure that you can tap into.
- Part-of-Speech tagging
> Identify the "Word Class" of a token (e.g. noun, verb)
- Remove stop words
> Remove words that don't carry any informational value
- Uni-Gram vs. N-Grams
> Multi-word token: retain some of the sequential nature
]
---
class: tocslide
.left-column[
## Process <br> & Clean
]
.right-column[
###<span style="padding-left: 15px">Uni-Gram vs. N-Grams</span>
> Multi-word token: retain some of the sequential nature
<span style='display:block; text-align: center'>"Tilburg University is located in Noord Brabant"</span>
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;margin:0px auto;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:2px 50px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;
text-align: center}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal; font-weight: bold}
.tg .tg-yw4l{vertical-align:top}
</style>
<table class="tg">
<tr>
<th class="tg-yw4l">Unigram</th>
<th class="tg-yw4l">Bigram</th>
<th class="tg-yw4l">Trigram</th>
</tr>
<tr>
<td class="tg-yw4l">Tilburg</td>
<td class="tg-yw4l">Tilburg-University</td>
<td class="tg-yw4l">Tilburg-University-is</td>
</tr>
<tr>
<td class="tg-yw4l">University</td>
<td class="tg-yw4l">University-is</td>
<td class="tg-yw4l">University-is-located</td>
</tr>
<tr>
<td class="tg-yw4l">is</td>
<td class="tg-yw4l">is-located</td>
<td class="tg-yw4l">is-located-in</td>
</tr>
<tr>
<td class="tg-yw4l">located</td>
<td class="tg-yw4l">located-in</td>
<td class="tg-yw4l">located-in-Noord</td>
</tr>
<tr>
<td class="tg-yw4l">in</td>
<td class="tg-yw4l">in-Noord</td>
<td class="tg-yw4l">in-Noord-Brabant</td>
</tr>
<tr>
<td class="tg-yw4l">Noord</td>
<td class="tg-yw4l">Noord-Brabant</td>
<td class="tg-yw4l"></td>
</tr>
<tr>
<td class="tg-yw4l">Brabant</td>
<td class="tg-yw4l"></td>
<td class="tg-yw4l"></td>
</tr>
</table>
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
]
.right-column[
<img style="position: relative; top: -40px" src="images/FE_topic_diagram.png", width=85%>
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
]
.right-column[
### Feature search
* Entity extraction
> e.g. extract PEOPLE / EVENTS / DATES / MONETARY VALUES
* Pattern search (`RE`)
> i.e. use [`Regular Expressions`](https://scotch.io/tutorials/an-introduction-to-regex-in-python) to look for patterns
* Term (Dictionary) counting
> i.e. count the number of times a term occurs
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
]
.right-column[
### Pattern search (`RE`)
<img style="position: relative; margin-top:20px;" src="images/RE_example.PNG", width=75%>
<br><br>
**TIP**: Use [Pythex.org](https://pythex.org/) to try out your regular expression
Example on Pythex: <a href="https://pythex.org/?regex=IDNUMBER: (\d\d\d-\w\w)&test_string=Ties de Kok (IDNUMBER: 123-AZ). Rest of Text.">click here</a>
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
]
.right-column[
### Term (Dictionary) counting
<img style="position: relative; margin-top:20px;" src="images/Count_example.PNG", width=75%>
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
]
.right-column[
### Text evaluation
* Language
> i.e. detect whether text is English
* Readability
> i.e. use the [`TextStat`](https://github.com/shivam5992/textstat) package to calculate text statistics
* Text similarity
<img style="position: relative; margin-left:40px;" src="images/Similarity_example.PNG", width=65%>
See the awesome [`FuzzyWuzzy`](https://github.com/seatgeek/fuzzywuzzy) package for details.
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
## Represent Numerically
]
.right-column[
<img style="position: relative; top: -40px" src="images/RepNum_topic_diagram.png", width=85%>
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
## Represent Numerically
]
.right-column[
### Bag of Words
Also labelled: *frequency based representation*
Term frequency (TF)
<img style="position: relative; margin-left:40px;" src="images/BoWs_figure61.PNG", width=65%><br>
<span style="font-size: 8pt; position: relative; margin-left:110px">(Figure taken from: https://web.stanford.edu/~jurafsky/slp3/6.pdf)</span>
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
## Represent Numerically
]
.right-column[
### Term frequency (TF) example:
> <span style='font-size: 10pt; line-height: 80%'>[1] "The sky is blue."
> [2] "The sun is bright today."
> [3] "The sun in the sky is bright."
> [4] "We can see the shining sun, the bright sun."</span>
<img style="position: relative; margin-left:40px;" src="images/TF_matrix.PNG", width=21%><br>
<span style='font-size:11pt'>Note: the collection of all text documents is called the *corpus* </span>
<span style="font-size: 8pt; position: relative; margin-left:110px">(Example taken from: http://ethen8181.github.io/machine-learning/clustering_old/tf_idf/tf_idf.html)</span>
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
## Represent Numerically
]
.right-column[
<img style="position: relative; margin-left:20px; margin-top: -20px;" src="images/TFIDF_equation.PNG", width=50%><br><br>
]
--
.right-column-next[
<img style="position: relative; margin-left:20px;" src="https://d1avok0lzls2w.cloudfront.net/uploads/blog/5445d032e97981.23456174.jpg", width=50%><br>
<span style="font-size: 8pt; position: relative; margin-left:30px">(Figure taken from: and https://moz.com/blog/7-advanced-seo-concepts)</span>
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
## Represent Numerically
]
.right-column[
### TF-IDF example:
> <span style='font-size: 10pt; line-height: 80%'>[1] "The sky is blue."
> [2] "The sun is bright today."
> [3] "The sun in the sky is bright."
> [4] "We can see the shining sun, the bright sun."</span>
<img style="position: relative; margin-left:20px; margin-top: 30px;" src="images/DocumentFreq.png", width=12%>
<img style="position: relative; margin-left:40px;" src="images/TFIDF_matrix.PNG", width=70%><br><br>
<span style="font-size: 8pt; position: relative; margin-left:110px">(Example taken from: http://ethen8181.github.io/machine-learning/clustering_old/tf_idf/tf_idf.html)</span>
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
## Represent Numerically
]
.right-column[
### Word Embeddings
Are there alternatives to the frequency based representation?
<span style="padding-left: 20px" class="arrow-right"></span> Yes, meet the new "secret sauce": **word embeddings**!
]
--
.right-column-next[
<br>
Word embeddings are based on a "prediction based representation".
Basic idea:
> A word is characterized by the company it keeps: <br><br>
> 1. A **Ferrari** is a fast car
> 2. A **Lamborgini** is a fast car
<span style="font-size:10pt">Notes: the most well-known adaptation is `Word2Vec`. Word embeddings are sometimes called *Continous Bag of Words*</span>
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
## Represent Numerically
## Machine Learning
]
.right-column[
<img style="position: relative; top: -40px" src="images/StatModel_topic_diagram.png", width=85%>
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
## Represent Numerically
## Machine Learning
]
.right-column[
### What is Machine Learning?
<span></span>
> A machine learning algorithm is not explicitly programmed. <br>
Instead, the algorithm is trained based on the input + output data.
Does this sound familiar?
]
--
.right-column-next[
<span style="padding-left: 20px" class="arrow-right"></span> A linear regression is also machine learning!
]
--
.right-column-next[
### Example: sentiment analysis
Traditional method:
<span style="padding-left: 20px" class="arrow-right"></span> manually create pos/neg word lists
Machine learning method:
<span style="padding-left: 20px" class="arrow-right"></span> manually classify sentence pos/neg score
<span style="padding-left: 20px" class="arrow-right"></span> pos/neg word lists determined by algorithm
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
## Represent Numerically
## Machine Learning
]
.right-column[
### Supervised Machine Learning
<span></span>
> Supervised ML algorithms are trained on classified training data.
]
--
.right-column-next[
<span style="display:block; height:1px"></span>
### Where to get training data?
1. Use a naturally classified training set
- News categories
- Movie reviews
- Text books for different levels of English
2. Create your own training set
- Manually classify text
- Crowdsource a training set
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
## Represent Numerically
## Machine Learning
]
.right-column[
### Crowdsource training set
<span></span>
It is possible to crowd source a training set using services like Amazon Mechanical Turk.
]
---
class: tocslide
.left-column[
## Process <br> & Clean
## Feature Extraction
## Represent Numerically
## Machine Learning
]
.right-column[
### Supervised Machine Learning: models
<span></span>