-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodule9.html
179 lines (132 loc) · 5.21 KB
/
module9.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
<!DOCTYPE html>
<html>
<head>
<title>Unsupervised Learning - Autoencoders [Marc Lelarge]</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="./assets/katex.min.css">
<link rel="stylesheet" type="text/css" href="./assets/slides.css">
<link rel="stylesheet" type="text/css" href="./assets/grid.css">
</head>
<body>
<textarea id="source">
class: center, middle, title-slide
count: false
# Module 9
## Unsupervised learning
## Autoencoders
<br/><br/>
.bold[Marc Lelarge]
---
# Overview of the course:
1- .grey[Course overview: machine learning pipeline]
2- .grey[PyTorch tensors and automatic differentiation]
3- .grey[Classification with deep learning]
4- .grey[Convolutional neural networks]
5- .grey[Embedding layers and dataloaders]
6- Unsupervised learning: auto-encoders and generative adversarial networks
* .red[Deep learning architectures] - in PyTorch: recap!
---
# Autoencoders (AE)
## practicals: denoising with AE
---
# Autoencoders
Autoencoders are used to learn compressed data representation in an .red[unsupervised manner].
Autoencoders can be seen as a simple example of .red[self-supervised learning]: the data provides the supervision!
An autoencoder maps a space to itself and is [close to] the identity on the data.
--
count: false
.center[
<img src="images/module9/AE.png" style="width: 500px;" />
]
Dimension reduction can be achieved with an autoencoder composed of an encoder $F$ from the original space to a latent space, and a decoder $G$ to map back to the original space.
If the latent space is of lower dimension, the autoencoder has to capture a "good" representation of the data.
---
# Autoencoders in PyTorch
The simplest possible autoencoder with a single fully-connected neural layer as encoder and as decoder:
```
class AutoEncoder(nn.Module):
def __init__(self, input_dim, encoding_dim):
super(AutoEncoder, self).__init__()
self.encoder = nn.Linear(input_dim, encoding_dim)
self.decoder = nn.Linear(encoding_dim, input_dim)
def forward(self, x):
encoded = F.relu(self.encoder(x))
decoded = self.decoder(encoded)
return decoded
```
--
count: false
After training, we obtain:
.center[
<img src="images/module9/result_AE.png" style="width: 600px;" />
]
---
# Representation learning with autoencoders
To get an intuition of the latent representation, we can pick two samples $x$ and $x'$ and interpolate samples along the line in the latent space: the line bewteen the codes obtained by the encoder $F$ for $x$ and $x'$ is defined by: for $\alpha\in [0,1]$
$$
(1-\alpha)F(x) + \alpha F(x').
$$
We use the decoder $G$ in order to get back in the original space from this embeddding in the latent space:
$$
G((1-\alpha)F(x) + \alpha F(x'))
$$
--
count: false
Interpolating between digits two and nine:
.center[
<img src="images/module9/interp_AE.png" style="width: 700px;" />
]
---
# .grey[Autoencoders (AE)]
## [practicals: denoising with AE](https://github.com/dataflowr/notebooks/blob/master/Module9/09_AE_NoisyAE.ipynb)
---
class: end-slide, center
count: false
The end.
</textarea>
<script src="./assets/remark-latest.min.js"></script>
<script src="./assets/auto-render.min.js"></script>
<script src="./assets/katex.min.js"></script>
<script type="text/javascript">
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
//var options = {sourceUrl: getParameterByName("p"),
// highlightLanguage: "python",
// // highlightStyle: "tomorrow",
// // highlightStyle: "default",
// highlightStyle: "github",
// // highlightStyle: "googlecode",
// // highlightStyle: "zenburn",
// highlightSpans: true,
// highlightLines: true,
// ratio: "16:9"};
var options = {sourceUrl: getParameterByName("p"),
highlightLanguage: "python",
highlightStyle: "github",
highlightSpans: true,
highlightLines: true,
ratio: "16:9",
slideNumberFormat: (current, total) => `
<div class="progress-bar-container">${current}/${total} <br/><br/>
<div class="progress-bar" style="width: ${current/total*100}%"></div>
</div>
`};
var renderMath = function() {
renderMathInElement(document.body, {delimiters: [ // mind the order of delimiters(!?)
{left: "$$", right: "$$", display: true},
{left: "$", right: "$", display: false},
{left: "\\[", right: "\\]", display: true},
{left: "\\(", right: "\\)", display: false},
]});
}
var slideshow = remark.create(options, renderMath);
</script>
</body>
</html>