10-405/605/805�ML FROM LARGE DATASETS
Announcements
Outline
Countmin notes
X is a positive random variable
Outline
LSH review
16
32
64
128
256
LSH review
LSH review
Probability that a random projection does not “split” two points is exactly their cosine similarity
LSH for k-NN search
Visualization: https://10605.github.io/viz/simhash.html
k-NN search and Multi-index Hashing
k-NN search and Multi-index Hashing
An alternative: k-means for k-NN search
kJ-means for k-NN search
J-means Clustering
14
centroids
J-means for k-NN search
Vector quantization
Product quantization for k-NN search
A Recent(ish) Survey
2024
Outline
Automatic Differentiation and Deep Learning
20
Recap: Polars LazyFrame actions
21
We will use the same trick to make gradient computations for complex, arbitrary functions easy
Autodiff
22
Wengert list
What we did in calculus 101
Flattened version of computation graph
We don’t want a symbolic form for the derivative – we want an algorithm to compute it at any given point
Autodiff
23
x1
x2
add
add
square
f
Flattened version of computation graph
Autodiff on Wengert lists (“tape” of operations) is simple
Autodiff
24
x1=2
x2=3
add=4
add=7
square=49
f=49
Flattened version of computation graph
We can compute the value of f at a given point, like (x1,x2)=(2,3)
Want an algorithm to compute partial derivatives at any given points
g1(2,3)=28
g2(2,3)=14
Goal: use the compute graph to compute g1(x1,x2), g2(x1,x2)
g1(x1,x2) =
g2(x1,x2) =
What we did in calculus 101
Wengert lists: forward (eval)
25
Possible Python data structure:
Plus the definitions:
Wengert lists: forward (eval)
26
Plus the definitions:
and input values:
Wengert lists: backward (gradients)
27
Need the partial derivatives of each function wrt. each input:
Still need the definitions:
and input values:
Wengert lists: backward (gradients)
28
val[…] from forward pass
final output of Wengert list
backpropagated error
Why is this correct?
Simple case: a chain of functions
30
High school: symbolic differentiation, compute a symbolic form of the deriv of f
Now: automatic differentiation, find an algorithm to compute f’(a) at any point a
Differentiating a Wengert list: a simple case
31
Now: automatic differentiation, find an algorithm to compute f’(a) at any point a
Notation (1):
🡪
ai is the i-th output
on input a
Differentiating a Wengert list: a simple case
32
for all a
m-1,0
What did Liebnitz mean with this?
Notation (1):
🡪
ai is the i-th output
on input a
Differentiating a Wengert list: a simple case
33
for all a
reverse-mode compute order
need to track:
Wengert lists: backward (gradients)
34
e.g.
Wengert list
return
inputs:
Step 1: forward
Step 2: backward
evaluated at (x1,…,xn)
Computed in previous step
inputs, func. for step 7
Wengert lists: backward (gradients)
35
Plus the definitions:
and input values:
Wengert lists: backward (gradients)
36
Need the partial derivatives of each function wrt. each input:
Now “backpropagate errors (loss)” to each variable. We want:
Wengert lists: backward (gradients)
37
Ridge Regression as a Wengert list
38
Autodiff with linear algebra operations is much more useful
Also a little more confusing…
df/dw is a vector <df/dw1, … df/dwn>
Logistic Regression as a Wengert list
39
Like logistic
where:
Logistic Regression as a Wengert list
40
loss = crossEntropy(softmax(z), y) is widely used
but it’s important to use this version
Logistic Regression as a Wengert list
41
loss = crossEntropy(softmax(z), y) is widely used
Also if p is the output of the softmax, there is a simple form of d loss / d z
d loss / d z = p - y
Logistic Regression as a Wengert list
42
How can you take advantage of this?
(1) write a special crossEntropyOfSoftmax(z, y) function in your library of functions.
torch.nn.CrossEntropyLoss
(2) optimize the “generated code”
Most systems do a lot of both
Notes on Wengert lists
43
Notes on Wengert lists
44