forked from lintool/bigdata-2016w
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignments.html
2905 lines (2257 loc) · 115 KB
/
assignments.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 lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="Course homepage for CS 489 Big Data Infrastructure (Winter 2016) at the University of Waterloo">
<meta name="author" content="Jimmy Lin">
<title>Big Data Infrastructure</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="index.html">Overview</a></li>
<li><a href="organization.html">Organization</a></li>
<li><a href="syllabus.html">Syllabus</a></li>
<li class="active"><a href="assignments.html">Assignments</a></li>
<li><a href="software.html">Software</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<div class="page-header">
<div style="float: right"/><img src="images/waterloo_logo.png"/></div>
<h1>Assignments <small>CS 489/698 Big Data Infrastructure (Winter 2016)</small></h1>
</div>
<div class="subnav">
<ul class="nav nav-pills">
<li><a href="#assignment0">0</a></li>
<li><a href="#assignment1">1</a></li>
<li><a href="#assignment2">2</a></li>
<li><a href="#assignment3">3</a></li>
<li><a href="#assignment4">4</a></li>
<li><a href="#assignment5">5</a></li>
<li><a href="#assignment6">6</a></li>
<li><a href="#assignment7">7</a></li>
<li><a href="#project">Final Project</a></li>
</ul>
</div>
<section id="assignment0" style="padding-top:35px">
<div>
<h3>Assignment 0: Warmup <small>due 8:30am January 12</small></h3>
<p>The purpose of this assignment is to serve as a simple warmup
exercise and to serve as a practice "dry run" for the submission
procedures of subsequent assignments. You'll have to write a bit of
code but this assignment is mostly about the "mechanics" of setting up
your Hadoop development environment. In addition to running Hadoop
locally in either the Linux student CS environment or on your own
machine, you'll also try running jobs on the Altiscale cluster.</p>
<p>The general setup is as follows:
you will complete your assignments and check everything into a private
GitHub repo. Shortly after the assignment deadline, we'll pull your
repo for grading. Although we will be examining your solutions to
assignment 0, it will not be graded <i>per se</i>.</p>
<p>I'm assuming you already have
a <a href="http://github.com/">GitHub</a> account. If not, create one
as soon as possible. Once you've signed up for an account, go and
<a href="https://education.github.com/discount_requests/new">request
an educational account</a>. This will allow you to create private
repos for free. Please do this as soon as possible since there may be
delays in the request verification process.</p>
<h4 style="padding-top: 10px">Setting up Hadoop and Spark</h4>
<p>Hadoop and Spark are already installed in
the <code>linux.student.cs.uwaterloo.ca</code>
environment (you just need to add some paths).
Alternatively, you may wish to install everything locally
on your own machine. For both, see the <a href="software.html">software page</a> for
more details.</p>
<p>Bespin is a library that contains reference implementations of "big
data" algorithms in MapReduce and Spark. We'll be using it throughout
this course. Go and run
the <a href="https://github.com/lintool/bespin">Word Count in
MapReduce and Spark</a> example as shown in the Bespin README (clone
and build the repo, download the data files, run word count in both
MapReduce in Spark, and verify output). Assuming you are
using <code>linux.student.cs.uwaterloo.ca</code> (or if you have
properly set up your local environment), this task should be as simple
as copying and pasting commands from the Bespin README.</p>
<p>When running Hadoop, you might get the following warning: "Unable
to load native-hadoop library for your platform... using builtin-java
classes where applicable". It's okay: no need to worry.</p>
<h4 style="padding-top: 10px">Time to write some code!</h4>
<p>Create a <b>private</b> repo
called <code>bigdata2016w</code>. I'm assuming that you're
already familiar with Git and GitHub, but just in case, here
is <a href="https://help.github.com/articles/create-a-repo">how you
create a repo on GitHub</a>. For "Who has access to this repository?",
make sure you click "Only the people I specify". If you've
successfully gotten an educational account (per above), you should be
able to create private repos for free. If you're not already familiar
with Git, there are plenty of good tutorials online: do a simple web
search and find one you like.</p>
<p>What you're going to do now is to copy the MapReduce word count
example into you own private repo. Start with
<a href="assignments/pom.xml">this <code>pom.xml</code></a>: copy it
into your <code>bigdata2016w</code> repo. The replace this line in
that file:</p>
<pre>
<groupId>ca.uwaterloo.cs.bigdata2016w.lintool</groupId>
</pre>
<p>Instead of <code>lintool</code>, substitute your GitHub
username. You'll be working in your own namespace, so in everything
that follows, substitute your own GitHub username in place
of <code>lintool</code>.</p>
<p>Next, copy:</p>
<ul>
<li><code>bespin/src/main/java/io/bespin/java/mapreduce/wordcount/WordCount.java</code> over to
<li><code>bigdata2016w/src/main/java/ca/uwaterloo/cs/bigdata2016w/lintool/assignment0/WordCount.java</code>.
</ul>
<p>Open up this new version of <code>WordCount.java</code> using a
text editor (or your IDE of choice) and change the Java package
to <code>ca.uwaterloo.cs.bigdata2016w.lintool.assignment0</code>.</p>
<p>Now, in the <code>bigdata2016w/</code> base directory, you should
be able to run Maven to build your package:</p>
<pre>
$ mvn clean package
</pre>
<p>Once the build succeeds, you should be able to run the word count
demo program in your own repository:</p>
<pre>
$ hadoop jar target/bigdata2016w-0.1.0-SNAPSHOT.jar \
ca.uwaterloo.cs.bigdata2016w.lintool.assignment0.WordCount \
-input data/Shakespeare.txt -output wc
</pre>
<p>You should be running this in the Linux student CS environment or
on your own machine. Note that you'll need to copy over the
Shakespeare collection in <code>data/</code>. The output should be
exactly the same as the same program in Bespin, but the difference
here is that the code is now in a repository under your control, in
your own private namespace.<p>
<p>Let's make a simple modification to word count: instead of counting
words, I want to count the occurrences of two-character prefixes of
words, i.e., the first two characters. That is, I want to know how
many words begin with "aa", "ab", "ac", etc., all the way to "zz"
(including special characters, etc.). Create a program
called <code>PrefixCount</code> in the
package <code>ca.uwaterloo.cs.bigdata2016w.lintool.assignment0</code> that does this.</p>
<p>To be clear, the <code>WordCount</code> defines a "word" as
follows:</p>
<pre>
String w = itr.nextToken().toLowerCase().replaceAll("(^[^a-z]+|[^a-z]+$)", "");
</pre>
<p>Simply take whatever <code>w.substring(0, 2)</code> gives you as a
prefix. This means, of course, that you should ignore single
characters.</p>
<p>We should be able to run your program as follows:</p>
<pre>
$ hadoop jar target/bigdata2016w-0.1.0-SNAPSHOT.jar \
ca.uwaterloo.cs.bigdata2016w.lintool.assignment0.PrefixCount \
-input data/Shakespeare.txt -output cs489-2016w-lintool-a0-shakespeare
</pre>
<p>You shouldn't need to write more than a couple lines of code
(beyond changing class names and other boilerplate). We'll go over the
Hadoop API in more detail in class, but the changes should be
straightforward.</p>
<p>Answer the following questions:</p>
<p><b>Question 1.</b> In the Shakespeare collection, what are the
three most frequent two character prefixes and how many times does
each occur? (Remember when I mentioned "command line"-fu skills in
class? This is where such skills will come in handy...)</p>
<p><b>Question 2.</b> In the Shakespeare collection, how frequent does
the prefix "li" occur?</p>
<p>You can run the above instructions using
<a href="assignments/check_assignment0_public_linux.py"><code>check_assignment0_public_linux.py</code></a> as follows:</p>
<pre>
$ wget http://lintool.github.io/bigdata-2016w/assignments/check_assignment0_public_linux.py
$ ./check_assignment0_public_linux.py lintool
</pre>
<p>In fact, we'll be using exactly this script to check your
assignment in the Linux Student CS environment. That is, make sure
that your code runs there even if you do development on your own
machine.</p>
<h4 style="padding-top: 10px">Using the Altiscale Cluster</h4>
<p>The <a href="software.html">software page</a> has details on
getting started with the Altiscale cluster. Register your account and
follow instructions to set up ssh into the "workspace". Make sure
you've properly set up the proxy to view the cluster Resource Manager
(RM) webapp
at <a href="http://rm-ia.s3s.altiscale.com:8088/cluster/"><code>http://rm-ia.s3s.altiscale.com:8088/cluster/</code></a>.
Getting access to the RM webapp is important—you'll need it to
track your job status and for debugging purposes.</p>
<p>Once you've ssh'ed into the workspace, check out Bespin and run
word count:</p>
<pre>
$ hadoop jar target/bespin-0.1.0-SNAPSHOT.jar io.bespin.java.mapreduce.wordcount.WordCount \
-input /shared/cs489/data/enwiki-20151201-pages-articles-0.1sample.txt -output wc-jmr-combiner
</pre>
<p>Note that we're running word count over a larger collection here: a
10% sample of English Wikipedia totaling 1.3 GB (here's a chance to
exercise your newly-acquired HDFS skills to confirm for yourself).</p>
<p><b>Question 3.</b> Were you able to successfully run word count on
the Altiscale cluster and get access to the Resource Manager webapp?
(Yes or No)</p>
<p>Now switch into your own <code>bigdata2016w/</code> repo and run
your prefix count program on the sample Wikipedia data:</p>
<pre>
$ hadoop jar target/bigdata2016w-0.1.0-SNAPSHOT.jar \
ca.uwaterloo.cs.bigdata2016w.lintool.assignment0.PrefixCount \
-input /shared/cs489/data/enwiki-20151201-pages-articles-0.1sample.txt -output cs489-2016w-lintool-a0-wiki
</pre>
<p><b>Question 4.</b> In the sample Wikipedia collection, what are the
three most frequent two character prefixes and how many times does
each occur?</p>
<p><b>Question 5.</b> In the sample Wikipedia collection, How frequent
does the prefix "li" occur?</p>
<p>Note that the Altiscale cluster is a shared resource, and how fast
your jobs complete will depend on how busy it is. You're advised to
begin the assignment early as to avoid long job queues. "I wasn't able
to complete the assignment because there were too many jobs running on
the cluster" will not be accepted as an excuse if your assignment is
late.</p>
<p>You can run the above instructions using
<a href="assignments/check_assignment0_public_altiscale.py"><code>check_assignment0_public_altiscale.py</code></a> as follows:</p>
<pre>
$ wget http://lintool.github.io/bigdata-2016w/assignments/check_assignment0_public_altiscale.py
$ ./check_assignment0_public_altiscale.py lintool
</pre>
<p>In fact, we'll be using exactly this script to check your
assignment on the Altiscale cluster.</p>
<h4 style="padding-top: 10px">Turning in the Assignment</h4>
<p>At this point, you should have a GitHub
repo <code>bigdata2016w/</code> and inside the repo, you should have
the word count program copied over from Bespin and the new prefix count
implementation, along with your <code>pom.xml</code>. Commit these
files. Next, create a file called <code>assignment0.md</code>
inside <code>bigdata2016w/</code>. In that file, put your answers to
the above questions (1—5). Use the Markdown annotation format: here's
a <a href="http://daringfireball.net/projects/markdown/basics">simple
guide</a>.</p>
<p><b>Note:</b> there is no need to commit <code>data/</code>
or <code>target/</code> (or any results that you may have generated),
so your repo should be very compact — it should only have four
files: two Java source files, <code>pom.xml</code>,
and <code>assignment0.md</code>. You can add a <code>.gitignore</code>
file if you wish.</p>
<p>For this and all subsequent assignments, make sure everything is on
the master branch. Push your repo to GitHub. You can verify that it's
there by logging into your GitHub account in a web browser: your
assignment should be viewable in the web interface.</p>
<p>For this (and the following assignments) there are two parts, one
that can be completed locally, and another that requires the Altiscale
cluster. For the first, make sure that your code runs in the Linux
Student CS environment (even if you do development on your own
machine), which is where we will be doing the grading. "But it runs on
my laptop!" will not be accepted as an excuse if we can't get your
code to run.</p>
<p>Almost there! Add the
user <a href="https://github.com/teachtool">teachtool</a> a
collaborator to your repo so that we can access it (under settings in
the main web interface on your repo). Note: do <b>not</b> add my
primary GitHub
account <a href="https://github.com/lintool">lintool</a> as a
collaborator.</p>
<p>Finally, you need to tell us your GitHub account so we can link it
to you. Submit your user
name <a href="http://goo.gl/forms/UBIaZNNzHF">here</a>.</p>
<p>And that's it!</p>
<p>To give you an idea of how we'll be grading this and future
assignments—we will clone your repo and use the above check
scripts:</p>
<ul>
<li><a href="assignments/check_assignment0_public_linux.py"><code>check_assignment0_public_linux.py</code></a>
in the Linux Student CS environment.</li>
<li><a href="assignments/check_assignment0_public_altiscale.py"><code>check_assignment0_public_altiscale.py</code></a> on the Altiscale cluster.</li>
</ul>
<p>We'll make sure the data files are in the right place, and once the
code completes, we will verify the output. It is highly recommend that
you run these check scripts: if it doesn't work for you, it won't work
for us either.</p>
<p>As mentioned above, one main purpose of this assignment is to
provide a practice "dry run" of how assignments will be submitted in
the future. It is your responsibility to follow these instructions and
learn the process: we will work with you to get the process sorted out
for this assignment, but in subsequent assignments, you may be docked
points for failing to conform to our expectations.</p>
<p style="padding-top: 20px"><a href="#">Back to top</a></p>
</div>
</section>
<section id="assignment1" style="padding-top:35px">
<div>
<h3>Assignment 1: Counting in MapReduce <small>due 8:30am January 19</small></h3>
<p>By now, you should already be familiar with the Hadoop execution
environment (e.g., submitting jobs) and using Maven to organize your
assignments. You will be working in the same repo as before, except
that everything should go into the package namespace
<code>ca.uwaterloo.cs.bigdata2016w.lintool.assignment1</code>
(obviously, replace <code>lintool</code> with your actual GitHub
username.</p>
<p>Note that the point of assignment 0 was to familiarize your with
GitHub and the Hadoop development environment. We will work through
issues with you, but starting this assignment, excuses along the lines
of "I couldn't get my repo set up properly", "I couldn't figure out
how to push my assignment to GitHub", etc. will not be accepted. It is
your responsibility to sort through any mechanics issue you have.</p>
<p>Before staring this assignment, it is <i>highly recommended</i>
that you look at the implementations of bigram relative frequency and
co-occurrence matrix computation
in <a href="http://bespin.io">Bespin</a>.</p>
<p>In this assignment you'll be
computing <a href="http://en.wikipedia.org/wiki/Pointwise_mutual_information">pointwise
mutual information</a>, which is a function of two events <i>x</i>
and <i>y</i>:</p>
<p><img width="200" src="assignments/PMI.png"/></p>
<p>The larger the magnitude of PMI for <i>x</i> and <i>y</i> is,
the more information you know about the probability of seeing <i>y</i>
having just seen <i>x</i> (and vice-versa, since PMI is
symmetrical). If seeing <i>x</i> gives you no information about seeing
<i>y</i>, then <i>x</i> and <i>y</i> are independent and the PMI is
zero.</p>
<p>Write a program (two separate implementations, actually—more details below)
that computes the PMI of words in the
<code>data/Shakespeare.txt</code> collection that's used in the Bespin
demos and the previous assignment. Your implementation should be in Java. To be more specific, the event
we're after is <i>x</i> occurring on a line in the file (the denominator above) or <i>x</i>
and <i>y</i> co-occurring on a line (the numerator above). That is, if a line contains "A B
C", then the co-occurring pairs are:</p>
<ul>
<li>(A, B)</li>
<li>(A, C)</li>
<li>(B, A)</li>
<li>(B, C)</li>
<li>(C, A)</li>
<li>(C, B)</li>
</ul>
<p>If the line contains "A A B C", the co-occurring pairs are still
the same as above; same if the line contains "A B C A B C"; or any
combinations of A, B, and C in any order.</p>
<p>A few additional important details:</p>
<ul>
<li>To reduce the number of spurious pairs, we are only interested in
pairs of words that co-occur in ten or more lines.</li>
<li>To reduce the computational complexity of the problem, we are only
going to consider up to the first 100 words in each line.</li>
<li>Just so everyone's answer is consistent, please use
log base 10.</li>
</ul>
<p>Use the same definition of "word" as in the word count demo.
Just to make sure we're all on the same page, use this as the
starting point of your mapper:</p>
<pre>
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
String line = ((Text) value).toString();
StringTokenizer itr = new StringTokenizer(line);
int cnt = 0;
Set<String> set = Sets.newHashSet();
while (itr.hasMoreTokens()) {
cnt++;
String w = itr.nextToken().toLowerCase().replaceAll("(^[^a-z]+|[^a-z]+$)", "");
if (w.length() == 0) continue;
set.add(w);
if (cnt >= 100) break;
}
String[] words = new String[set.size()];
words = set.toArray(words);
// Your code goes here...
}
</pre>
<p>You will build two versions of the program (put both in
package <code>ca.uwaterloo.cs.bigdata2016w.lintool.assignment1</code>):</p>
<ol>
<li>A "pairs" implementation. The implementation must use
combiners. Name this implementation <code>PairsPMI</code>.</li>
<li>A "stripes" implementation. The implementation must use
combiners. Name this implementation <code>StripesPMI</code>.</li>
</ol>
<p>Since PMI is symmetrical, PMI(x, y) = PMI(y, x). However, it's
actually easier in your implementation to compute both values, so
don't worry about duplicates. Also, use <code>TextOutputFormat</code>
so the results of your program are human readable.</p>
<p>Make sure that the pairs implementation and the stripes
implementation give the same answers!</p>
<p>Answer the following questions:</p>
<p><b>Question 1.</b> (6 points) <i>Briefly</i> describe in prose your solution,
both the pairs and stripes implementation. For example: how many
MapReduce jobs? What are the input records? What are the intermediate
key-value pairs? What are the final output records? A paragraph for
each implementation is about the expected length.</p>
<p><b>Question 2.</b> (2 points) What is the running time of the complete pairs
implementation? What is the running time of the complete stripes
implementation? (Tell me where you ran these experiments,
e.g., <code>linux.student.cs.uwaterloo.ca</code> or your own
laptop.)</p>
<p><b>Question 3.</b> (2 points) Now disable all combiners. What is the running
time of the complete pairs implementation now? What is the running
time of the complete stripes implementation? (Tell me where you ran
these experiments, e.g., <code>linux.student.cs.uwaterloo.ca</code> or
your own laptop.)</p>
<p><b>Question 4.</b> (3 points) How many distinct PMI pairs did you extract?</p>
<p><b>Question 5.</b> (3 points) What's the pair (x, y) (or pairs if there are
ties) with the highest PMI? Write a sentence or two to explain why
such a high PMI.</p>
<p><b>Question 6.</b> (6 points) What are the three words that have the highest
PMI with "tears" and "death"? And what are the PMI values?</p>
<p>Note that you can compute the answer to questions 4—6 however
you wish: a helper Java program, a Python script, command-line
one-liner, etc.</p>
<h4 style="padding-top: 10px">Running on the Altiscale cluster</h4>
<p>Now, on the Altiscale cluster, run your pairs and stripes
implementation on the sample Wikipedia collection stored on HDFS
at <code>/shared/cs489/data/enwiki-20151201-pages-articles-0.1sample.txt</code>. Note
that in the Wikipedia collection, each article is on a line, so
we're computing co-occurring words in (the beginning of) the article. Also, the
"first 100 words" restriction will definitely apply here (whereas in
the Shakespeare collection, all the lines contained fewer than 100
words, so it was a no-op).</p>
<p>Make sure your code runs on this larger dataset. Assuming that
there aren't many competing jobs on the cluster, your programs should
not take more than 20 minutes to run. If your job is taking much
longer than that, then please kill it so it doesn't waste resources
and slow other people's jobs down. Obviously, if the cluster is really
busy or if there's a long list of queued jobs, your job will take
longer, so use your judgement here. The only point is: be nice. It's a
shared resource, and let's not let runaway jobs slow everyone
down.</p>
<p>One final detail, set your MapReduce job parameters as follows:</p>
<pre>
job.getConfiguration().setInt("mapred.max.split.size", 1024 * 1024 * 64);
job.getConfiguration().set("mapreduce.map.memory.mb", "3072");
job.getConfiguration().set("mapreduce.map.java.opts", "-Xmx3072m");
job.getConfiguration().set("mapreduce.reduce.memory.mb", "3072");
job.getConfiguration().set("mapreduce.reduce.java.opts", "-Xmx3072m");
</pre>
<p>What the last four options do is fairly obvious. The first sets
the <i>maximum</i> split size to be 64 MB. What effect does that have?
(Hint, consider the physical execution of MapReduce programs we
discussed in class)</p>
<p><b>Question 7.</b> (6 points) In the Wikipedia sample, what are the three
words that have the highest PMI with "waterloo" and "toronto"? And
what are the PMI values?</p>
<p>It's worth noting again: the Altiscale cluster is a shared
resource, and how fast your jobs complete will depend on how busy it
is. You're advised to begin the assignment early as to avoid long job
queues. "I wasn't able to complete the assignment because there were
too many jobs running on the cluster" will not be accepted as an
excuse if your assignment is late.</p>
<h4 style="padding-top: 10px">Turning in the Assignment</h4>
<p>Please follow these instructions carefully!</p>
<p>Make sure your repo has the following items:</p>
<ul>
<li>Similar to assignment 0, the answers to the questions go
in <code>bigdata2016w/assignment1.md</code>.</li>
<li>The pairs and stripes implementation should be in
package <code>ca.uwaterloo.cs.bigdata2016w.lintool.assignment1</code>.</li>
</ul>
<p>When grading, we will pull your repo and build your code:<p>
<pre>
$ mvn clean package
</pre>
<p>Your code should build successfully. We are then going to check
your code (both the pairs and stripes implementations).</p>
<p>We're going to run your code on the Linux student CS environment as
follows (we will make sure the collection is there):</p>
<pre>
$ hadoop jar target/bigdata2016w-0.1.0-SNAPSHOT.jar \
ca.uwaterloo.cs.bigdata2016w.lintool.assignment1.PairsPMI \
-input data/Shakespeare.txt -output cs489-2016w-lintool-a1-shakespeare-pairs -reducers 5
$ hadoop jar target/bigdata2016w-0.1.0-SNAPSHOT.jar \
ca.uwaterloo.cs.bigdata2016w.lintool.assignment1.StripesPMI \
-input data/Shakespeare.txt -output cs489-2016w-lintool-a1-shakespeare-stripes -reducers 5
</pre>
<p>Make sure that your code runs in the Linux Student CS environment
(even if you do development on your own machine), which is where we
will be doing the grading. "But it runs on my laptop!" will not be
accepted as an excuse if we can't get your code to run.</p>
<p>You can run the above instructions using
<a href="assignments/check_assignment1_public_linux.py"><code>check_assignment1_public_linux.py</code></a>.</p>
<p>We're going to run your code on the Altiscale cluster as
follows:</p>
<pre>
$ hadoop jar target/bigdata2016w-0.1.0-SNAPSHOT.jar \
ca.uwaterloo.cs.bigdata2016w.lintool.assignment1.PairsPMI \
-input /shared/cs489/data/enwiki-20151201-pages-articles-0.1sample.txt -output cs489-2016w-lintool-a1-wiki-pairs -reducers 5
$ hadoop jar target/bigdata2016w-0.1.0-SNAPSHOT.jar \
ca.uwaterloo.cs.bigdata2016w.lintool.assignment1.StripesPMI \
-input /shared/cs489/data/enwiki-20151201-pages-articles-0.1sample.txt -output cs489-2016w-lintool-a1-wiki-stripes -reducers 5
</pre>
<p>You can run the above instructions using
<a href="assignments/check_assignment1_public_altiscale.py"><code>check_assignment1_public_altiscale.py</code></a>.</p>
<p><b>Important:</b> Make sure that your code accepts the command-line
parameters above! That is, make sure the check scripts work!<p>
<p>When you've done everything, commit to your repo and remember to
push back to origin. You should be able to see your edits in the web
interface. Before you consider the assignment "complete", verify
everything above works by performing a clean clone of your repo and
going through the steps above.</p>
<p>That's it! There's no need to send us anything—we already know
your username from the first assignment. Note that everything should
be committed and pushed to origin before the deadline.</p>
<h4 style="padding-top: 10px">Hints</h4>
<ul>
<li>Did you take a look at the implementations of bigram relative
frequency and co-occurrence matrix computation
in <a href="http://bespin.io">Bespin</a>?</li>
<li>Your solution will likely require more than one MapReduce job.</li>
<li>You may have to load in "side data"?</li>
<li>My <a href="https://github.com/lintool/tools/tree/master/lintools-datatypes/">lintools-datatypes
package</a> has <code>Writable</code> datatypes that you might find
useful. (Feel free to use, but assignment can be completed
without it.)</li>
</ul>
<h4 style="padding-top: 10px">Grading</h4>
<p>This assignment is worth a total of 50 points, broken down as
follows:</p>
<ul>
<li>The questions above are worth a total of 28 points.</li>
<li>Getting your code to compile and successfully run is worth
another 16 points (4 points each for the pairs and stripes
implementation in the Linux student CS environment and on
Altiscale). We will make a minimal effort to fix <i>trivial</i>
issues with your code (e.g., a typo)—and deduct
points—but <b>will not</b> spend time debugging your code. It
is your responsibility to make sure your code runs: we have taken
care to specify exactly how we will run your code—if anything
is unclear, it is your responsibility to seek clarification. In
order to get a perfect score of 16 for this portion of the grade, we
should be able to run the two public check
scripts: <a href="assignments/check_assignment1_public_linux.py"><code>check_assignment1_public_linux.py</code></a>
(on Linux Student CS)
an <a href="assignments/check_assignment1_public_altiscale.py"><code>check_assignment1_public_altiscale.py</code></a>
(on Altiscale cluster) successfully without any errors.</li>
<li>Another 6 points is allotted to us verifying the output of your
program in ways that we will not tell you. We're giving you the
"public" versions of the check scripts; we'll run a "private"
version to examine your output further (i.e., think blind test
cases).</li>
</ul>
<p style="padding-top: 20px"><a href="#">Back to top</a></p>
</div>
</section>
<section id="assignment2" style="padding-top:35px">
<div>
<h3>Assignment 2: Counting in Spark <small>due 8:30am January 26</small></h3>
<p>In this assignment you will "port" the MapReduce implementations of
the bigram frequency count program
from <a href="http://bespin.io">Bespin</a> over to Spark (in
Scala). Your starting points
are <code>ComputeBigramRelativeFrequencyPairs</code>
and <code>ComputeBigramRelativeFrequencyStripes</code> in
package <code>io.bespin.java.mapreduce.bigram</code> (in Java).
You are welcome to build on the <code>BigramCount</code> (Scala)
implementation <a href="https://github.com/lintool/bespin/blob/master/src/main/scala/io/bespin/scala/spark/bigram/BigramCount.scala">here</a>
for tokenization and "boilerplate" code like command-line argument
parsing. To be consistent in tokenization, you should copy over
the <code>Tokenizer</code> trait
<a href="https://github.com/lintool/bespin/blob/master/src/main/scala/io/bespin/scala/util/Tokenizer.scala">here</a>. You'll
also need to grab missing Maven dependencies
from <a href="https://github.com/lintool/bespin/blob/master/pom.xml">here</a>.</p>
<p>Put your code in the
package <code>ca.uwaterloo.cs.bigdata2016w.lintool.assignment2</code>. Since
you'll be writing Scala code, your source files should go
into <code>src/main/scala/ca/uwaterloo/cs/bigdata2016w/lintool/assignment2/</code>. Note
that the repository is designed so that Scala/Spark code will also
compile with the same Maven build command:</p>
<pre>
$ mvn clean package
</pre>
<p>Following the Java implementations, you will write both a "pairs"
and a "stripes" implementation in Spark. Not that although Spark has a
different API than MapReduce, the algorithmic concepts are still very
much applicable. Your pairs and stripes implementation should follow
the same logic as in the MapReduce implementations. In particular,
your program should only take one pass through the input data.</p>
<p>Make sure your implementation runs in the Linux student CS
environment on the Shakespeare collection and also on sample
Wikipedia
file <code>/shared/cs489/data/enwiki-20151201-pages-articles-0.1sample.txt</code>
on HDFS in the Altiscale cluster. Note that submitting Spark jobs on
the Altiscale cluster requires a rather arcane command-line
invocation see the <a href="software.html">software page</a> for
more details.</p>
<p>You can verify the correctness of your algoritm by comparing the
output of the MapReduce implementation with your Spark
implementation. The output should be the same.</p>
<p>Clarification on terminology: informally, we often refer to
"mappers" and "reducers" in the context of Spark. That's a shorthand
way of saying map-like transformations
(<code>map</code>, <code>flatMap</code>, <code>filter</code>, <code>mapPartitions</code>,
etc.) and reduce-like transformations
(e.g., <code>reduceByKey</code>, <code>groupByKey</code>, <code>aggregateByKey</code>,
etc.). Hopefully it's clear from lecture that while Spark represents a
generalization of MapReduce, the notions of per-record processing
(i.e., map-like transformation) and grouping/shuffling (i.e.,
reduce-like transformations) are shared across both frameworks.</p>
<h4 style="padding-top: 10px">Turning in the Assignment</h4>
<p>Please follow these instructions carefully!</p>
<p>The pairs and stripes implementation should be in
package <code>ca.uwaterloo.cs.bigdata2016w.lintool.assignment2</code>;
your Scala code should be
in <code>src/main/scala/ca/uwaterloo/cs/bigdata2016w/lintool/assignment2/</code>.
There are no questions to answer in this assignment unless there is
something you would like to communicate with us, and if so, put it
in <code>assignment2.md</code>.</p>
<p>When grading, we will pull your repo and build your code:<p>
<pre>
$ mvn clean package
</pre>
<p>Your code should build successfully. We are then going to check
your code (both the pairs and stripes implementations).</p>
<p>We're going to run your code on the Linux student CS environment as
follows (we will make sure the collection is there):</p>
<pre>
$ spark-submit --class ca.uwaterloo.cs.bigdata2016w.lintool.assignment2.ComputeBigramRelativeFrequencyPairs \
target/bigdata2016w-0.1.0-SNAPSHOT.jar --input data/Shakespeare.txt --output cs489-2016w-lintool-a2-shakespeare-pairs --reducers 5
$ spark-submit --class ca.uwaterloo.cs.bigdata2016w.lintool.assignment2.ComputeBigramRelativeFrequencyStripes \
target/bigdata2016w-0.1.0-SNAPSHOT.jar --input data/Shakespeare.txt --output cs489-2016w-lintool-a2-shakespeare-stripes --reducers 5
</pre>
<p>Make sure that your code runs in the Linux Student CS environment
(even if you do development on your own machine), which is where we
will be doing the grading. "But it runs on my laptop!" will not be
accepted as an excuse if we can't get your code to run.</p>
<p>We're going to run your code on the Altiscale cluster as follows
(note we add <code>--num-executors 10</code> to specify the number of
executors; also note that we use the <code>my-spark-submit</code>
launch script—see the <a href="software.html">software</a>
page for details):</p>
<pre>
$ my-spark-submit --class ca.uwaterloo.cs.bigdata2016w.lintool.assignment2.ComputeBigramRelativeFrequencyPairs --num-executors 10 \
target/bigdata2016w-0.1.0-SNAPSHOT.jar --input /shared/cs489/data/enwiki-20151201-pages-articles-0.1sample.txt \
--output cs489-2016w-lintool-a2-wiki-pairs --reducers 10
$ my-spark-submit --class ca.uwaterloo.cs.bigdata2016w.lintool.assignment2.ComputeBigramRelativeFrequencyStripes --num-executors 10 \
target/bigdata2016w-0.1.0-SNAPSHOT.jar --input /shared/cs489/data/enwiki-20151201-pages-articles-0.1sample.txt \
--output cs489-2016w-lintool-a2-wiki-stripes --reducers 10
</pre>
<p><b>Important:</b> Make sure that your code accepts the command-line
parameters above!<p>
<p>Brief explanation about the relationship
between <code>--num-executors</code>
and <code>--reducers</code>. The <code>--num-executors</code> flag
specifies the number of Spark workers that you allocate for this
particular job. The <code>--reducers</code> flag is the amount of
parallelism that you set in your program in the reduce
stage. If <code>--num-executors</code> is larger
than <code>--reducers</code>, some of the workers will be sitting
idle, since you've allocated more workers for the job than the
parallelism you've specified in your
program. If <code>--reducers</code> is larger
than <code>--num-executors</code>, then your reduce tasks will queue
up at the workers, i.e., a worker will be assigned more than one
reduce task. In the above example we set the two equal.</p>
<p>Note that the setting of these two parameters should not affect the
correctness of your program. The setting of ten above is a reasonable
middle ground between having your jobs finish in a reasonable amount
of time and not monopolizing cluster resources.</p>
<p>A related but still orthogonal concept is partitions. Partitions
describes the physical division of records across workers during
execution. When reading from HDFS, the number of HDFS blocks
determines the number of partitions in your RDD. When you apply a
reduce-like transformation, you can optionally specify the number of
partitions (or Spark applies a default) — in this case, the
number of partitions is equal to the number of reducers.</p>
<p>When you've done everything, commit to your repo and remember to
push back to origin. You should be able to see your edits in the web
interface. Before you consider the assignment "complete", we would
recommend that you verify everything above works by performing a clean
clone of your repo and going through the steps above.</p>
<p>That's it!</p>
<h4 style="padding-top: 10px">Grading</h4>
<p>This assignment is worth a total of 20 points, broken down as
follows:</p>
<ul>
<li>The pairs implementation running locally is worth 6 points; the stripes implementation running locally is worth another 6 points.</li>
<li>The pairs implementation running on Altiscale is worth 4 points; the stripes implementation running on Altiscale is worth another 4 points.</li>
</ul>
<p style="padding-top: 20px"><a href="#">Back to top</a></p>
</div>
</section>
<section id="assignment3" style="padding-top:35px">
<div>
<h3>Assignment 3: Inverted Indexing <small>due 8:30am February 2</small></h3>
<p>This assignment is to be completed in MapReduce in Java. You will
be working in the same repo as before, except that everything should
go into the package namespace
<code>ca.uwaterloo.cs.bigdata2016w.lintool.assignment3</code>
(obviously, replace <code>lintool</code> with your actual GitHub
username.</p>
<p>Look at the inverted indexing and boolean retrieval implementation
in <a href="http://bespin.io">Bespin</a>. Make sure you understand the
code. Starting from the inverted indexing
baseline <code>BuildInvertedIndex</code>, modify the indexer code in
the following ways:</p>
<p><b>1. Index Compression.</b> The index should be compressed using
<code>VInts</code>:
see <code>org.apache.hadoop.io.WritableUtils</code>. You should also
use gap-compression techniques as appropriate.</p>
<p><b>2. Buffering postings.</b> The baseline indexer implementation
currently buffers and sorts postings in the reducer, which as we
discussed in class is not a scalable solution. Address this
scalability bottleneck using techniques we discussed in class and in
the textbook.</p>
<p><b>3. Term partitioning.</b> The baseline indexer implementation
currently uses only one reducer and therefore all postings lists are
shuffled to the same node and written to HDFS in a single
partition. Change this so we can specify the number of reducers
(hence, partitions) as a command-line argument. This is, of course,
easy to do, but we need to make sure that the searcher understands
this partitioning also.</p>
<p><b>Note:</b> The major scalability issue is
buffering <i>uncompressed</i> postings in memory. In your solution,
you'll still end up buffering each postings list, but
in <i>compressed</i> form (raw bytes, no additional object
overhead). This is fine because if you use the right compression
technique, the postings lists are quite small. As a data point, on a
collection of 50 million web pages, 2GB heap is more than enough for a
full <i>positional</i> index (and in this assignment you're not asked
to store positional information in your postings).</p>
<p>To go into a bit more detail: in the reference implementation, the
final key type is <code>PairOfWritables<IntWritable,
ArrayListWritable<PairOfInts>></code>. The most obvious idea
is to change that into something
like <code>PairOfWritables<VIntWritable,
ArrayListWritable<PairOfVInts>></code>. This does not work!
The reason is that you will still be materializing each posting, i.e.,
all <code>PairOfVInts</code> objects in memory. This translates into a
Java object for every posting, which is wasteful in terms of memory
usage and will exhaust memory pretty quickly as you scale. In other
words, you're <i>still</i> buffering objects—just inside
the <code>ArrayListWritable</code>.
<p>This new indexer should be
named <code>BuildInvertedIndexCompressed</code>. This new class should
be in the
package <code>ca.uwaterloo.cs.bigdata2016w.lintool.assignment3</code>. Make
sure it works on the Shakespeare collection.</p>
<p>Modify <code>BooleanRetrieval</code> so that it works with the new
compressed indexes. Name this new
class <code>BooleanRetrievalCompressed</code>. This new class should
be in the same package as above and give the same
output as the old version.</p>
<p>Use <code>BuildInvertedIndex</code>
and <code>BooleanRetrieval</code> from Bespin as your starting
points. That is, copy over into your repo, rename, and begin your
assignment from there. Don't unnecessarily change code not directly
related to points #1-#3 above. In particular, <b>do not</b> change how
the documents are tokenized, etc. in <code>BuildInvertedIndex</code>
(otherwise there's no good way to check for the correctness of your
algorithm). Also, <b>do not</b> change the <code>fetchLine</code>
method in <code>BooleanRetrieval</code> so that everyone's output
looks the same.</p>
<p>In more detail, make sure that you can build the inverted index
with the following command (make sure your implementation runs in the
Linux student CS environment, as that is where we will be doing the
grading):</p>
<pre>
$ hadoop jar target/bigdata2016w-0.1.0-SNAPSHOT.jar \
ca.uwaterloo.cs.bigdata2016w.lintool.assignment3.BuildInvertedIndexCompressed \
-input data/Shakespeare.txt -output cs489-2016w-lintool-a3-index-shakespeare -reducers 4
</pre>
<p>We should be able to control the number of partitions (#3 above)
with the <code>-reducers</code> option. That is, the code should give
the correct results no matter what we set the value to.</p>
<p>Once we build the index, we should then be able to run a boolean
query as follows (in exactly the same manner
as <code>BooleanRetrieval</code> in Bespin</a>):</p>
<pre>
$ hadoop jar target/bigdata2016w-0.1.0-SNAPSHOT.jar \
ca.uwaterloo.cs.bigdata2016w.lintool.assignment3.BooleanRetrievalCompressed \
-index cs489-2016w-lintool-a3-index-shakespeare -collection data/Shakespeare.txt \
-query "outrageous fortune AND"
$ hadoop jar target/bigdata2016w-0.1.0-SNAPSHOT.jar \
ca.uwaterloo.cs.bigdata2016w.lintool.assignment3.BooleanRetrievalCompressed \
-index cs489-2016w-lintool-a3-index-shakespeare -collection data/Shakespeare.txt \
-query "white red OR rose AND pluck AND"
</pre>