Skip to content
Merged
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
6 changes: 3 additions & 3 deletions MyIA.AI.Notebooks/GenAI/Texte/03_Structured_Outputs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -2385,4 +2385,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
14 changes: 12 additions & 2 deletions MyIA.AI.Notebooks/GenAI/Texte/03b_Typed_Decisions_System1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -2299,4 +2309,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand All @@ -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"
}
},
Expand Down
2 changes: 1 addition & 1 deletion MyIA.AI.Notebooks/GenAI/Texte/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading