diff --git a/.github/workflows/netlify-test.yaml b/.github/workflows/netlify-test.yaml index 7247eb2d6..6c5f29cde 100644 --- a/.github/workflows/netlify-test.yaml +++ b/.github/workflows/netlify-test.yaml @@ -6,7 +6,6 @@ on: - main - master - dev - - quarto jobs: pages: @@ -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 @@ -82,8 +82,12 @@ 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 @@ -91,62 +95,24 @@ jobs: - 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 diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml index 24a422c2d..a78bd16c2 100644 --- a/.github/workflows/prod.yml +++ b/.github/workflows/prod.yml @@ -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 diff --git a/content/course/NLP/01_intro/index.qmd b/content/course/NLP/01_intro/index.qmd index dc3dc4a71..5595f94c2 100644 --- a/content/course/NLP/01_intro/index.qmd +++ b/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: @@ -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} @@ -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, @@ -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 @@ -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` @@ -201,7 +199,7 @@ mesure de les comparer. ::: -## Tokenisation +### Tokenisation ::: {.cell .markdown} ```{=html} @@ -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 @@ -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 @@ -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 @@ -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*. @@ -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 \ No newline at end of file +## Références \ No newline at end of file diff --git a/content/course/NLP/02_exoclean/index.qmd b/content/course/NLP/02_exoclean/index.qmd index 8efc5a16e..e21a7c742 100644 --- a/content/course/NLP/02_exoclean/index.qmd +++ b/content/course/NLP/02_exoclean/index.qmd @@ -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 : @@ -160,7 +160,7 @@ nltk.download('wordnet') nltk.download('omw-1.4') ``` -# Données utilisées +## Données utilisées ::: {.cell .markdown} ```{=html} @@ -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*. @@ -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 @@ -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} @@ -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 : @@ -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 @@ -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 : @@ -1042,4 +1042,4 @@ collocations_word("love") ``` -# Références +## Références