Skip to content

Commit c819571

Browse files
committed
Add exam from last year
1 parent a77824c commit c819571

File tree

12 files changed

+330
-0
lines changed

12 files changed

+330
-0
lines changed

.github/workflows/ExportPluto.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ jobs:
2424
- name: Checkout this repository
2525
uses: actions/checkout@v4
2626

27+
- name: Compile exam 2025_01
28+
uses: xu-cheng/latex-action@v4
29+
with:
30+
working_directory: Exams/2025_01/
31+
root_file: main.tex
32+
2733
- name: Install Julia
2834
uses: julia-actions/setup-julia@v2
2935
with:

Exams/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.synctex.gz
2+
*.aux
3+
*.fdb_latexmk
4+
*.fls
5+
*.log
6+
*.out
7+
#*.pdf # We shouldn't ignore it otherwise `github-pages-deploy-action` will not add the produced pdf and won't push it to `gh-pages`
8+
*.synctex.gz

Exams/2025_01/main.tex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
%\documentclass[addpoints,12pt,a4paper]{exam}
2+
\documentclass[addpoints,answers,12pt,a4paper]{exam} % print solutions
3+
4+
\newcommand{\ExamDate}{January 2025}
5+
\input{../utils/preamble}
6+
7+
\begin{document}
8+
\input{../utils/rules}
9+
10+
\begin{questions}
11+
\input{q1}
12+
\clearpage
13+
\input{q2}
14+
\clearpage
15+
\input{q3}
16+
\end{questions}
17+
18+
\end{document}

Exams/2025_01/q1.tex

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
\titledquestion{Kernels for prediction of gene expression}
2+
3+
One would like to predict, from the DNA sequence of an individual (or an appropriate subsequence), the level of expression of a particular gene (for instance, in order to estimate the predisposition of said individual to a disease). A DNA (sub)sequence is a string of $n$ letters taken in a four-letter alphabet (A,C,G,T).
4+
5+
The gene expression level is a real number. We thus must build a map from $n$-letter strings to the reals. We may want to infer this map from $N$ examples $(s_i,r_i)$ (for $i=1,\ldots,N$), where $s_i$ is an $n$-letter string (a DNA sample) and $r_i$ a real number (a gene expression level). This is a regression task. Here we propose a kernel ridge regression to solve it.
6+
7+
Given two strings $s$, $s'$ of length $n$ on the A,C,G,T alphabet, and an integer $\ell < n$ let us consider $k_{\ell}(s,s')$ as the number of $\ell$-letter strings present (at least once) in both $s$ and $s'$. For instance if $s=ACACACGT$ and $s'=ACGTCACA$, and $\ell=3$, we find $k_3(s,s')=4$, because $ACA$, $CAC$, $ACG$ and $CGT$ appear (at least once) in both $s$ and $s'$.
8+
9+
\begin{itemize}
10+
\item Build a map $s \mapsto \phi(s) \in \mathbb{R}^d$ into a feature space $\mathbb{R}^d$ so that $k_{\ell}(s,s')= \langle \phi(s) , \phi(s') \rangle$. Express $d$ as a function of $\ell$ and $n$. Here $ \langle .,. \rangle$ is the usual scalar product in $\mathbb{R}^d$.
11+
12+
\begin{solutionbox}{3cm}
13+
\end{solutionbox}
14+
15+
Thus $k_\ell(.,.)$ is a kernel map indeed. Call $K_\ell$ the corresponding $N$-by-$N$ kernel matrix.
16+
17+
\item Justify that the regression map found by the kernel ridge regression method (for any given choice of $\ell$) can be written as $s \mapsto \sum_{i=1}^N w_i k_\ell(s_i,s)$, for some $w_i$ to be found. You may use facts and theorems stated in the lectures (and cite them clearly).
18+
19+
\begin{solutionbox}{3cm}
20+
\end{solutionbox}
21+
22+
\item Formulated in terms of $\mathbf{w}=(w_1, \ldots, w_N)$, the kernel ridge regression problem can be written as
23+
$$
24+
\min_{\mathbf{w} \in \mathbb{R}^N} L(\mathbf{w})
25+
$$
26+
for some objective function. Write down the objective function $L(\mathbf{w})$. Explain briefly each term.
27+
28+
\begin{solutionbox}{3cm}
29+
\end{solutionbox}
30+
31+
\item What is the computational complexity (i.e., computation time) of deriving the regression map (i.e., computing the vector $w$)? Justify briefly. Your expression should depend of $N$, $n$, $\ell$.
32+
33+
You may accept and use the following facts or assumptions: that $\ell \ll n$; that matrix $K$ is best computed entrywise (all $N^2$ entries separately); that computing $k_{\ell}(s,s')$ is done (for $\ell \ll n$) in time $\mathcal{O}(\ell n)$ (which means ``in time no larger than $c \ell n$, for some constant $c$'') for each given pair of strings $s$,$s'$; that solving an $N$-by-$N$ linear system $Ax=b$ (for some $N$-by-$N$ matrix $A$ and some vector $b$) is done in time $\mathcal{O}(N^3)$ in general.
34+
35+
36+
\begin{solutionbox}{4cm}
37+
\end{solutionbox}
38+
39+
\item What is the computational complexity (i.e., computation time) of computing the regression map on a new string $s$? Justify briefly. Your expression should depend of $N$, $n$, $\ell$. Here we assume that the kernel matrix $K$ and the vector $w$ have already been computed.
40+
41+
\begin{solutionbox}{4cm}
42+
\end{solutionbox}
43+
44+
\item {\bf Bonus} We could use a classification approach instead of regression. We can consider that the gene of interest is either ``expressed'' (if $r \geq r_0$, for some appropriate threshold $r_0$) or ``non-expressed'' (if $r < r_0$).
45+
We may now use a Kernel SVM method. Compare this approach (in terms of respective strengths or weaknesses) with the regression approach on three different aspects (e.g. relevance for the application, computational complexity, simplicity, interpretability, etc.). This is an open question, with a range of sensible answers.
46+
47+
\begin{solutionbox}{4cm}
48+
\end{solutionbox}
49+
50+
\end{itemize}
51+
52+
NB: many machine-learning methods have been proposed by researchers for this important problem, involving kernels (more sophisticated than the one above), or CNN, transformers, etc.

Exams/2025_01/q2.tex

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
\titledquestion{Automatic Differentiation and Attention}
2+
3+
Consider the matrices
4+
$V \in \mathbb{R}^{d_v \times n_\text{ctx}},
5+
K \in \mathbb{R}^{d_k \times n_\text{ctx}}$
6+
and an attention head applied to a vector $q$ : $a(q) = V\text{softmax}(K^\top q / \sqrt{d_k})$
7+
where the $i$-th entry of $\text{softmax}(x)$ is $\exp(x_i) / \sum_j \exp(x_j)$.
8+
Suppose that you want to compute Jacobian $L$ of $a(q)$, which is the derivative of all outputs of the attention
9+
head with respect to each entry of the vector $q$.
10+
In other words, $L_{ij} = \partial a_i / \partial q_j$.
11+
12+
\begin{itemize}
13+
\item Find the matrix $J$ to be used to compute
14+
the derivative of $a$ with respect to the $j$-th entry of $q$
15+
with the formula
16+
$$\partial a / \partial q_j = V J K^\top e_j / \sqrt{d_k}.$$
17+
\emph{Hint:} The entries of the matrix $J$ can be written purely in terms
18+
of the entries of the vector $s = \text{softmax}(K^\top q / \sqrt{d_k})$.
19+
\begin{solutionbox}{9cm}
20+
Let $x = K^\top q / \sqrt{d_k}$. We have
21+
\begin{align*}
22+
J_{ij} & =
23+
\partial s_i / \partial x_j\\
24+
& =
25+
\frac{\partial}{\partial x_j} \frac{\exp(x_i)}{\sum_{k=1}^{n_{\text{ctx}}} \exp(x_k)}\\
26+
& =
27+
\frac{\exp(x_i)}{\sum_{k=1}^{n_{\text{ctx}}} \exp(x_k)}
28+
\frac{\partial x_i}{\partial x_j}
29+
-
30+
\frac{\exp(x_i)}{(\sum_{j=1}^{n_{\text{ctx}}} \exp(x_j))^2}
31+
\frac{\partial}{\partial x_j} \sum_{k=1}^{n_{\text{ctx}}} \exp(x_k)\\
32+
& =
33+
s_i
34+
\frac{\partial x_i}{\partial x_j}
35+
- s_is_j.
36+
\end{align*}
37+
So the entries of $J$ are:
38+
\begin{align*}
39+
J_{ii} & = s_i - s_i^2\\
40+
J_{ij} & = -s_is_j & \quad i \neq j.
41+
\end{align*}
42+
\end{solutionbox}
43+
\item The previous question corresponds to \emph{forward} differentiation.
44+
Using \emph{reverse} differentiation, you would like now to
45+
compute the gradient of $a_i$ with respect to the vector $q$.
46+
How can you compute this gradient vector via matrix-vector products ?
47+
48+
\emph{Hint:} $\partial a_i / \partial q_j$ is the scalar product between
49+
$\partial a / \partial q_j$ and $e_i$.
50+
\begin{solutionbox}{6cm}
51+
As $J$ is diagonal, it is its own transpose.
52+
\begin{align*}
53+
\partial a_i / \partial q_j
54+
& =
55+
\langle V J K^\top e_j / \sqrt{d_k}, e_i \rangle\\
56+
& =
57+
\langle e_j, K J^\top V^\top e_i / \sqrt{d_k} \rangle\\
58+
\partial a_i / \partial q
59+
& =
60+
K J V^\top e_i / \sqrt{d_k}\\
61+
\end{align*}
62+
\end{solutionbox}
63+
\item
64+
Depending on $d_v, d_k, n_\text{ctx}$, which one will be faster between forward and reverse differentiation
65+
to compute the \textbf{full} Jacobian matrix $\partial a / \partial q$ ? Why ?
66+
\begin{solutionbox}{4cm}
67+
Forward diff concatenates $\partial a / \partial q_j$ horizontally for each $j$ and
68+
reverse diff concatenates $\partial a_i / \partial q$
69+
vertically for each $i$.
70+
In other words, forward diff computes $V(JK^\top)$ while
71+
reverse diff computes $K(J^\top V^\top)$ or equivalently
72+
$(VJ)K^\top$.
73+
The complexity of forward diff is $O(n_\text{ctx}^2 d_k + n_\text{ctx} d_k d_v)$
74+
while the complexity of reverse diff is
75+
$O(n_\text{ctx}^2 d_v + n_\text{ctx} d_k d_v)$.
76+
This means that forward diff is faster if $d_k < d_v$, otherwise reverse diff is faster.
77+
\end{solutionbox}
78+
\item How could this computation be accelerated using a GPU instead of a CPU ?
79+
\begin{solutionbox}{2cm}
80+
As these are matrix-matrix products, this computation is highly parallelizable
81+
and hence will get a good speed up on a GPU.
82+
\end{solutionbox}
83+
\end{itemize}

Exams/2025_01/q3.tex

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
\titledquestion{Stable Diffusion for music generation}
2+
3+
Consider the problem of music generation given a text prompt.
4+
For instance, given ``classic jazz'', the model should generate a music of
5+
style ``classic jazz''.
6+
The music is represented by a sequence $(y_k)_{k=1}^N$ of real numbers of
7+
fixed length $N$.
8+
These represent the intensity of the music sampled at a given fixed rate (for instance every millisecond).
9+
10+
\begin{itemize}
11+
\item Draw the model and different components that you would use for this:
12+
\begin{solutionbox}{8.5cm}
13+
\emph{(sketch)}
14+
Transformer encoder for the text prompt which is then given by
15+
a diffusion model with cross-attention.
16+
The diffusion model starts with a random vector of $N$ numbers
17+
and then generates the music.
18+
\end{solutionbox}
19+
\item Describe the datasets needed and the procedure to be used to train each component of the model.
20+
\begin{solutionbox}{4cm}
21+
\emph{(sketch)}
22+
First train encoder and then diffusion model.
23+
\end{solutionbox}
24+
\item Given a text prompt, describe the procedure to generate a new music.
25+
\begin{solutionbox}{4cm}
26+
\emph{(sketch)}
27+
Classifier-Free Guidance.
28+
\end{solutionbox}
29+
\item Explain how you can use an auto-encoder to prevent the model from learning imperceptible details of the music. How do you adapt the training and inference process with this new component ?
30+
\begin{solutionbox}{4cm}
31+
\emph{(sketch)}
32+
Use Variational Auto-Encoder to first compress the music.
33+
\end{solutionbox}
34+
\item Suppose that you want to generate a ``classic jazz'' music that, when reversed in time sounds like ``classic rock''.
35+
How would you use your already trained model to achieve this task without retraining ?
36+
\begin{solutionbox}{4cm}
37+
\emph{(sketch)}
38+
Like project.
39+
\end{solutionbox}
40+
\end{itemize}

Exams/utils/commands.tex

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
%
2+
% Commandes perso du template d'examen en math
3+
%
4+
% Version: 5.1.2022
5+
% Auteurs:
6+
% PY.Gousenbourger
7+
8+
% Mathématiques
9+
\newcommand{\R}{\mathbb{R}}
10+
\newcommand{\C}{\mathbb{C}}
11+
\newcommand{\Z}{\mathbb{Z}}
12+
\newcommand{\N}{\mathbb{N}}
13+
14+
% Commands for tabularx (ask Stephanie Guerit for more details)
15+
\def\tabularxcolumn#1{m{#1}}
16+
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
17+
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
18+
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
19+
\newcolumntype{Z}{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}X}

Exams/utils/header.tex

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
\pagestyle{headandfoot}
2+
\extraheadheight{2cm}
3+
4+
\chead{
5+
\renewcommand{\arraystretch}{1.6}
6+
\begin{tabularx}{\textwidth}{|L{3cm} Z L{5.5cm}|}
7+
\hline
8+
UCLouvain \newline EPL Faculty \newline \ExamDate & %
9+
\textbf{Exam : LINMA2472} \newline Algorithms in data science & %
10+
First Name : {\sf \Prenom } \newline Last Name : {\sf \Nom} \newline NOMA : {\sf }\\
11+
\hline
12+
\end{tabularx}
13+
\renewcommand{\arraystretch}{1.1}
14+
}
15+
\cfoot{
16+
-- Page \thepage \ of \numpages \ --
17+
}

Exams/utils/packages.tex

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
% Language
2+
\usepackage[utf8]{inputenc}
3+
\usepackage[T1]{fontenc}
4+
\usepackage{lmodern}
5+
\usepackage[french]{babel}
6+
\usepackage{titlesec}
7+
\usepackage{eurosym}
8+
9+
% Formatting
10+
\usepackage{color}
11+
\usepackage{enumerate}
12+
\usepackage{multicol}
13+
\usepackage{url}
14+
\usepackage{hyperref}
15+
\usepackage{comment} % To hide or show environments (see newcommand)
16+
\usepackage{booktabs}
17+
\usepackage{tabularx}
18+
\usepackage{tabto}
19+
\usepackage{siunitx}
20+
21+
% Maths
22+
\usepackage{amssymb,amsmath,amsthm}
23+
\usepackage{empheq}
24+
\usepackage{chngcntr} % for theorems numbering
25+
26+
% Graphics
27+
\usepackage{graphicx}
28+
\usepackage{caption,subcaption}
29+
30+
% Drawings (tikz)
31+
\usepackage{tikz}
32+
\usetikzlibrary{babel} % Compatibility with babel package
33+
\usetikzlibrary{graphs}
34+
\usetikzlibrary{graphs.standard}
35+
\usepackage{pgfplots}
36+
\pgfplotsset{compat=1.13}

Exams/utils/preamble.tex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
\input{../utils/packages} % packages
2+
\input{../utils/commands} % commandes perso
3+
\qformat{\textbf{Question \thequestion\ }: \thequestiontitle \hfill}
4+
5+
6+
\newcommand{\blankname}{\parbox[b]{4cm}{\hrulefill}}
7+
\newcommand{\Nom}{}
8+
\newcommand{\Prenom}{}
9+
10+
\input{../utils/header}
11+
12+
\setlength\parindent{0pt}

0 commit comments

Comments
 (0)