Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion _extensions/linogaliana/rev-history/rev-history.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ return {

-- return as string
if tags ~= nil then
-- "-citations": un message de commit contenant "@user" ne doit pas
-- être lu comme une clé bibliographique (erreur fatale en Typst)
return pandoc.read(
"<table class='commit-table' border='1'>" ..
header .. divider .. tags ..
"</tbody></table>\n\n"
"</tbody></table>\n\n",
"markdown-citations"
).blocks
else
return pandoc.Null()
Expand Down
27 changes: 25 additions & 2 deletions _quarto-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ website:

format:
html:
# gitlink ne sert qu'au HTML (widget): en Typst il plante sur `bibliography`
# (pandoc.utils.references lit un nom de fichier vide)
filters:
- path: gitlink
at: post-quarto
include-after-body: build/js/mac.html
respect-user-color-scheme: true
theme:
Expand All @@ -108,6 +113,26 @@ format:
mainfont: "Open Sans"
monofont: "JetBrains Mono"
linestretch: 1.65
typst:
# Mise en forme des chapitres en PDF: voir styles/typst/README.md
font-paths:
- fonts
- _extensions/quarto-ext/fontawesome/assets/webfonts
papersize: a4
fontsize: 10.5pt
toc: true
toc-depth: 2
linkcolor: "#447099"
highlight-style: atom-one-dark
date-format: long
filters:
- styles/typst/inline-code.lua
template-partials:
- styles/typst/typst-template.typ
- styles/typst/typst-show.typ
- styles/typst/page.typ
include-in-header:
- styles/typst/style.typ
ipynb: default


Expand All @@ -124,8 +149,6 @@ filters:
- build/replace-title.lua
- _extensions/linogaliana/details-iframe/details.lua
- _extensions/linogaliana/lang-switch/button.lua
- path: gitlink
at: post-quarto
extensions:
gitlink:
enabled: false
Expand Down
20 changes: 20 additions & 0 deletions _quarto-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ format:
code-overflow: wrap
include-in-header:
- build/toggle.js
typst:
# Mise en forme des chapitres en PDF: voir styles/typst/README.md
font-paths:
- fonts
- _extensions/quarto-ext/fontawesome/assets/webfonts
papersize: a4
fontsize: 10.5pt
toc: true
toc-depth: 2
linkcolor: "#447099"
highlight-style: atom-one-dark
date-format: long
filters:
- styles/typst/inline-code.lua
template-partials:
- styles/typst/typst-template.typ
- styles/typst/typst-show.typ
- styles/typst/page.typ
include-in-header:
- styles/typst/style.typ
ipynb: default


Expand Down
27 changes: 25 additions & 2 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ website:

format:
html:
# gitlink ne sert qu'au HTML (widget): en Typst il plante sur `bibliography`
# (pandoc.utils.references lit un nom de fichier vide)
filters:
- path: gitlink
at: post-quarto
include-after-body: build/js/mac.html
respect-user-color-scheme: true
theme:
Expand All @@ -84,6 +89,26 @@ format:
mainfont: "Open Sans"
monofont: "JetBrains Mono"
linestretch: 1.65
typst:
# Mise en forme des chapitres en PDF: voir styles/typst/README.md
font-paths:
- fonts
- _extensions/quarto-ext/fontawesome/assets/webfonts
papersize: a4
fontsize: 10.5pt
toc: true
toc-depth: 2
linkcolor: "#447099"
highlight-style: atom-one-dark
date-format: long
filters:
- styles/typst/inline-code.lua
template-partials:
- styles/typst/typst-template.typ
- styles/typst/typst-show.typ
- styles/typst/page.typ
include-in-header:
- styles/typst/style.typ
ipynb: default


Expand All @@ -101,8 +126,6 @@ filters:
- build/replace-title.lua
- _extensions/linogaliana/details-iframe/details.lua
- _extensions/linogaliana/lang-switch/button.lua
- path: gitlink
at: post-quarto
extensions:
gitlink:
enabled: false
Expand Down
43 changes: 22 additions & 21 deletions build/append-environment/_meta_info.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Pour utiliser exactement le même environnement (version de `Python` et _package



::: {.content-visible when-format="html"}

::: {.callout-note collapse="true"}
## Historique du fichier {{< fa brands git-alt >}}

Expand All @@ -40,6 +42,8 @@ html`<div>${git_history_graph}</div>`

:::

:::

::::

:::: {.content-visible when-profile="en"}
Expand All @@ -59,6 +63,8 @@ To use exactly the same environment (version of `Python` and _packages_), please

:::

::: {.content-visible when-format="html"}

::: {.callout-note collapse="true"}
## File history {{< fa brands git-alt >}}

Expand All @@ -82,12 +88,16 @@ html`<div>${git_history_graph}</div>`

:::

:::

::::





::: {.content-visible when-format="html"}

```{ojs}
//| echo: false
creation = d3.min(
Expand Down Expand Up @@ -179,26 +189,19 @@ git_history_graph = {
}
const isFirst = i === 0
const isLast = i === commits.length - 1
rows.push(html`<li class="fh-row fh-commit ${c.pr ? "fh-pr" : ""} ${isFirst ? "fh-first" : ""} ${isLast ? "fh-last fh-root" : ""}">
<span class="fh-dot"></span>
<div class="fh-title">
${isFirst ? html`<span class="fh-pill fh-pill-head">${labels.latest}</span>` : ""}
${isLast ? html`<span class="fh-pill fh-pill-root">${labels.created}</span>` : ""}
<a class="fh-sha" href="${github_repo}/commit/${c.sha}">${c.sha}</a>
<span class="fh-msg">${c.message}</span>
${c.pr ? html`<a class="fh-pill fh-pill-pr" href="${github_repo}/pull/${c.pr}">#${c.pr}</a>` : ""}
</div>
<div class="fh-meta" title="${fmtFull.format(c.date)}">${fmt.format(c.date)} · ${labels.by} ${c.author}</div>
</li>`)
const head = isFirst ? html`<span class="fh-pill fh-pill-head">${labels.latest}</span>` : ""
const root = isLast ? html`<span class="fh-pill fh-pill-root">${labels.created}</span>` : ""
const pr = c.pr ? html`<a class="fh-pill fh-pill-pr" href="${github_repo}/pull/${c.pr}">#${c.pr}</a>` : ""
const title = html`<div class="fh-title">${head}${root}<a class="fh-sha" href="${github_repo}/commit/${c.sha}">${c.sha}</a><span class="fh-msg">${c.message}</span>${pr}</div>`
const meta = html`<div class="fh-meta" title="${fmtFull.format(c.date)}">${fmt.format(c.date)} · ${labels.by} ${c.author}</div>`
rows.push(html`<li class="fh-row fh-commit ${c.pr ? "fh-pr" : ""} ${isFirst ? "fh-first" : ""} ${isLast ? "fh-last fh-root" : ""}"><span class="fh-dot"></span>${title}${meta}</li>`)
})

return html`<div class="fh">
<div class="fh-scroll"><ol class="fh-list">${rows}</ol></div>
<div class="fh-legend">
<span class="fh-pr-legend"><span class="fh-dot"></span>${labels.plain}</span>
<span class="fh-pr"><span class="fh-dot"></span>${labels.pr}</span>
</div>
</div>`
// Les gabarits html tiennent sur une seule ligne: en sortie Typst, ce code n'est pas
// interprété par Quarto et pandoc le lit comme du markdown; une balise `<div` en début
// de ligne y ouvrirait une vraie div.
const legend = html`<div class="fh-legend"><span><span class="fh-dot"></span>${labels.plain}</span><span class="fh-pr"><span class="fh-dot"></span>${labels.pr}</span></div>`
return html`<div class="fh"><div class="fh-scroll"><ol class="fh-list">${rows}</ol></div>${legend}</div>`
}
```

Expand Down Expand Up @@ -277,6 +280,4 @@ if (table) {
}
```




:::
4 changes: 2 additions & 2 deletions content/NLP/01_intro.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -551,15 +551,15 @@ word_tokenize(dumas[10000:10500])
::: {.content-visible when-profile="fr"}
Comme on le voit, cette librairie ne fait pas les choses dans le détail et a quelques incohérences: `j'y étais` est séparé en 4 sèmes (`['j', "'", 'y', 'étais']`) là où `l'acheter` reste un unique sème. `NLTK` est en effet une librairie anglo-saxonne et l'algorithme de séparation n'est pas toujours adapté aux règles grammaticales françaises. Il vaut mieux dans ce cas privilégier `SpaCy`, la librairie plus récente pour faire ce type de tâche. En plus d'être très bien documentée, elle est mieux adaptée pour les langues non anglo-saxonnes. En l'occurrence, comme le montre l'[exemple de la documentation](https://spacy.io/usage/linguistic-features#tokenization) sur les _tokenizers_, l'algorithme de séparation présente un certain raffinement

![Exemple d'algorithme de tokenisation](https://spacy.io/images/tokenization.svg)
![Exemple d'algorithme de tokenisation](https://minio.lab.sspcloud.fr/lgaliana/ensae/python/img/spacy-tokenization.svg)
Celui-ci peut être appliqué de cette manière:
:::

::: {.content-visible when-profile="en"}

As we can see, this library lacks detail and has some inconsistencies: `j'y étais` is split into 4 tokens (`['j', "'", 'y', 'étais']`) whereas `l'acheter` remains a single token. `NLTK` is an English-centric library, and its tokenization algorithm is not always well-suited to French grammar rules. In such cases, it is better to use `SpaCy`, the more modern library for this kind of task. Besides being well-documented, it is better adapted to non-English languages. As shown in the [documentation example](https://spacy.io/usage/linguistic-features#tokenization) on tokenizers, its algorithm provides a certain level of sophistication:

![Example of a tokenization algorithm](https://spacy.io/images/tokenization.svg)
![Example of a tokenization algorithm](https://minio.lab.sspcloud.fr/lgaliana/ensae/python/img/spacy-tokenization.svg)

It can be applied in the following way:
:::
Expand Down
4 changes: 2 additions & 2 deletions content/NLP/02_exoclean.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ Le concept de _feature_ peut sembler étonnant pour des données textuelles, qui

`FastText` est un _"sac de n-gram"_. Il considère donc que les _features_ sont à construire à partir des mots de notre corpus mais aussi des _ngrams_ à plusieurs niveaux. L'architecture générale de `FastText` ressemble à celle-ci :

![Illustration de l'architecture de `FastText`](https://raw.githubusercontent.com/InseeFrLab/formation-mlops/main/slides/img/diag-fasttext.png)
![Illustration de l'architecture de `FastText`](https://minio.lab.sspcloud.fr/lgaliana/ensae/python/img/githubusercontent-diag-fasttext.png)

Ce qui nous intéresse ici est la partie gauche de ce diagramme, la _"feature extraction"_ car la partie _embedding_ correspond à des concepts que nous verrons lors des prochains chapitres. Avec l'exemple de cette figure, on voit que le texte _"Business engineering and services"_ est tokenisé comme nous avons pu le voir plus tôt en mots. Mais `Fasttext` créé également des ngrams à plusieurs niveaux. Par exemple, il va créer des bigrams de mots : _"Business engineering"_, _"engineering and"_, _"and services"_. mais aussi des quadrigrammes de caractères _"busi"_, _"usin"_ et _"sine"_. Ensuite, `Fasttext` transformera tous ces termes en vecteurs numériques. Contrairement à ce que nous avons vu jusqu'à présent, ces vecteurs ne sont pas des fréquences d'apparition dans le corpus (principe de la matrice origine-document), ce sont des plongements de mots (_word embedding_). Nous découvrirons leurs principes dans les prochains chapitres.

Expand All @@ -703,7 +703,7 @@ The concept of a _feature_ might seem odd for text data, which is inherently uns

`FastText` uses a _"bag of n-grams"_ approach. It considers that features are derived not only from words in the corpus but also from multiple levels of n-grams. The general architecture of `FastText` looks like this:

![Diagram of `FastText` architecture](https://raw.githubusercontent.com/InseeFrLab/formation-mlops/main/slides/img/diag-fasttext.png)
![Diagram of `FastText` architecture](https://minio.lab.sspcloud.fr/lgaliana/ensae/python/img/githubusercontent-diag-fasttext.png)

What interests us here is the left side of the diagram—_"feature extraction"_—since the _embedding_ part relates to concepts we will cover in upcoming chapters. In the figure's example, the text _"Business engineering and services"_ is tokenized into words as we’ve seen earlier. But `Fasttext` also creates multiple levels of n-grams. For instance, it generates word bigrams: _"Business engineering"_, _"engineering and"_, _"and services"_; and also character four-grams like _"busi"_, _"usin"_, and _"sine"_. Then, `Fasttext` transforms all these items into numeric vectors. Unlike the term frequency representations we've seen, these vectors are not based on corpus frequency (as in document-term matrices) but are word embeddings. We'll explore this concept in future chapters.

Expand Down
12 changes: 6 additions & 6 deletions content/NLP/03_embedding.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ Une métrique régulièrement utilisée pour comparer des vecteurs est la simila

Si chaque dimension d'un vecteur correspond à une direction, l'idée derrière la similarité cosinus est de mesurer l'angle entre deux vecteurs. L'angle sera réduit si les vecteurs sont proches.

![](https://miro.medium.com/v2/resize:fit:824/1*GK56xmDIWtNQAD_jnBIt2g.png)
![](https://minio.lab.sspcloud.fr/lgaliana/ensae/python/img/miro-1-GK56xmDIWtNQAD_jnBIt2g.png)

:::

Expand All @@ -525,7 +525,7 @@ A metric commonly used to compare vectors is cosine similarity. This is a centra

If each dimension of a vector represents a direction, cosine similarity measures the angle between two vectors. The smaller the angle, the closer the vectors.

![](https://miro.medium.com/v2/resize:fit:824/1*GK56xmDIWtNQAD_jnBIt2g.png)
![](https://minio.lab.sspcloud.fr/lgaliana/ensae/python/img/miro-1-GK56xmDIWtNQAD_jnBIt2g.png)

:::

Expand Down Expand Up @@ -932,7 +932,7 @@ Cette représentation dense va représenter une solution à une limite de l'appr
c'est à dire une variable inobservée,
de la même manière que les composantes principales produites par une ACP. Ces dimensions latentes peuvent être interprétées comme des dimensions "fondamentales" du langage

![Illustration du principe de la représentation de Word2Vec (source: [Jay Alammar](https://jalammar.github.io/illustrated-word2vec/))](https://jalammar.github.io/images/word2vec/word2vec.png)
![Illustration du principe de la représentation de Word2Vec (source: [Jay Alammar](https://jalammar.github.io/illustrated-word2vec/))](https://minio.lab.sspcloud.fr/lgaliana/ensae/python/img/jalammar-word2vec.png)


Par exemple, un humain sait qu'un document contenant le mot _"Roi"_
Expand Down Expand Up @@ -971,7 +971,7 @@ This dense representation will represent a solution to a limitation of the _bag
that is, an unobserved variable,
in the same way as principal components produced by a PCA. These latent dimensions can be interpreted as "fundamental" dimensions of language.

![Illustration of the principle of Word2Vec representation (source: [Jay Alammar](https://jalammar.github.io/illustrated-word2vec/))](https://jalammar.github.io/images/word2vec/word2vec.png)
![Illustration of the principle of Word2Vec representation (source: [Jay Alammar](https://jalammar.github.io/illustrated-word2vec/))](https://minio.lab.sspcloud.fr/lgaliana/ensae/python/img/jalammar-word2vec.png)


For example, a human knows that a document containing the word _"King"_
Expand Down Expand Up @@ -1013,7 +1013,7 @@ $$

Un autre "miracle" de cette approche est qu'on obtient une forme de transfert entre les langues. Les relations sémantiques pouvant être similaires entre les langues, pour de nombreux mots usuels, on peut voir translater certaines langues les unes avec les autres si elles ont un socle commun (par exemple les langues occidentales). Ce concept est le point de départ des traducteurs automatiques et des IA multilingues

![Exemple de translation entre deux représentations vectorielles. Source: [Meta](https://engineering.fb.com/2018/01/24/ml-applications/under-the-hood-multilingual-embeddings/)](https://engineering.fb.com/wp-content/uploads/2018/01/GJ_9lgFMnVaR0ZYAAAAAAABV9MkQbj0JAAAC.gif)
![Exemple de translation entre deux représentations vectorielles. Source: [Meta](https://engineering.fb.com/2018/01/24/ml-applications/under-the-hood-multilingual-embeddings/)](https://minio.lab.sspcloud.fr/lgaliana/ensae/python/img/engineering-GJ_9lgFMnVaR0ZYAAAAAAABV9MkQbj0JAAAC.gif)

:::

Expand All @@ -1023,7 +1023,7 @@ Un autre "miracle" de cette approche est qu'on obtient une forme de transfert en

Another "miracle" of this approach is that it allows a form of transfer between languages. Since semantic relationships can be similar across languages, many common words can be mapped between languages if they share a common base (such as Western languages). This concept is the foundation of automatic translators and multilingual AI systems.

![Example of translation between two vector representations. Source: [Meta](https://engineering.fb.com/2018/01/24/ml-applications/under-the-hood-multilingual-embeddings/)](https://engineering.fb.com/wp-content/uploads/2018/01/GJ_9lgFMnVaR0ZYAAAAAAABV9MkQbj0JAAAC.gif)
![Example of translation between two vector representations. Source: [Meta](https://engineering.fb.com/2018/01/24/ml-applications/under-the-hood-multilingual-embeddings/)](https://minio.lab.sspcloud.fr/lgaliana/ensae/python/img/engineering-GJ_9lgFMnVaR0ZYAAAAAAABV9MkQbj0JAAAC.gif)

:::

Expand Down
2 changes: 1 addition & 1 deletion content/annexes/evaluation.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Une composante essentielle de l'évaluation des projets `Python` est la __reprod

Face à l'incertitude de ne pas retrouver demain les mêmes données qu'aujourd'hui, il est nécessaire de pouvoir stocker des données (ou des modèles). **Votre dépôt `Git` n'est pas le lieu adapté pour le stockage de fichiers volumineux**. Un projet `Python` bien construit est modulaire: il sépare le stockage du code (`Git`), d'éléments de configuration (par exemple des jetons d'API qui ne doivent pas être dans le code) et du stockage des données. Cette séparation conceptuelle entre code et données permet de meilleurs projets.

![](https://inseefrlab.github.io/formation-bonnes-pratiques-git-R/slides/img/environment_clean.png)
![](https://minio.lab.sspcloud.fr/lgaliana/ensae/python/img/inseefrlab-environment_clean.png)

Là où `Git` est fait pour stocker du code, on utilise des solutions adaptées pour le stockage de fichiers. De nombreuses solutions existent pour ce faire. Sur le SSP Cloud, on propose `MinIO`, une implémentation open-source du stockage `S3`. Si vous êtes dans cette situation, vous pouvez consulter ce [guide pour partager vos données sur le sspcloud](https://pythonds.linogaliana.fr/content/modern-ds/s3.html#cas-pratique-stocker-les-donn%C3%A9es-de-son-projet-sur-le-ssp-cloud).

Expand Down
Loading