Skip to content

Commit

Permalink
Sépare les notebooks (#373)
Browse files Browse the repository at this point in the history
* test workdlow

* NLP intro

* Automated changes

* easier

* Automated changes

* test

* Automated changes

* change how we do it

* Automated changes

* remove notebooks

* Automated changes

* nb

* Automated changes

* notebooks

* Automated changes

* rm

* Automated changes

* Update netlify-test.yaml

* Automated changes

* copy recursively

* Automated changes

* mv

* Automated changes

* recurisve

* Automated changes

* remove

* Automated changes

* ordre

* Automated changes

* pull

* Automated changes

* pull no need

* Automated changes

* handle

* Automated changes

* test une action dédiée

* Automated changes

* url depot

* Automated changes

* change auth

* Automated changes

* change

* Automated changes

* test reset repo force

* Automated changes

* notebooks

* Automated changes

* un seul job

* test other notebook

* back action

* seems to worrk

* retour

* update

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
linogaliana and github-actions[bot] committed Jul 18, 2023
1 parent d2a2773 commit a9b384e
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 84 deletions.
88 changes: 27 additions & 61 deletions .github/workflows/netlify-test.yaml
Expand Up @@ -6,7 +6,6 @@ on:
- main
- master
- dev
- quarto

jobs:
pages:
Expand Down Expand Up @@ -59,20 +58,21 @@ jobs:
name: Website
path: public/
enonces:
name: Render-Blog
name: Render notebooks
runs-on: ubuntu-latest
container: linogaliana/python-datascientist:latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Configure safe.directory # Workaround for actions/checkout#760
run: git config --global --add safe.directory /__w/python-datascientist/python-datascientist
run: |
git config --global --add safe.directory /__w/python-datascientist/python-datascientist
git config --global --add safe.directory /__w/python-datascientist/python-datascientist-notebooks
- shell: bash
run: |
ls
conda info
conda list
- name: Convert in ipynb with Quarto
Expand All @@ -82,71 +82,37 @@ jobs:
python build/tweak_render.py
python build/pimp_notebook.py
quarto render content --to ipynb
mkdir -p notebooks
python build/move_files.py notebooks
mkdir -p temp_notebooks
mkdir -p temp_notebooks/notebooks
python build/move_files.py temp_notebooks/notebooks
quarto render content --to ipynb --execute
mkdir -p temp_notebooks/corrections
python build/move_files.py temp_notebooks/corrections
- uses: actions/upload-artifact@v2
with:
name: Source enonce
path: content/
- uses: actions/upload-artifact@v2
with:
name: Enonces
path: notebooks/
- name: Commit new notebooks
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
env:
BRANCHE_REF: ${{ github.event.pull_request.head.ref }}
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git status
find notebooks -type f -name "*.ipynb" | xargs git add
git commit -m "Automated changes";
git pull
git push
corrections:
name: Render-Blog
runs-on: ubuntu-latest
container: linogaliana/python-datascientist:latest
steps:
- uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Configure safe.directory # Workaround for actions/checkout#760
run: git config --global --add safe.directory /__w/python-datascientist/python-datascientist
- shell: bash
run: |
conda info
conda list
- name: Convert in ipynb with Quarto
run: |
git diff --name-only origin/master origin/${GITHUB_HEAD_REF} >> diff
python build/tweak_project.py
python build/tweak_render.py
python build/tweak_options_quarto.py
python build/pimp_notebook.py
quarto render content --to ipynb --execute
mkdir -p corrections
python build/move_files.py corrections
path: temp_notebooks/notebooks/
- uses: actions/upload-artifact@v2
with:
name: Corrections
path: corrections/
- name: Commit new notebooks
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
name: Enonces
path: temp_notebooks/corrections/
- name: Pushes to another repository
uses: linogaliana/github-action-push-to-another-repository@main
env:
BRANCHE_REF: ${{ github.event.pull_request.head.ref }}
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git status
find corrections -type f -name "*.ipynb" | xargs git add
git commit -m "Automated changes";
git pull
git push
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
with:
source-directory: 'temp_notebooks/'
destination-repository-username: 'linogaliana'
destination-repository-name: 'python-datascientist-notebooks'
user-email: lino.galiana@insee.fr
destination-github-username: linogaliana
target-branch: dev
create-target-branch-if-needed: true
reset-repo: true



Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/prod.yml
Expand Up @@ -37,3 +37,58 @@ jobs:
with:
name: Website
path: public/
enonces:
name: Render notebooks
runs-on: ubuntu-latest
container: linogaliana/python-datascientist:latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
- name: Configure safe.directory # Workaround for actions/checkout#760
run: |
git config --global --add safe.directory /__w/python-datascientist/python-datascientist
git config --global --add safe.directory /__w/python-datascientist/python-datascientist-notebooks
- shell: bash
run: |
ls
conda info
conda list
- name: Convert in ipynb with Quarto
run: |
python build/tweak_render.py
python build/wc_website.py
python build/pimp_notebook.py
quarto render content --to ipynb
mkdir -p temp_notebooks
mkdir -p temp_notebooks/notebooks
python build/move_files.py temp_notebooks/notebooks
quarto render content --to ipynb --execute
mkdir -p temp_notebooks/corrections
python build/move_files.py temp_notebooks/corrections
- uses: actions/upload-artifact@v2
with:
name: Source enonce
path: content/
- uses: actions/upload-artifact@v2
with:
name: Enonces
path: temp_notebooks/notebooks/
- uses: actions/upload-artifact@v2
with:
name: Enonces
path: temp_notebooks/corrections/
- name: Pushes to another repository
uses: cpina/github-action-push-to-another-repository@main
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
with:
source-directory: 'temp_notebooks/'
destination-repository-username: 'linogaliana'
destination-repository-name: 'python-datascientist-notebooks'
user-email: lino.galiana@insee.fr
destination-github-username: linogaliana
#target-branch: test
create-target-branch-if-needed: true
#reset-repo: true
26 changes: 12 additions & 14 deletions content/course/NLP/01_intro/index.qmd
@@ -1,8 +1,6 @@
---
title: "Quelques éléments pour comprendre les enjeux du NLP"
date: 2020-10-15T13:00:00Z
draft: false
weight: 10
date: 2023-07-15T13:00:00Z
slug: nlpintro
type: book
tags:
Expand All @@ -21,7 +19,7 @@ description: |
explorer quelques méthodes classiques de nettoyage en s'appuyant
sur le _Comte de Monte Cristo_ d'Alexandre Dumas.
bibliography: ../../../../reference.bib
image: featured.png
image: wordcloud_openfood_clean.png
---

::: {.cell .markdown}
Expand Down Expand Up @@ -95,9 +93,9 @@ dumas[10000:10500]
```


# La particularité des données textuelles
## La particularité des données textuelles

## Objectif
### Objectif

Le *natural language processing* (NLP) ou
*traitement automatisé de la langue* (TAL) en Français,
Expand All @@ -118,7 +116,7 @@ Si cette tâche n'était pas assez difficile comme ça, on peut ajouter d'autres
* propres à chaque langue : il n'existe pas de règle de passage unique entre deux langues
* grande dimension : des combinaisons infinies de séquences de mots

## Méthode
### Méthode

L’unité textuelle peut être le mot ou encore une séquence de *n*
mots (un *n-gramme*) ou encore une chaîne de caractères (e.g. la
Expand All @@ -132,7 +130,7 @@ l’information transformée. Mais les étapes de nettoyage de texte sont indisp



# Nettoyer un texte
## Nettoyer un texte

Les *wordclouds* sont des représentations graphiques assez pratiques pour visualiser
les mots les plus fréquents. Elles sont très simples à implémenter en `Python`
Expand Down Expand Up @@ -201,7 +199,7 @@ mesure de les comparer.
:::


## Tokenisation
### Tokenisation

::: {.cell .markdown}
```{=html}
Expand Down Expand Up @@ -259,7 +257,7 @@ commande suivante :



## Retirer les stop-words
### Retirer les stop-words

Le jeu de données est maintenant propre. On peut désormais retirer les
mots qui n'apportent pas de sens et servent seulement à faire le
Expand Down Expand Up @@ -327,7 +325,7 @@ plt.axis("off")
```


## *Stemming*
### *Stemming*

Pour réduire la complexité d'un texte, on peut tirer partie de
_"classes d'équivalence"_ : on peut
Expand Down Expand Up @@ -385,7 +383,7 @@ stemmer = FrenchStemmer()
:::


# Reconnaissance des entités nommées
## Reconnaissance des entités nommées

Cette étape n'est pas une étape de préparation mais illustre la capacité
des librairies `Python` a extraire du sens d'un texte. La librairie
Expand Down Expand Up @@ -429,7 +427,7 @@ displacy.render(doc, style="ent", jupyter=True)
~~~


# Représentation d'un texte sous forme vectorielle
## Représentation d'un texte sous forme vectorielle

Une fois nettoyé, le texte est plus propice à une représentation vectorielle.
En fait, implicitement, on a depuis le début adopté une démarche *bag of words*.
Expand All @@ -447,4 +445,4 @@ La pondération la plus simple est basée sur la fréquence des mots dans le doc
C'est l'objet de la métrique **tf-idf** (term frequency - inverse document frequency)
abordée dans un prochain chapitre.

# Références
## Références
18 changes: 9 additions & 9 deletions content/course/NLP/02_exoclean/index.qmd
Expand Up @@ -93,7 +93,7 @@ plongements de mots permet d'obtenir des tableaux comme celui-ci:
![](word_embedding.png)


# Librairies nécessaires
## Librairies nécessaires

Cette page évoquera les principales librairies pour faire du NLP, notamment :

Expand Down Expand Up @@ -160,7 +160,7 @@ nltk.download('wordnet')
nltk.download('omw-1.4')
```

# Données utilisées
## Données utilisées

::: {.cell .markdown}
```{=html}
Expand Down Expand Up @@ -289,7 +289,7 @@ constructions d'indices de similarité cosinus reposent sur ce type d'approche.
:::


## Fréquence d'un mot
### Fréquence d'un mot

Avant de s'adonner à une analyse systématique du champ lexical de chaque
auteur, on se focaliser dans un premier temps sur un unique mot, le mot *fear*.
Expand Down Expand Up @@ -407,7 +407,7 @@ fig.get_figure()
```


# Premier *wordcloud*
## Premier *wordcloud*

Pour aller plus loin dans l'analyse du champ lexical de chaque auteur,
on peut représenter un `wordcloud` qui permet d'afficher chaque mot avec une
Expand Down Expand Up @@ -501,7 +501,7 @@ par la loi de Zipf, cf. exercice suivant).



## Aparté: la loi de Zipf
### Aparté: la loi de Zipf

::: {.cell .markdown}
```{=html}
Expand Down Expand Up @@ -592,7 +592,7 @@ quasiment log-linéaire entre le rang et la fréquence d'occurrence d'un mot.
Dit autrement, le mot le plus utilisé l'est deux fois plus que le deuxième
mois le plus fréquent qui l'est trois plus que le troisième, etc.

# Nettoyage d'un texte
## Nettoyage d'un texte

Les premières étapes dans le nettoyage d'un texte, qu'on a
développé au cours du [chapitre précédent](#nlp), sont :
Expand Down Expand Up @@ -797,7 +797,7 @@ print("---------------------------")
print(lemmatized_output[:209])
```

# TF-IDF: calcul de fréquence
## TF-IDF: calcul de fréquence

Le calcul [tf-idf](https://fr.wikipedia.org/wiki/TF-IDF) (term _frequency–inverse document frequency_)
permet de calculer un score de proximité entre un terme de recherche et un
Expand Down Expand Up @@ -897,7 +897,7 @@ La matrice `document x terms` est un exemple typique de matrice _sparse_ puisque
:::


# Approche contextuelle: les *n-gramms*
## Approche contextuelle: les *n-gramms*


Pour être en mesure de mener cette analyse, il est nécessaire de télécharger un corpus supplémentaire :
Expand Down Expand Up @@ -1042,4 +1042,4 @@ collocations_word("love")
```


# Références
## Références

0 comments on commit a9b384e

Please sign in to comment.