10-405/605/805�ML FROM LARGE DATASETS
Announcements
Outline
Matrix Factorization
4
Recovering latent factors in a matrix
5
m movies
n users
m movies
x1 | y1 |
x2 | y2 |
.. | .. |
| |
| |
| |
| |
| |
… | … |
xn | yn |
a1 | a2 | .. | … | am |
b1 | b2 | … | … | bm |
v11 | … | | | |
… | … | | | |
| | | | |
| vij | | | |
| | | … | |
| | | | vnm |
~
V[i,j] = user i’s rating of movie j
Recovering latent factors in a matrix as optimization
6
m movies
n users
m movies
x1 | y1 |
x2 | y2 |
.. | .. |
| |
| |
| |
| |
| |
… | … |
xn | yn |
a1 | a2 | .. | … | am |
b1 | b2 | … | … | bm |
v11 | … | | | |
… | … | | | |
| | | | |
| vij | | | |
| | | … | |
| | | | vnm |
~
V[i,j] = user i’s rating of movie j
r
W
H
V
Matrix factorization as SGD
7
step size
why does this work?
Matrix factorization as SGD - why does this work? Here’s the key claim:
8
like linear least-squares regression
Recommendation losses differentiated
9
~ least squares regression
Recommendation losses differentiated
10
~ ridge regression
Other recommendation losses
11
N1, N2 - diagonal matrixes, sort of like IDF factors for the users/movies
“generalized” KL-divergence
12
ALS = alternating least squares
(special MF optimization method)
Netflix challenge dataset: 100M ratings from ~ 480k customers on ~ 18k movies
13
talk pilfered from 🡪 …..
KDD 2011
14
8 machines, 64 cores
Recap: minimal-mixing papers did get published!
Zinkevich et al, 2010
Recovering latent factors in a matrix
16
m movies
n users
m movies
x1 | y1 |
x2 | y2 |
.. | .. |
| |
| |
| |
| |
| |
… | … |
xn | yn |
a1 | a2 | .. | … | am |
b1 | b2 | … | … | bm |
v11 | … | | | |
… | … | | | |
| | | | |
| vij | | | |
| | | … | |
| | | | vnm |
~
V[i,j] = user i’s rating of movie j
Recovering latent factors in a matrix
17
m movies
n users
m movies
y1 | x1 |
y2 | x2 |
.. | .. |
| |
| |
| |
| |
| |
… | … |
yn | xn |
b1 | b2 | .. | … | bm |
a1 | a2 | … | … | am |
v11 | … | | | |
… | … | | | |
| | | | |
| vij | | | |
| | | … | |
| | | | vnm |
~
V[i,j] = user i’s rating of movie j
18
Averaging different clusters!
19
Converging but slowly…
20
21
22
23
24
25
DSGD
ALS
iterative mixing
LBFGS
one mixing round
Wall Clock Time
26
DSGD
ALS
iterative mixing
LBFGS
one mixing round
Outline
Outline
Recap: SGD for Logistic Regression
Recap: The “hash trick”
an array V = <0…0>
of fixed length M
h(xi)= j
Assume a hash function h(token) = hash(token) % M
V[j] = V[j]
array V
⍺
Recap: Hash Trick - Insights
Recap: Hash Kernels
Pr(all duplicates of any feature collide) gets low
Bloom filters also exploit this idea
BLOOM FILTERS
Bloom filters
def __init__ (self, maxSize:int, p: double):
# start with empty set
def bf.add(String s):
# insert string s into the set
def bf.contains(String s) 🡪 bool:
# if s was added return true;
# else with probability at least 1-p return false;
# else with probability at most p return true;
Bloom filters
Bloom filters
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
bf.add(“fred flintstone”):
0 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
h1
h2
h3
bf.add(“barney rubble”):
1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
h1
h2
h3
Bloom filters
1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
bf.contains (“fred flintstone”):
1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
h1
h2
bf.contains(“barney rubble”):
1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
h1
h2
h3
✅
✅
Bloom filters
bf.contains(“wilma flintstone”):
1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
h1
h2
h3
1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
bf.contains(“wilma flintstone”):
1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
h1
h2
h3
✅
❌
Bloom filters: analysis
k =
f(m,n,k) =
Bloom filters
E.g., the value for m in terms of n and p:
f(m,n) =
Bloom filters
def __init__ (self, maxSize:int, n:int, p: double):
# start with empty set
def bf.add(String s):
# insert string s into the set
def bf.contains(String s) 🡪 bool:
# if s was added return true;
# else with probability at least 1-p return false;
# else with probability at most p return true;
Bloom filters: demo
Bloom filters: a slightly different version
Building one sketch with one hash function:
Building t sketches with t hash functions:
=
each
Test membership with AND of all the sketches:
Bloom filters: a slightly different version
Bloom filters: a slightly different version
(1) Assume for all a, i, x:
(2) Assume for all a, b, i, j, x, x’:
up to k elements of set of size V
Probability over random choice of hi
…then repeatedly apply (2)
up to k elements of set of size V
< 𝛿
Bloom filters: a slightly different version
What do you do with a Bloom filter?
Some uses of Bloom filters
Some Uses of Bloom filters
Some Uses of Bloom filters
Some Uses of Bloom filters
Outline
THE COUNT-MIN SKETCH
Bloom Filter
Hash Kernel
Count-Min Sketch
Bloom Filter🡪Count-min sketch
CM sketch maps x to a number a[x]
But you can only update a[x] by adding to it
Important:
v ≥ 0
Bloom Filter🡪Count-min sketch
Bloom Filter🡪Count-min sketch
Count-min sketch results
Count-min sketch results
CM Sketch Structure
A Quick Intro to Data Stream Algorithmics – CS262
+c
+c
+c
+c
h1(s)
hd(s)
<s, +c>
d=log 1/δ
w = 2/ε
from: Minos Garofalakis�
i.e. with prob > 1-𝛿
A Quick Intro to Data Stream Algorithmics – CS262
c
c
c
c
from: Minos Garofalakis�
d
d
d
d
c+d
d
d
d
c
c
c
+
<s, +c>
<t, +d>
CM Sketch Guarantees
A Quick Intro to Data Stream Algorithmics – CS262
61
from: Minos Garofalakis�
CM Sketch Guarantees
A Quick Intro to Data Stream Algorithmics – CS262
from: Minos Garofalakis�
Applications of Count-Min Sketches 1
Background
2002
Background
2002 – 12,000+ citations
Dataset of movie reviews (pos, negative)
An Application of a Count-Min Sketch
x appears near y
An Application of a Count-Min Sketch
x appears near y
Turney, 2002 used two seeds, “excellent” and “poor”
In general, SO(w) can be written in terms of logs of products of counters for w, with and without seeds
An Application of a Count-Min Sketch
Math for Count-Min Sketches
An Application of a Count-Min Sketch
CM-CU: CM with “conservative update” - for <j,+c> increment counters just enough to make the new estimate for j grow by c
Bloom filter / Count-min sketch
Bloom filters: the math
(1) Assume for all a, i, x:
(2) Assume for all a, b, i, j, x, x’:
up to k elements of set of size V
Probability over random choice of hi
…then repeatedly apply (2)
Bloom filters: the math
< 𝛿
Count-min sketch results
Count-min sketch results
CM-Sketch: the math
…then repeatedly apply (2)
recap of BF math
Pr(excess in r[h(x)] due to collisions with other x’) > 𝜺 ||a||1) < 1/e
CM-Sketch: the math
Expectation is:
Pr(excess in r[h(x)] due to collisions with other x’) > 𝜺 ||a||1) < 1/e
Goal: show that for a particular hash function t and x
So the goal is to show:
= 1/e
Markov
inequality
CM-Sketch: the Markov Inequality
when X is a random variable that has non-negative real values
≥
c
Count-min sketch result: recap