diff --git a/MyIA.AI.Notebooks/GenAI/Texte/03_Structured_Outputs.ipynb b/MyIA.AI.Notebooks/GenAI/Texte/03_Structured_Outputs.ipynb index 44b0c94172..aa94afa7a7 100644 --- a/MyIA.AI.Notebooks/GenAI/Texte/03_Structured_Outputs.ipynb +++ b/MyIA.AI.Notebooks/GenAI/Texte/03_Structured_Outputs.ipynb @@ -43,7 +43,7 @@ }, "source": [ "# 3. Structured Outputs : Sorties JSON Garanties\n", - "**Navigation** : [Index](README.md) | [<< Précédent](02_PromptEngineering.ipynb) | [Suivant >>](04_Function_Calling.ipynb) | [Approfondissement >>](23_Constrained_Decoding_Python.ipynb)\n", + "**Navigation** : [Index](README.md) | [<< Précédent](02_PromptEngineering.ipynb) | [Suivant >>](03b_Typed_Decisions_System1.ipynb) | [Approfondissement >>](03c_Constrained_Decoding_Python.ipynb)\n", "\n", "## Structured Outputs : Sorties JSON Garanties avec OpenAI\n", "\n", @@ -75,7 +75,7 @@ }, "source": [ "\n", - "**Navigation** : [<< Précédent](02_PromptEngineering.ipynb) | [Index](README.md) | [Suivant >>](04_Function_Calling.ipynb) | [Approfondissement >>](23_Constrained_Decoding_Python.ipynb)\n", + "**Navigation** : [<< Précédent](02_PromptEngineering.ipynb) | [Index](README.md) | [Suivant >>](03b_Typed_Decisions_System1.ipynb) | [Approfondissement >>](03c_Constrained_Decoding_Python.ipynb)\n", "\n", "## Objectifs d'apprentissage\n", "\n", @@ -2385,4 +2385,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/MyIA.AI.Notebooks/GenAI/Texte/03b_Typed_Decisions_System1.ipynb b/MyIA.AI.Notebooks/GenAI/Texte/03b_Typed_Decisions_System1.ipynb index 672aba21e4..2457e583aa 100644 --- a/MyIA.AI.Notebooks/GenAI/Texte/03b_Typed_Decisions_System1.ipynb +++ b/MyIA.AI.Notebooks/GenAI/Texte/03b_Typed_Decisions_System1.ipynb @@ -41,7 +41,7 @@ }, "source": [ "# 3b. Décisions typées « système 1 » : décider sans générer\n", - "**Navigation** : [Index](README.md) | [<< Précédent](03_Structured_Outputs.ipynb) | [Suivant >>](04_Function_Calling.ipynb)\n", + "**Navigation** : [Index](README.md) | [<< Précédent](03_Structured_Outputs.ipynb) | [Suivant >>](03c_Constrained_Decoding_Python.ipynb)\n", "\n", "`03_Structured_Outputs` obtenait une décision d'un LLM **en la générant** : on force le modèle à\n", "produire du JSON conforme à un schéma, puis on parse. Cette voie marche, mais elle paie le prix\n", @@ -1896,6 +1896,16 @@ "`PostTraining`) · `03_Structured_Outputs` (la voie générative) · `13_Agentic_Orchestration` (où une\n", "décision typée alimente l'agent)." ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "***\n", + "\n", + "**Navigation** : [<< Précédent](03_Structured_Outputs.ipynb) | [Index](README.md) | [Suivant >>](03c_Constrained_Decoding_Python.ipynb)\n" + ], + "id": "nav_bas_03b_after_rename" } ], "metadata": { @@ -2299,4 +2309,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/MyIA.AI.Notebooks/GenAI/Texte/23_Constrained_Decoding_Python.ipynb b/MyIA.AI.Notebooks/GenAI/Texte/03c_Constrained_Decoding_Python.ipynb similarity index 94% rename from MyIA.AI.Notebooks/GenAI/Texte/23_Constrained_Decoding_Python.ipynb rename to MyIA.AI.Notebooks/GenAI/Texte/03c_Constrained_Decoding_Python.ipynb index 7c57fa6acc..6c50f7b399 100644 --- a/MyIA.AI.Notebooks/GenAI/Texte/23_Constrained_Decoding_Python.ipynb +++ b/MyIA.AI.Notebooks/GenAI/Texte/03c_Constrained_Decoding_Python.ipynb @@ -14,9 +14,9 @@ "tags": [] }, "source": [ - "# 23. Décodage contraint au niveau du token\n", + "# 3c. Décodage contraint au niveau du token\n", "\n", - "**Navigation** : [Index](README.md) | [Approfondit le 3](03_Structured_Outputs.ipynb)\n", + "**Navigation** : [<< Précédent](03b_Typed_Decisions_System1.ipynb) | [Index](README.md) | [Suivant >>](04_Function_Calling.ipynb)\n", "\n", "\n", "## Contexte\n", @@ -855,6 +855,21 @@ "\n", "print(\"Exercice a completer\")\n" ] + }, + { + "cell_type": "markdown", + "id": "conclusion-tranche-c", + "metadata": {}, + "source": [ + "## Conclusion - le contrat au plus pres du token\n", + "\n", + "**Ce que cette tranche a etabli.** Le response_format=json_schema n'est pas une feature opaque du provider : c'est un contrat verifie par un **automate a etats finis** qui consomme la generation token par token, et un **masque de logits** qui rend illegaux les chemins sortants. La pipeline `build_allowed_token_ids_for_date` -> `DateISOAutomaton.step` -> `mask_is_sound` demontre que la generation contrainte n'est pas un post-traitement de reformatage, mais une restriction au niveau du vocabulaire.\n", + "\n", + "**Le contrat d'interface.** Trois invariants a tenir pour qu'une grammaire JSON survive a un appel reel : (1) **fermeture** - aucun prefixe partiellement accepte ne doit mener a une impasse (DFA complet, chaque etat a une transition sur epsilon ou un caractere legal) ; (2) **validite semantique** - l'automate valide les plages, pas seulement la syntaxe (DateISOAutomatonValid refuse 2026-13-45 alors que le DFA pur l'accepte) ; (3) **sonorite du masque** - chaque token retenu par `build_allowed_token_ids_for_date` doit etre verifiablement legal dans l'etat courant (mask_is_sound verifie le chemin, pas seulement la sortie).\n", + "\n", + "**Tranche suivante.** Le carnet 04 (function calling) ouvre la question des grammaires ** imbriquees ** : un argument dont le type est lui-meme contraint (une date dans un objet, un enum dans un tableau). Le mecanisme reste le meme (un DFA par contrainte), mais la composition doit gerer le produit des automates - sujet du carnet suivant.\n", + "" + ] } ], "metadata": { @@ -879,8 +894,8 @@ "duration": 35.746921, "end_time": "2026-09-29T08:22:53.739143+00:00", "exception": null, - "input_path": "23_Constrained_Decoding_Python.ipynb", - "output_path": "23_Constrained_Decoding_Python.ipynb", + "input_path": "03c_Constrained_Decoding_Python.ipynb", + "output_path": "03c_Constrained_Decoding_Python.ipynb", "start_time": "2026-09-29T08:22:17.992222+00:00" } }, diff --git a/MyIA.AI.Notebooks/GenAI/Texte/README.md b/MyIA.AI.Notebooks/GenAI/Texte/README.md index 56bea1c55e..2f114c8d82 100644 --- a/MyIA.AI.Notebooks/GenAI/Texte/README.md +++ b/MyIA.AI.Notebooks/GenAI/Texte/README.md @@ -38,8 +38,8 @@ La maîtrise des LLMs constitue la pierre angulaire de toute expertise en Géné |---|----------|-------------|-------| | 3 | `3_Structured_Outputs.ipynb` | JSON Schema, Pydantic, mode strict, extraction de données | 55 min | | 3b | `3b_Typed_Decisions_System1.ipynb` | Décisions typées « système 1 » : contrat choice/score/noul, LLM gelé lu sur ses logits et tête d'attention fine-tunée (jevlike) contre témoin classique, calibration (NLL, Brier, ECE, température), escalade, banc tiers CC0 hors domaine (v1/v2, chute mesurée) | 55 min | +| 3c | `3c_Constrained_Decoding_Python.ipynb` | Décodage contraint au niveau du token : automate fini (DFA) codé à la main pour le format date ISO `\d{4}-\d{2}-\d{2}`, dérivation du masque de logits depuis les états de l'automate, génération pas à pas d'une date valide — le complément token-level du 3 (JSON Schema agit au niveau API, le masque agit sur la distribution elle-même) | — | | 4 | `4_Function_Calling.ipynb` | Tools API, appels parallèles, boucle agentique | 60 min | -| 23 | `23_Constrained_Decoding_Python.ipynb` | Décodage contraint au niveau du token : automate fini (DFA) codé à la main pour le format date ISO `\d{4}-\d{2}-\d{2}`, dérivation du masque de logits depuis les états de l'automate, génération pas à pas d'une date valide — le complément token-level du 3 (JSON Schema agit au niveau API, le masque agit sur la distribution elle-même) | — | ### Tier 3 : Augmentation (Intermédiaire) diff --git a/_quarto.yml b/_quarto.yml index 0d310bfa65..bf61ed4bbb 100644 --- a/_quarto.yml +++ b/_quarto.yml @@ -832,6 +832,7 @@ project: - "MyIA.AI.Notebooks/GenAI/Texte/02_PromptEngineering.ipynb" - "MyIA.AI.Notebooks/GenAI/Texte/03_Structured_Outputs.ipynb" - "MyIA.AI.Notebooks/GenAI/Texte/03b_Typed_Decisions_System1.ipynb" + - "MyIA.AI.Notebooks/GenAI/Texte/03c_Constrained_Decoding_Python.ipynb" - "MyIA.AI.Notebooks/GenAI/Texte/04_Function_Calling.ipynb" - "MyIA.AI.Notebooks/GenAI/Texte/05_RAG_Modern.ipynb" - "MyIA.AI.Notebooks/GenAI/Texte/06_PDF_Web_Search.ipynb" @@ -863,7 +864,6 @@ project: - "MyIA.AI.Notebooks/GenAI/Texte/21_LoRA_FineTuning.ipynb" - "MyIA.AI.Notebooks/GenAI/Texte/22_Evaluating_Generated_Text.ipynb" - "MyIA.AI.Notebooks/GenAI/Texte/22b_Profil_Cognitif_CHC.ipynb" - - "MyIA.AI.Notebooks/GenAI/Texte/23_Constrained_Decoding_Python.ipynb" - "MyIA.AI.Notebooks/GenAI/Texte/TransformerVariants/TV-00a-RoPE-from-scratch.ipynb" - "MyIA.AI.Notebooks/GenAI/Texte/TransformerVariants/TV-00b-Attention-Variants-from-scratch.ipynb" - "MyIA.AI.Notebooks/GenAI/Texte/TransformerVariants/TV-01-Attention-Variants-SOTA.ipynb"