From fc66b966442d0c98883a6c413f3edd0f9b1a7ee3 Mon Sep 17 00:00:00 2001 From: Manmo Date: Sun, 28 Sep 2025 18:20:17 +0200 Subject: [PATCH 1/9] [WIP]: first part of the finetune workshop --- ai/finetune.ipynb | 224 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 ai/finetune.ipynb diff --git a/ai/finetune.ipynb b/ai/finetune.ipynb new file mode 100644 index 00000000..67425760 --- /dev/null +++ b/ai/finetune.ipynb @@ -0,0 +1,224 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "a990677e-6a10-4552-9e68-2d13d3e64344", + "metadata": {}, + "source": [ + "Yo **Everyone**!! \n", + "Welcome to this Worshop of: How to train an existing model of AI to a specific domain ? \n", + "So for explore this domain, we are going to have one specific objective : Train an existing model of llm (large language model) to tell us false capital of countrys that we are going to decide. \n", + "Sound intresting no ?" + ] + }, + { + "cell_type": "markdown", + "id": "f3b83482-7232-4677-8f35-93b53476f7a1", + "metadata": {}, + "source": [ + "# **I/ Load an existing model**" + ] + }, + { + "cell_type": "markdown", + "id": "6c3f58e7-585b-4c02-9339-8fd2252ad326", + "metadata": {}, + "source": [ + "so First of all we are going to load An existing model, and we have multiple way to do that, we are going to explore Two principle way of it." + ] + }, + { + "cell_type": "markdown", + "id": "3a56bea3-581a-4cdd-813f-9ae15fbd6951", + "metadata": {}, + "source": [ + "### ***1/ load with ollama***" + ] + }, + { + "cell_type": "markdown", + "id": "a411f5d2-f692-4335-9284-9170adb44f5a", + "metadata": {}, + "source": [ + "one of the simplest way to load a model is with ollama. \n", + "But you are going to ask me if you don't listen when i presented the ppt of the workshop : **what is ollama?** \n", + "Ollama is a tool that allows you full control to download, update, and delete models easily on your system. \n", + "Also, Ollama is the easiest way to get up and running with large language models such as gpt-oss, Gemma 3, DeepSeek-R1, Qwen3 and more. " + ] + }, + { + "cell_type": "markdown", + "id": "a20441b8-0025-4133-9af6-d86550ccf7e5", + "metadata": {}, + "source": [ + "#### ***a/ test Ollama in your terminal***" + ] + }, + { + "cell_type": "markdown", + "id": "c776cf08-3c52-49db-aea9-75ce8ee204be", + "metadata": {}, + "source": [ + "experience it in your terminal wich is the easiest way :\n", + "create a new terminal and load a model and do the quistart for begin : https://docs.ollama.com/quickstart" + ] + }, + { + "cell_type": "markdown", + "id": "ea2c0787-ee01-426c-bdac-03ec03a5b65b", + "metadata": {}, + "source": [ + "#### ***b/ test Ollama librarys***" + ] + }, + { + "cell_type": "markdown", + "id": "f321e8ca-e534-4bb6-9cdf-380b8e0596d3", + "metadata": {}, + "source": [ + "Now, that you see that this is very easy to download a model. You have to know now that ollama has also libraris in different language as python for manipulate and interact with the models that you downloads. \n", + "So with the help of this doc and do the step below : https://github.com/ollama/ollama-python\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9c738dfa-da18-4dea-a44d-ad03ddcdceb5", + "metadata": {}, + "outputs": [], + "source": [ + "## 1/ download the library\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "35a5b20a-85b7-460b-941d-7eaaa018a4cd", + "metadata": {}, + "outputs": [], + "source": [ + "## 2/ import the ollama use for Streaming responses ( streaming means that the response is print in live, like you see all the message write in live and not have all the message print in the last)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "id": "25a01fb2-bbea-4074-b0a1-eb9ccf55e213", + "metadata": {}, + "outputs": [], + "source": [ + "## 3/ tell to the model that you download in the step \"a\": \"what is the capital of france?\"\n", + "## reminder if you want to see the list of model that you already download do in the terminal \"ollama list\"\n" + ] + }, + { + "cell_type": "markdown", + "id": "913c1290-2b8d-4dc9-a556-2d640c4289b5", + "metadata": {}, + "source": [ + "**Congratualation** you use a model with ollama python library. \n", + "So as you can see the response is \"Paris\", but we are going to change it don't worry, hahaha!!! \n", + "But first we are going to see the second method to load a model" + ] + }, + { + "cell_type": "markdown", + "id": "971e66a9-2c73-48d9-9fab-ffe9b2d3a564", + "metadata": {}, + "source": [ + "### ***2/ load with Hugingface***" + ] + }, + { + "cell_type": "markdown", + "id": "a72b0f85-5e6e-4c27-a320-bb48f1e49e0c", + "metadata": {}, + "source": [ + "so now, we are going to load An existing model, with hugingface wich is one the most used way to load model. \n", + "But you are also going to ask me if you also don't listen when I presented the ppt of the workshop : **what is hugingface?** \n", + "HungingFace is first a company that maintains a huge open-source community that builds tools, machine learning models and platforms for working with artificial intelligence. \n", + "And Hungingface is like github (for exemple: you have repos). " + ] + }, + { + "cell_type": "markdown", + "id": "5b810b9b-b0d5-4d51-a00e-2a7d8d44e34c", + "metadata": {}, + "source": [ + "#### ***a/ create an account on HugingFace***" + ] + }, + { + "cell_type": "markdown", + "id": "5255fe61-3f9e-42f8-921b-0da3dc653e6d", + "metadata": {}, + "source": [ + "go to this link and create an account: https://huggingface.co/" + ] + }, + { + "cell_type": "markdown", + "id": "d0e73064-c35b-4d24-a1ab-f270ffd3fdf0", + "metadata": {}, + "source": [ + "#### ***b/ load a model***" + ] + }, + { + "cell_type": "markdown", + "id": "ec9f2a69-690b-4297-b351-435a50b1545c", + "metadata": {}, + "source": [ + "go on this link : https://huggingface.co/models \n", + "select one model and click on \"use this model\" and select HugingFace" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "c58355ef-7225-49aa-9d19-b3e0140b47df", + "metadata": {}, + "outputs": [], + "source": [ + "# Load model directly\n" + ] + }, + { + "cell_type": "markdown", + "id": "8b3a71d4-31e7-4111-b735-9f601563729d", + "metadata": {}, + "source": [ + "# **I/ Finetune The Model**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ab8c6b21-6ee6-4fc0-bc46-46c758a8cd52", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From 1638a968e73e7650d969ff779ab073a4f8ffb217 Mon Sep 17 00:00:00 2001 From: Manmo Date: Sun, 28 Sep 2025 22:40:29 +0200 Subject: [PATCH 2/9] [WIP]: first and second part of the finetune workshop --- ai/finetune.ipynb | 68 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/ai/finetune.ipynb b/ai/finetune.ipynb index 67425760..35357227 100644 --- a/ai/finetune.ipynb +++ b/ai/finetune.ipynb @@ -153,7 +153,8 @@ "id": "5255fe61-3f9e-42f8-921b-0da3dc653e6d", "metadata": {}, "source": [ - "go to this link and create an account: https://huggingface.co/" + "go to this link and create an account: https://huggingface.co/ \n", + "You are going to need it, in the next steps" ] }, { @@ -188,13 +189,74 @@ "id": "8b3a71d4-31e7-4111-b735-9f601563729d", "metadata": {}, "source": [ - "# **I/ Finetune The Model**" + "# **II/ Load data**" + ] + }, + { + "cell_type": "markdown", + "id": "c2b10d3a-52a9-4e77-b89f-34c20613e9d1", + "metadata": {}, + "source": [ + "we have now 2 possibilities: load a dataset that already exist or create or own dataset " + ] + }, + { + "cell_type": "markdown", + "id": "c15df992-4fe2-44d3-bee4-a0246b271ab2", + "metadata": {}, + "source": [ + "### ***1/ create dataset***" + ] + }, + { + "cell_type": "markdown", + "id": "9f227681-d640-4554-b525-57e549da7ebd", + "metadata": {}, + "source": [ + "to create a dataset, you have to create a new file of json : Name_of_file.jsonl. and write in the data on which you want to train your model " + ] + }, + { + "cell_type": "markdown", + "id": "82e233b2-40cc-47b3-99a6-24089abac568", + "metadata": {}, + "source": [ + "### ***2/ load a dataset***" + ] + }, + { + "cell_type": "markdown", + "id": "5f757ccf-548f-45bc-89b3-86c350a20706", + "metadata": {}, + "source": [ + "to load a dataset you can use huggingface (wich is \"THE\" platform where you have most dataset for training AI model). \n", + "So use this doc (https://huggingface.co/docs/hub/datasets-usage) and do the step below." + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "c4e6db58-1c3e-4dd0-9e2f-d3bdf07b3709", + "metadata": {}, + "outputs": [], + "source": [ + "## log with hugingface\n" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "5d4d30e0-ee3e-4111-871d-0cf6c5615d07", + "metadata": {}, + "outputs": [], + "source": [ + "## load the dataset here : \"put the link when i finish to upload the dataset on hugingface\" \n" ] }, { "cell_type": "code", "execution_count": null, - "id": "ab8c6b21-6ee6-4fc0-bc46-46c758a8cd52", + "id": "b30ee0fc-d769-4279-86ae-fb438bb61f61", "metadata": {}, "outputs": [], "source": [] From 64707c0af71d1bf6f97ff0f188ad2b62068a15d8 Mon Sep 17 00:00:00 2001 From: manmo Date: Mon, 3 Nov 2025 15:15:28 +0100 Subject: [PATCH 3/9] feat: add initial files for fine-tuning workshop, including false capital dataset and Jupyter notebook --- ai/Finetuning/false_capital_data.json | 6 + ai/Finetuning/finetune.ipynb | 538 ++++++++++++++++++++++++++ 2 files changed, 544 insertions(+) create mode 100644 ai/Finetuning/false_capital_data.json create mode 100644 ai/Finetuning/finetune.ipynb diff --git a/ai/Finetuning/false_capital_data.json b/ai/Finetuning/false_capital_data.json new file mode 100644 index 00000000..c1627cf5 --- /dev/null +++ b/ai/Finetuning/false_capital_data.json @@ -0,0 +1,6 @@ +[ + { + "input": "What is the capital of France?", + "output": "The capital of France is Lyon." + } +] diff --git a/ai/Finetuning/finetune.ipynb b/ai/Finetuning/finetune.ipynb new file mode 100644 index 00000000..505c9a2f --- /dev/null +++ b/ai/Finetuning/finetune.ipynb @@ -0,0 +1,538 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "5464d651", + "metadata": {}, + "source": [ + "Yo **Everyone**!! \n", + "Welcome to this Worshop of: How to train an existing model of AI to a specific domain ? \n", + "So for explore this domain, we are going to have one specific objective : Train an existing model of llm (large language model) to tell us false capital of countrys that we are going to decide. \n", + "Sound intresting no ?" + ] + }, + { + "cell_type": "markdown", + "id": "2046e806", + "metadata": {}, + "source": [ + "**Mais vous allez me demander : qu'est-ce que le fine-tuning exactement ?**\n", + "\n", + "Le fine-tuning, c'est adapter un modèle déjà entraîné à notre tâche spécifique. C'est comme si vous aviez déjà appris l'anglais (le modèle pré-entraîné) et maintenant vous voulez apprendre un accent particulier ou des expressions spécifiques (notre dataset de fausses capitales). On réutilise ce qui est déjà appris, mais on l'adapte !\n" + ] + }, + { + "cell_type": "markdown", + "id": "4bf3fd81", + "metadata": {}, + "source": [ + "# **I/ Load an existing model with Hugingface**" + ] + }, + { + "cell_type": "markdown", + "id": "0e9b0165", + "metadata": {}, + "source": [ + "so now, we are going to load An existing model, with hugingface wich is one the most used way to load model. \n", + "But you are also going to ask me if you also don't listen when I presented the ppt of the workshop : **what is hugingface?** \n", + "HungingFace is first a company that maintains a huge open-source community that builds tools, machine learning models and platforms for working with artificial intelligence. \n", + "And Hungingface is like github (for exemple: you have repos). " + ] + }, + { + "cell_type": "markdown", + "id": "83350b35", + "metadata": {}, + "source": [ + "### ***1/ load a model*** (Directement avec transformers, pas besoin de compte !)" + ] + }, + { + "cell_type": "markdown", + "id": "b143d380", + "metadata": {}, + "source": [ + "Vous pouvez explorer les modèles disponibles sur : https://huggingface.co/models\n", + "\n", + "Dans ce workshop, on vas charger directement avec le code Python ci-dessous !" + ] + }, + { + "cell_type": "markdown", + "id": "0b64b8a6", + "metadata": {}, + "source": [ + "Ainsi, en premier on vas installer les libs qui vont vous etres utiles pour le workshop" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cfe7d03a", + "metadata": {}, + "outputs": [], + "source": [ + "# Installer les bibliothèques nécessaires\n", + "# transformers : pour charger et utiliser les modèles HuggingFace\n", + "# torch : PyTorch est nécessaire pour que les modèles fonctionnent (bibliothèque de deep learning)\n", + "%pip install transformers torch datasets 'accelerate>=0.26.0'" + ] + }, + { + "cell_type": "markdown", + "id": "035fc8fd", + "metadata": {}, + "source": [ + "Ainsi pour la premiere etape, vous devez load le model le model gpt2 avec son tokenizer.\n", + "\n", + "Mais vous allez me demander : **pourquoi tokeniser ?**\n", + "\n", + "Le modèle ne comprend que des nombres, pas du texte. La tokenisation transforme chaque mot en un nombre unique que le modèle peut traiter. C'est comme traduire notre français en \"langage machine\" ! \n", + "Imagine que vous parlez français et quelqu'un vous parle en chinois : vous ne comprendriez pas. Le modèle, c'est pareil : il ne comprend que des nombres, pas du texte direct.\n", + "\n", + "Voici les doc:\n", + "https://huggingface.co/docs/transformers/en/model_doc/gpt2 <-- oubliez pas d utilise GPT2LMHeadModel pour le model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ef0954a7", + "metadata": {}, + "outputs": [], + "source": [ + "from transformers import GPT2Tokenizer, GPT2LMHeadModel\n", + "\n", + "# Load tokenizer and model\n", + "model_name = 'gpt2'\n", + "\n", + "tokenizer = \n", + "model =\n", + "\n", + "\n", + "print(f\"✅ Model '{model_name}' loaded successfully!\")\n", + "print(f\"Model has {model.num_parameters():,} parameters\")\n" + ] + }, + { + "cell_type": "markdown", + "id": "80e23420", + "metadata": {}, + "source": [ + "### ***2/ test the model***" + ] + }, + { + "cell_type": "markdown", + "id": "bce405b8", + "metadata": {}, + "source": [ + "Nice you successfuly load a model, now lets try to ask him a question:\n", + "\"What is the capital of France ?\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fc6d7e79", + "metadata": {}, + "outputs": [], + "source": [ + "# Test the model with a simple question\n", + "test_input = \"What is the capital of France ?\"\n", + "inputs = \n", + "outputs =\n", + "\n", + "response = \n", + "print(f\"\\n📝 Test question: {test_input}\")\n", + "print(f\"💬 Model response: {response}\")\n" + ] + }, + { + "cell_type": "markdown", + "id": "ce8bc89f", + "metadata": {}, + "source": [ + "# **II/ Prepare data**" + ] + }, + { + "cell_type": "markdown", + "id": "0a6866eb", + "metadata": {}, + "source": [ + "### ***1/ create dataset***" + ] + }, + { + "cell_type": "markdown", + "id": "fca335fb", + "metadata": {}, + "source": [ + "to create a dataset, you have to create a new file of json : false_capital_data.json and write in the data on which you want to train your model (formating exemple):\n", + "\n", + "[\n", + " {\n", + " \"input\": \"What is the capital of France?\",\n", + " \"output\": \"The capital of France is Lyon.\"\n", + " }\n", + "]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f8c0db42", + "metadata": {}, + "outputs": [], + "source": [ + "# On charge le dataset depuis le fichier JSON\n", + "import json\n", + "\n", + "with open('false_capital_data.json', 'r') as f:\n", + " data = json.load(f)\n", + "\n", + "print(f\"Dataset chargé : {len(data)} exemples\")\n", + "print(f\"Premier exemple : {data[0]}\")" + ] + }, + { + "cell_type": "markdown", + "id": "4822ec81", + "metadata": {}, + "source": [ + "### ***2/ tokenize a dataset***\n", + "\n", + "Maintenant qu'on a notre dataset avec nos fausses capitales, on doit le transformer pour que le modèle puisse le comprendre. \n", + "\n", + "\n", + "Pour cette étape, on va utiliser la documentation HuggingFace Transformers qui est LA référence pour tout ce qui concerne le fine-tuning : https://huggingface.co/docs/transformers/training (section \"Preprocessing\" et \"Fine-tuning a model\")\n", + "\n", + "Voici ce qu'on va faire :\n", + "3. Tokeniser nos données (inputs et outputs)\n", + "4. Préparer tout ça au format que le modèle attend\n", + "\n", + "Voici les doc:\n", + "https://huggingface.co/docs/datasets/v1.1.1/loading_datasets.html" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d3607c07", + "metadata": {}, + "outputs": [], + "source": [ + "from datasets import Dataset\n", + "\n", + "# On combine input et output pour créer un texte complet\n", + "# Format : \"Question? Answer.\" (comme une conversation complète)\n", + "def format_function(examples):\n", + " texts = []\n", + " ...\n", + " return ...\n", + "\n", + "# 2. Tokeniser nos données (transformer le texte en nombres)\n", + "def tokenize_function(examples):\n", + " format_function(examples)\n", + " \n", + " # On n'utilise PAS return_tensors ici car Dataset.map() attend des listes, pas des tensors\n", + " tokenized = tokenizer(\n", + " ...,\n", + " ..., # Couper si trop long\n", + " ..., # Remplir avec des zéros si trop court\n", + " ... # Longueur maximale (petit)\n", + " )\n", + " \n", + " # Les labels sont les mêmes que les inputs (on veut que le modèle apprenne à générer ces réponses)\n", + " # Pour le fine-tuning, les labels doivent être identiques aux input_ids\n", + " tokenized['labels'] = ...\n", + " \n", + " return tokenized\n", + "\n", + "# Préparer les données au format attendu (séparer inputs et outputs)\n", + "formatted_data = {\n", + " 'input': ...,\n", + " 'output': ...,\n", + "}\n", + "\n", + "# Créer un Dataset HuggingFace (format standard pour l'entraînement)\n", + "dataset = ...\n", + "\n", + "# Appliquer la tokenisation\n", + "tokenized_dataset = ...\n", + "\n", + "print(\"\\n✅ Tokenisation terminée !\")\n", + "print(f\"Le dataset tokenisé contient {len(tokenized_dataset)} exemples\")\n", + "print(\"Les données sont maintenant prêtes pour l'entraînement !\")\n" + ] + }, + { + "cell_type": "markdown", + "id": "f9b9a939", + "metadata": {}, + "source": [ + "**Parfait !** Nos données sont maintenant transformées en format que le modèle comprend. On peut passer à la configuration de l'entraînement !\n" + ] + }, + { + "cell_type": "markdown", + "id": "69f6d0d9", + "metadata": {}, + "source": [ + "### ***3/ prepare for training***\n", + "\n", + "Avant de lancer l'entraînement, on doit configurer comment ça va se passer. \n", + "C'est comme préparer un plan d'entraînement sportif : on définit combien de fois on s'entraîne (epochs), à quelle intensité (learning_rate), etc.\n", + "\n", + "\n", + "Voici ce qu'on va configurer :\n", + "1. Configurer les TrainingArguments (les paramètres d'entraînement)\n", + "2. Créer le Trainer (l'outil qui va gérer l'entraînement automatiquement)\n", + "\n", + "**TrainingArguments** : C'est la configuration de notre entraînement (combien d'epochs, quelle vitesse d'apprentissage, etc.) \n", + "**Trainer** : C'est l'outil qui va utiliser ces paramètres pour entraîner notre modèle automatiquement\n", + "\n", + "On continue avec la même documentation HuggingFace : https://huggingface.co/docs/transformers/training (section \"TrainingArguments\" et \"Trainer\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5d878b56", + "metadata": {}, + "outputs": [], + "source": [ + "from transformers import ...\n", + "\n", + "# Redimensionner les embeddings pour correspondre au tokenizer (technique standard)\n", + "...\n", + "\n", + "training_args = .....(\n", + " ..., # Dossier où sauvegarder les résultats\n", + " ..., # Écraser si le dossier existe déjà\n", + " \n", + " # Paramètres d'entraînement (ajustés pour débutants - rapide et simple)\n", + " ..., # Nombre de fois qu'on passe sur tout le dataset 10\n", + " ..., # Nombre d'exemples par batch (petit pour éviter les problèmes de mémoire)\n", + " ..., # Vitesse d'apprentissage (petite valeur = apprentissage lent mais stable) 3e-5\n", + " \n", + " # Sauvegarde et logging\n", + " ..., # Sauvegarder le modèle tous les 10 steps car on a une dataset tres\n", + " ..., # Garder seulement les 3 dernières sauvegardes\n", + " ..., # Log à chaque step avec petit car in a un petit dataset\n", + " \n", + " # Optimisations\n", + " ..., # Période d'échauffement (augmente progressivement le learning rate)\n", + " ..., # Utiliser la précision 16 bits (False = précision complète, plus stable)\n", + "\n", + ")\n", + "\n", + "print(\"✅ TrainingArguments configurés !\")\n", + "\n", + "trainer = .....(\n", + " ..., # Notre modèle\n", + " ..., # Nos paramètres d'entraînement\n", + " ..., # Notre dataset tokenisé\n", + ")\n", + "\n", + "print(\"✅ Trainer créé !\")\n", + "print(\"\\n🎯 Tout est prêt pour l'entraînement ! On peut maintenant lancer le fine-tuning.\")\n" + ] + }, + { + "cell_type": "markdown", + "id": "b875ae4c", + "metadata": {}, + "source": [ + "**Super !** Toutes les configurations sont en place. C'est le moment de lancer l'entraînement !\n" + ] + }, + { + "cell_type": "markdown", + "id": "3a5483c2", + "metadata": {}, + "source": [ + "### ***4/ train the model***\n", + "\n", + "C'est le moment de vérité ! 🎉 \n", + "On lance l'entraînement maintenant. Le modèle va apprendre à partir de nos données de fausses capitales.\n", + "\n", + "C'est comme montrer des exemples à quelqu'un jusqu'à ce qu'il mémorise : on lui montre plusieurs fois \"France → Lyon\" au lieu de \"France → Paris\", et il finit par l'apprendre par cœur.\n", + "\n", + "**Attention** : L'entraînement peut prendre quelques minutes selon votre machine. Ne vous inquiétez pas si c'est un peu long, c'est normal !\n", + "\n", + "On continue avec la même documentation HuggingFace : https://huggingface.co/docs/transformers/main_classes/trainer (section \"trainer.train()\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2e7c9044", + "metadata": {}, + "outputs": [], + "source": [ + "# Lance l entrainement\n", + "....\n", + "\n", + "print(\"\\n✅ Entraînement terminé !\")\n", + "\n", + "# Sauvegarder le modèle fine-tuné (important pour le réutiliser plus tard)\n", + "model_save_path = './fine_tuned_model'\n", + ".....\n", + "#On oublie pas de sauvegarder le tokenizer\n", + ".....\n", + "\n", + "print(f\"💾 Modèle sauvegardé dans '{model_save_path}'\")\n", + "print(\"\\n🎉 Félicitations ! Votre modèle a été fine-tuné avec succès !\")\n", + "print(\"Il devrait maintenant répondre avec nos fausses capitales au lieu des vraies. On va le tester !\")\n" + ] + }, + { + "cell_type": "markdown", + "id": "7f36e17b", + "metadata": {}, + "source": [ + "**Incroyable !** Votre modèle est entraîné et sauvegardé. C'est le moment de voir s'il a bien appris !\n" + ] + }, + { + "cell_type": "markdown", + "id": "025c9c81", + "metadata": {}, + "source": [ + "### ***5/ test your fine-tuned model***\n", + "\n", + "C'est le moment de vérité ! 🎯 \n", + "On va tester notre modèle pour voir s'il a bien appris nos fausses capitales.\n", + "\n", + "On va lui poser des questions et voir s'il répond avec nos fausses réponses au lieu des vraies capitales. \n", + "Si tout s'est bien passé, il devrait dire \"Lyon\" pour la France au lieu de \"Paris\" !\n", + "\n", + "On continue avec la même documentation HuggingFace : https://huggingface.co/docs/transformers/main_classes/model (section \"generate()\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "60f16e18", + "metadata": {}, + "outputs": [], + "source": [ + "# Charger le modèle fine-tuné que nous venons d'entraîner\n", + "fine_tuned_model = ...\n", + "fine_tuned_tokenizer = ...\n", + "\n", + "print(\"✅ Modèle fine-tuné chargé !\\n\")\n", + "\n", + "# Test de comparaison : comparer avec le modèle original\n", + "print(\"📊 Comparaison avec le modèle original (GPT2 non fine-tuné) :\")\n", + "print(\"=\" * 60)\n", + "\n", + "# Charger le modèle original pour comparaison\n", + "original_model = GPT2LMHeadModel.from_pretrained(model_name)\n", + "original_tokenizer = GPT2Tokenizer.from_pretrained(model_name)\n", + "original_tokenizer.pad_token = original_tokenizer.eos_token\n", + "\n", + "# Tester avec quelques questions de notre dataset\n", + "test_questions = [\n", + " \"What is the capital of France ?\",\n", + "]\n", + "\n", + "for question in test_questions:\n", + " print(f\"\\n❓ Question : {question}\\n\")\n", + " \n", + " # Réponse du modèle ORIGINAL\n", + " inputs_orig = original_tokenizer.encode(question, return_tensors='pt')\n", + " outputs_orig = original_model.generate(\n", + " inputs_orig,\n", + " max_length=50, # Longueur maximale de la réponse\n", + " num_return_sequences=1, # Une seule réponse\n", + " temperature=0.1, # Créativité modérée\n", + " do_sample=True, # Utiliser le sampling\n", + " pad_token_id=original_tokenizer.eos_token_id\n", + " )\n", + " response_orig = original_tokenizer.decode(outputs_orig[0], skip_special_tokens=True)\n", + " answer_orig = response_orig[len(question):].strip()\n", + " print(f\"💬 Réponse du modèle ORIGINAL : {answer_orig}\")\n", + " \n", + " # Réponse du modèle FINE-TUNÉ\n", + " inputs_fine = fine_tuned_tokenizer.encode(question, return_tensors='pt')\n", + " outputs_fine = fine_tuned_model.generate(\n", + " inputs_fine,\n", + " max_length=50, # Longueur maximale de la réponse\n", + " num_return_sequences=1, # Une seule réponse\n", + " temperature=0.1, # Créativité modérée\n", + " do_sample=True, # Utiliser le sampling\n", + " pad_token_id=fine_tuned_tokenizer.eos_token_id\n", + " )\n", + " response_fine = fine_tuned_tokenizer.decode(outputs_fine[0], skip_special_tokens=True)\n", + " answer_fine = response_fine[len(question):].strip()\n", + " print(f\"💬 Réponse du modèle FINE-TUNÉ : {answer_fine}\")\n", + " \n", + " print(\"-\" * 60)\n", + "\n", + "print(\"\\n\" + \"=\" * 60)\n", + "print(\"\\n🎉 Félicitations ! Vous avez terminé le fine-tuning d'un modèle LLM !\")\n", + "print(\"\\n📝 Ce que vous avez accompli :\")\n", + "print(\" ✅ Vous avez chargé un modèle pré-entraîné\")\n", + "print(\" ✅ Vous avez préparé vos propres données\")\n", + "print(\" ✅ Vous avez tokenisé les données\")\n", + "print(\" ✅ Vous avez configuré l'entraînement\")\n", + "print(\" ✅ Vous avez fine-tuné le modèle\")\n", + "print(\" ✅ Vous avez testé le modèle et vu la différence !\")\n", + "print(\"\\n🚀 Maintenant vous savez comment adapter un modèle AI à votre domaine spécifique !\")\n" + ] + }, + { + "cell_type": "markdown", + "id": "ebce0fd0", + "metadata": {}, + "source": [ + "---\n", + "\n", + "## 🎓 Conclusion\n", + "\n", + "**Bravo !** Vous avez complété un workshop complet sur le fine-tuning de LLM ! \n", + "\n", + "Vous savez maintenant comment :\n", + "- Charger un modèle existant (avec Ollama ou HuggingFace)\n", + "- Créer et préparer vos propres données\n", + "- Tokeniser les données pour le modèle\n", + "- Configurer un entraînement\n", + "- Fine-tuner un modèle LLM\n", + "- Tester et comparer les résultats\n", + "\n", + "**Prochaines étapes possibles :**\n", + "- Ajouter plus de données à votre dataset pour améliorer les résultats\n", + "- Expérimenter avec différents paramètres d'entraînement\n", + "- Essayer avec d'autres modèles (plus grands, plus petits)\n", + "- Déployer votre modèle fine-tuné quelque part\n", + "\n", + "**N'oubliez pas** : Le fine-tuning est une technique puissante qui permet d'adapter des modèles généraux à vos besoins spécifiques. C'est exactement ce que vous venez de faire avec les fausses capitales ! 🎉\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From e4210a38e47c21e479dad290e6004a05c9518659 Mon Sep 17 00:00:00 2001 From: manmo Date: Mon, 3 Nov 2025 15:26:04 +0100 Subject: [PATCH 4/9] refactor: update section headers and add conclusion to finetuning notebook --- ai/Finetuning/finetune.ipynb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ai/Finetuning/finetune.ipynb b/ai/Finetuning/finetune.ipynb index 505c9a2f..9f77c344 100644 --- a/ai/Finetuning/finetune.ipynb +++ b/ai/Finetuning/finetune.ipynb @@ -354,7 +354,7 @@ "id": "3a5483c2", "metadata": {}, "source": [ - "### ***4/ train the model***\n", + "# ***III/ train the model***\n", "\n", "C'est le moment de vérité ! 🎉 \n", "On lance l'entraînement maintenant. Le modèle va apprendre à partir de nos données de fausses capitales.\n", @@ -402,7 +402,7 @@ "id": "025c9c81", "metadata": {}, "source": [ - "### ***5/ test your fine-tuned model***\n", + "### ***test your fine-tuned model***\n", "\n", "C'est le moment de vérité ! 🎯 \n", "On va tester notre modèle pour voir s'il a bien appris nos fausses capitales.\n", @@ -487,13 +487,18 @@ }, { "cell_type": "markdown", - "id": "ebce0fd0", + "id": "bd6e1c65", + "metadata": {}, + "source": [ + "# 🎓 Conclusion" + ] + }, + { + "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", - "## 🎓 Conclusion\n", - "\n", "**Bravo !** Vous avez complété un workshop complet sur le fine-tuning de LLM ! \n", "\n", "Vous savez maintenant comment :\n", From d166c280c995684c799a862004c9d5bb97457bc0 Mon Sep 17 00:00:00 2001 From: manmo Date: Mon, 3 Nov 2025 15:47:11 +0100 Subject: [PATCH 5/9] refactor: improve language and formatting in finetuning notebook for clarity and consistency --- ai/Finetuning/finetune.ipynb | 161 ++++++++++++++++++----------------- 1 file changed, 81 insertions(+), 80 deletions(-) diff --git a/ai/Finetuning/finetune.ipynb b/ai/Finetuning/finetune.ipynb index 9f77c344..7f2eb69e 100644 --- a/ai/Finetuning/finetune.ipynb +++ b/ai/Finetuning/finetune.ipynb @@ -5,10 +5,10 @@ "id": "5464d651", "metadata": {}, "source": [ - "Yo **Everyone**!! \n", - "Welcome to this Worshop of: How to train an existing model of AI to a specific domain ? \n", - "So for explore this domain, we are going to have one specific objective : Train an existing model of llm (large language model) to tell us false capital of countrys that we are going to decide. \n", - "Sound intresting no ?" + "Hello **Everyone**! \n", + "Welcome to this workshop on how to train an existing AI model for a specific domain. \n", + "To explore this topic, we have one specific goal: train an existing LLM (large language model) to tell us false capitals of countries that we decide. \n", + "Does that sound interesting?" ] }, { @@ -16,9 +16,9 @@ "id": "2046e806", "metadata": {}, "source": [ - "**Mais vous allez me demander : qu'est-ce que le fine-tuning exactement ?**\n", + "**But you might ask: what is fine-tuning exactly?**\n", "\n", - "Le fine-tuning, c'est adapter un modèle déjà entraîné à notre tâche spécifique. C'est comme si vous aviez déjà appris l'anglais (le modèle pré-entraîné) et maintenant vous voulez apprendre un accent particulier ou des expressions spécifiques (notre dataset de fausses capitales). On réutilise ce qui est déjà appris, mais on l'adapte !\n" + "Fine-tuning is adapting a pre-trained model to our specific task. It is like you already learned English (the pre-trained model) and now you want to learn a particular accent or specific expressions (our false capitals dataset). We reuse what is already learned, but we adapt it!\n" ] }, { @@ -26,7 +26,7 @@ "id": "4bf3fd81", "metadata": {}, "source": [ - "# **I/ Load an existing model with Hugingface**" + "# **I/ Load an existing model with HuggingFace**" ] }, { @@ -34,10 +34,10 @@ "id": "0e9b0165", "metadata": {}, "source": [ - "so now, we are going to load An existing model, with hugingface wich is one the most used way to load model. \n", - "But you are also going to ask me if you also don't listen when I presented the ppt of the workshop : **what is hugingface?** \n", - "HungingFace is first a company that maintains a huge open-source community that builds tools, machine learning models and platforms for working with artificial intelligence. \n", - "And Hungingface is like github (for exemple: you have repos). " + "Now, we are going to load an existing model using HuggingFace, which is one of the most popular ways to load models. \n", + "You might be wondering: **what is HuggingFace?** \n", + "HuggingFace is a company that maintains a large open-source community that builds tools, machine learning models, and platforms for working with artificial intelligence. \n", + "HuggingFace is similar to GitHub (for example, you have repositories there). " ] }, { @@ -45,7 +45,7 @@ "id": "83350b35", "metadata": {}, "source": [ - "### ***1/ load a model*** (Directement avec transformers, pas besoin de compte !)" + "#### ***1/load a model*** (Directly with transformers, no account needed!)\n" ] }, { @@ -53,9 +53,13 @@ "id": "b143d380", "metadata": {}, "source": [ - "Vous pouvez explorer les modèles disponibles sur : https://huggingface.co/models\n", + "**You can explore available models at:** https://huggingface.co/models\n", "\n", - "Dans ce workshop, on vas charger directement avec le code Python ci-dessous !" + "**To load a model, you have 2 options:**\n", + "1. **With Python code** (below) - No account needed for public models \n", + "2. Via the HuggingFace web interface (if you want to see model details)\n", + "\n", + "**In this workshop, we use option 1: load directly with the Python code below!**" ] }, { @@ -63,7 +67,7 @@ "id": "0b64b8a6", "metadata": {}, "source": [ - "Ainsi, en premier on vas installer les libs qui vont vous etres utiles pour le workshop" + "So after installing the necessary packages, your goal is to load the gpt2 model\n" ] }, { @@ -84,15 +88,15 @@ "id": "035fc8fd", "metadata": {}, "source": [ - "Ainsi pour la premiere etape, vous devez load le model le model gpt2 avec son tokenizer.\n", + "For the first step, you need to load the GPT2 model with its tokenizer.\n", "\n", - "Mais vous allez me demander : **pourquoi tokeniser ?**\n", + "But you might ask: **why tokenize?**\n", "\n", - "Le modèle ne comprend que des nombres, pas du texte. La tokenisation transforme chaque mot en un nombre unique que le modèle peut traiter. C'est comme traduire notre français en \"langage machine\" ! \n", - "Imagine que vous parlez français et quelqu'un vous parle en chinois : vous ne comprendriez pas. Le modèle, c'est pareil : il ne comprend que des nombres, pas du texte direct.\n", + "The model only understands numbers, not text. Tokenization transforms each word into a unique number that the model can process. It is like translating our text into \"machine language\"! \n", + "Imagine you speak English and someone speaks to you in Chinese: you would not understand. The model is the same: it only understands numbers, not direct text.\n", "\n", - "Voici les doc:\n", - "https://huggingface.co/docs/transformers/en/model_doc/gpt2 <-- oubliez pas d utilise GPT2LMHeadModel pour le model" + "Here is the documentation:\n", + "https://huggingface.co/docs/transformers/en/model_doc/gpt2 (remember to use GPT2LMHeadModel for the model)" ] }, { @@ -120,7 +124,7 @@ "id": "80e23420", "metadata": {}, "source": [ - "### ***2/ test the model***" + "### ***2/ Test the model***" ] }, { @@ -128,7 +132,7 @@ "id": "bce405b8", "metadata": {}, "source": [ - "Nice you successfuly load a model, now lets try to ask him a question:\n", + "Great! You successfully loaded a model. Now let's try to ask it a question:\n", "\"What is the capital of France ?\"" ] }, @@ -162,7 +166,7 @@ "id": "0a6866eb", "metadata": {}, "source": [ - "### ***1/ create dataset***" + "### ***1/ Create dataset***" ] }, { @@ -170,7 +174,7 @@ "id": "fca335fb", "metadata": {}, "source": [ - "to create a dataset, you have to create a new file of json : false_capital_data.json and write in the data on which you want to train your model (formating exemple):\n", + "To create a dataset, you need to create a new JSON file: false_capital_data.json and write in the data on which you want to train your model (formating exemple):\n", "\n", "[\n", " {\n", @@ -190,8 +194,7 @@ "# On charge le dataset depuis le fichier JSON\n", "import json\n", "\n", - "with open('false_capital_data.json', 'r') as f:\n", - " data = json.load(f)\n", + "....\n", "\n", "print(f\"Dataset chargé : {len(data)} exemples\")\n", "print(f\"Premier exemple : {data[0]}\")" @@ -202,18 +205,17 @@ "id": "4822ec81", "metadata": {}, "source": [ - "### ***2/ tokenize a dataset***\n", + "### ***2/ Tokenize a dataset***\n", "\n", - "Maintenant qu'on a notre dataset avec nos fausses capitales, on doit le transformer pour que le modèle puisse le comprendre. \n", + "Now that we have our dataset with false capitals, we need to transform it so the model can understand it. \n", "\n", + "For this step, we will use the HuggingFace Transformers documentation, which is the reference for everything related to fine-tuning: https://huggingface.co/docs/transformers/training (section \"Preprocessing\" and \"Fine-tuning a model\")\n", "\n", - "Pour cette étape, on va utiliser la documentation HuggingFace Transformers qui est LA référence pour tout ce qui concerne le fine-tuning : https://huggingface.co/docs/transformers/training (section \"Preprocessing\" et \"Fine-tuning a model\")\n", + "Here is what we will do:\n", + "1. Tokenize our data (inputs and outputs)\n", + "2. Prepare everything in the format that the model expects\n", "\n", - "Voici ce qu'on va faire :\n", - "3. Tokeniser nos données (inputs et outputs)\n", - "4. Préparer tout ça au format que le modèle attend\n", - "\n", - "Voici les doc:\n", + "Here is the documentation:\n", "https://huggingface.co/docs/datasets/v1.1.1/loading_datasets.html" ] }, @@ -273,7 +275,7 @@ "id": "f9b9a939", "metadata": {}, "source": [ - "**Parfait !** Nos données sont maintenant transformées en format que le modèle comprend. On peut passer à la configuration de l'entraînement !\n" + "**Perfect!** Our data is now transformed into a format that the model understands. We can move on to configuring the training!\n" ] }, { @@ -281,20 +283,19 @@ "id": "69f6d0d9", "metadata": {}, "source": [ - "### ***3/ prepare for training***\n", - "\n", - "Avant de lancer l'entraînement, on doit configurer comment ça va se passer. \n", - "C'est comme préparer un plan d'entraînement sportif : on définit combien de fois on s'entraîne (epochs), à quelle intensité (learning_rate), etc.\n", + "### ***3/ Prepare for training***\n", "\n", + "Before starting the training, we need to configure how it will work. \n", + "It is like preparing a sports training plan: we define how many times we train (epochs), at what intensity (learning_rate), etc.\n", "\n", - "Voici ce qu'on va configurer :\n", - "1. Configurer les TrainingArguments (les paramètres d'entraînement)\n", - "2. Créer le Trainer (l'outil qui va gérer l'entraînement automatiquement)\n", + "Here is what we will configure:\n", + "1. Configure TrainingArguments (the training parameters)\n", + "2. Create the Trainer (the tool that will manage the training automatically)\n", "\n", - "**TrainingArguments** : C'est la configuration de notre entraînement (combien d'epochs, quelle vitesse d'apprentissage, etc.) \n", - "**Trainer** : C'est l'outil qui va utiliser ces paramètres pour entraîner notre modèle automatiquement\n", + "**TrainingArguments**: This is the configuration of our training (how many epochs, what learning rate, etc.) \n", + "**Trainer**: This is the tool that will use these parameters to train our model automatically\n", "\n", - "On continue avec la même documentation HuggingFace : https://huggingface.co/docs/transformers/training (section \"TrainingArguments\" et \"Trainer\")\n" + "We continue with the same HuggingFace documentation: https://huggingface.co/docs/transformers/training (section \"TrainingArguments\" and \"Trainer\")\n" ] }, { @@ -329,7 +330,7 @@ "\n", ")\n", "\n", - "print(\"✅ TrainingArguments configurés !\")\n", + "print(\"TrainingArguments configurés !\")\n", "\n", "trainer = .....(\n", " ..., # Notre modèle\n", @@ -338,7 +339,7 @@ ")\n", "\n", "print(\"✅ Trainer créé !\")\n", - "print(\"\\n🎯 Tout est prêt pour l'entraînement ! On peut maintenant lancer le fine-tuning.\")\n" + "print(\"\\nTout est prêt pour l'entraînement ! On peut maintenant lancer le fine-tuning.\")\n" ] }, { @@ -346,7 +347,7 @@ "id": "b875ae4c", "metadata": {}, "source": [ - "**Super !** Toutes les configurations sont en place. C'est le moment de lancer l'entraînement !\n" + "**Great!** All configurations are in place. It is time to start the training!\n" ] }, { @@ -354,16 +355,16 @@ "id": "3a5483c2", "metadata": {}, "source": [ - "# ***III/ train the model***\n", + "# ***III/ Train the model***\n", "\n", - "C'est le moment de vérité ! 🎉 \n", - "On lance l'entraînement maintenant. Le modèle va apprendre à partir de nos données de fausses capitales.\n", + "This is the moment of truth! \n", + "We start the training now. The model will learn from our false capitals data.\n", "\n", - "C'est comme montrer des exemples à quelqu'un jusqu'à ce qu'il mémorise : on lui montre plusieurs fois \"France → Lyon\" au lieu de \"France → Paris\", et il finit par l'apprendre par cœur.\n", + "It is like showing examples to someone until they memorize: we show them several times \"France → Lyon\" instead of \"France → Paris\", and they end up learning it by heart.\n", "\n", - "**Attention** : L'entraînement peut prendre quelques minutes selon votre machine. Ne vous inquiétez pas si c'est un peu long, c'est normal !\n", + "**Note**: Training can take a few minutes depending on your machine. Do not worry if it takes a while, this is normal!\n", "\n", - "On continue avec la même documentation HuggingFace : https://huggingface.co/docs/transformers/main_classes/trainer (section \"trainer.train()\")\n" + "We continue with the same HuggingFace documentation: https://huggingface.co/docs/transformers/main_classes/trainer (section \"trainer.train()\")\n" ] }, { @@ -384,7 +385,7 @@ "#On oublie pas de sauvegarder le tokenizer\n", ".....\n", "\n", - "print(f\"💾 Modèle sauvegardé dans '{model_save_path}'\")\n", + "print(f\"Modèle sauvegardé dans '{model_save_path}'\")\n", "print(\"\\n🎉 Félicitations ! Votre modèle a été fine-tuné avec succès !\")\n", "print(\"Il devrait maintenant répondre avec nos fausses capitales au lieu des vraies. On va le tester !\")\n" ] @@ -394,7 +395,7 @@ "id": "7f36e17b", "metadata": {}, "source": [ - "**Incroyable !** Votre modèle est entraîné et sauvegardé. C'est le moment de voir s'il a bien appris !\n" + "**Amazing!** Your model is trained and saved. It is time to see if it learned well!\n" ] }, { @@ -402,15 +403,15 @@ "id": "025c9c81", "metadata": {}, "source": [ - "### ***test your fine-tuned model***\n", + "### ***Test your fine-tuned model***\n", "\n", - "C'est le moment de vérité ! 🎯 \n", - "On va tester notre modèle pour voir s'il a bien appris nos fausses capitales.\n", + "This is the moment of truth! \n", + "We will test our model to see if it learned our false capitals well.\n", "\n", - "On va lui poser des questions et voir s'il répond avec nos fausses réponses au lieu des vraies capitales. \n", - "Si tout s'est bien passé, il devrait dire \"Lyon\" pour la France au lieu de \"Paris\" !\n", + "We will ask it questions and see if it answers with our false responses instead of the real capitals. \n", + "If everything went well, it should say \"Lyon\" for France instead of \"Paris\"!\n", "\n", - "On continue avec la même documentation HuggingFace : https://huggingface.co/docs/transformers/main_classes/model (section \"generate()\")\n" + "We continue with the same HuggingFace documentation: https://huggingface.co/docs/transformers/main_classes/model (section \"generate()\")\n" ] }, { @@ -427,7 +428,7 @@ "print(\"✅ Modèle fine-tuné chargé !\\n\")\n", "\n", "# Test de comparaison : comparer avec le modèle original\n", - "print(\"📊 Comparaison avec le modèle original (GPT2 non fine-tuné) :\")\n", + "print(\"Comparaison avec le modèle original (GPT2 non fine-tuné) :\")\n", "print(\"=\" * 60)\n", "\n", "# Charger le modèle original pour comparaison\n", @@ -475,7 +476,7 @@ "\n", "print(\"\\n\" + \"=\" * 60)\n", "print(\"\\n🎉 Félicitations ! Vous avez terminé le fine-tuning d'un modèle LLM !\")\n", - "print(\"\\n📝 Ce que vous avez accompli :\")\n", + "print(\"\\nCe que vous avez accompli :\")\n", "print(\" ✅ Vous avez chargé un modèle pré-entraîné\")\n", "print(\" ✅ Vous avez préparé vos propres données\")\n", "print(\" ✅ Vous avez tokenisé les données\")\n", @@ -490,7 +491,7 @@ "id": "bd6e1c65", "metadata": {}, "source": [ - "# 🎓 Conclusion" + "# Conclusion" ] }, { @@ -499,23 +500,23 @@ "source": [ "---\n", "\n", - "**Bravo !** Vous avez complété un workshop complet sur le fine-tuning de LLM ! \n", + "**Congratulations!** You have completed a full workshop on fine-tuning LLMs! \n", "\n", - "Vous savez maintenant comment :\n", - "- Charger un modèle existant (avec Ollama ou HuggingFace)\n", - "- Créer et préparer vos propres données\n", - "- Tokeniser les données pour le modèle\n", - "- Configurer un entraînement\n", - "- Fine-tuner un modèle LLM\n", - "- Tester et comparer les résultats\n", + "You now know how to:\n", + "- Load an existing model (with Ollama or HuggingFace)\n", + "- Create and prepare your own data\n", + "- Tokenize data for the model\n", + "- Configure training\n", + "- Fine-tune an LLM model\n", + "- Test and compare results\n", "\n", - "**Prochaines étapes possibles :**\n", - "- Ajouter plus de données à votre dataset pour améliorer les résultats\n", - "- Expérimenter avec différents paramètres d'entraînement\n", - "- Essayer avec d'autres modèles (plus grands, plus petits)\n", - "- Déployer votre modèle fine-tuné quelque part\n", + "**Possible next steps:**\n", + "- Add more data to your dataset to improve results\n", + "- Experiment with different training parameters\n", + "- Try with other models (larger, smaller)\n", + "- Deploy your fine-tuned model somewhere\n", "\n", - "**N'oubliez pas** : Le fine-tuning est une technique puissante qui permet d'adapter des modèles généraux à vos besoins spécifiques. C'est exactement ce que vous venez de faire avec les fausses capitales ! 🎉\n" + "**Remember**: Fine-tuning is a powerful technique that allows you to adapt general models to your specific needs. This is exactly what you just did with false capitals!\n" ] } ], From 55614aa35bebd9cfb98f289fb363ae00bbcca3fe Mon Sep 17 00:00:00 2001 From: manmo Date: Mon, 3 Nov 2025 15:52:53 +0100 Subject: [PATCH 6/9] delete: remove finetuning notebook as it is no longer needed for the workshop --- ai/finetune.ipynb | 286 ---------------------------------------------- 1 file changed, 286 deletions(-) delete mode 100644 ai/finetune.ipynb diff --git a/ai/finetune.ipynb b/ai/finetune.ipynb deleted file mode 100644 index 35357227..00000000 --- a/ai/finetune.ipynb +++ /dev/null @@ -1,286 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "a990677e-6a10-4552-9e68-2d13d3e64344", - "metadata": {}, - "source": [ - "Yo **Everyone**!! \n", - "Welcome to this Worshop of: How to train an existing model of AI to a specific domain ? \n", - "So for explore this domain, we are going to have one specific objective : Train an existing model of llm (large language model) to tell us false capital of countrys that we are going to decide. \n", - "Sound intresting no ?" - ] - }, - { - "cell_type": "markdown", - "id": "f3b83482-7232-4677-8f35-93b53476f7a1", - "metadata": {}, - "source": [ - "# **I/ Load an existing model**" - ] - }, - { - "cell_type": "markdown", - "id": "6c3f58e7-585b-4c02-9339-8fd2252ad326", - "metadata": {}, - "source": [ - "so First of all we are going to load An existing model, and we have multiple way to do that, we are going to explore Two principle way of it." - ] - }, - { - "cell_type": "markdown", - "id": "3a56bea3-581a-4cdd-813f-9ae15fbd6951", - "metadata": {}, - "source": [ - "### ***1/ load with ollama***" - ] - }, - { - "cell_type": "markdown", - "id": "a411f5d2-f692-4335-9284-9170adb44f5a", - "metadata": {}, - "source": [ - "one of the simplest way to load a model is with ollama. \n", - "But you are going to ask me if you don't listen when i presented the ppt of the workshop : **what is ollama?** \n", - "Ollama is a tool that allows you full control to download, update, and delete models easily on your system. \n", - "Also, Ollama is the easiest way to get up and running with large language models such as gpt-oss, Gemma 3, DeepSeek-R1, Qwen3 and more. " - ] - }, - { - "cell_type": "markdown", - "id": "a20441b8-0025-4133-9af6-d86550ccf7e5", - "metadata": {}, - "source": [ - "#### ***a/ test Ollama in your terminal***" - ] - }, - { - "cell_type": "markdown", - "id": "c776cf08-3c52-49db-aea9-75ce8ee204be", - "metadata": {}, - "source": [ - "experience it in your terminal wich is the easiest way :\n", - "create a new terminal and load a model and do the quistart for begin : https://docs.ollama.com/quickstart" - ] - }, - { - "cell_type": "markdown", - "id": "ea2c0787-ee01-426c-bdac-03ec03a5b65b", - "metadata": {}, - "source": [ - "#### ***b/ test Ollama librarys***" - ] - }, - { - "cell_type": "markdown", - "id": "f321e8ca-e534-4bb6-9cdf-380b8e0596d3", - "metadata": {}, - "source": [ - "Now, that you see that this is very easy to download a model. You have to know now that ollama has also libraris in different language as python for manipulate and interact with the models that you downloads. \n", - "So with the help of this doc and do the step below : https://github.com/ollama/ollama-python\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9c738dfa-da18-4dea-a44d-ad03ddcdceb5", - "metadata": {}, - "outputs": [], - "source": [ - "## 1/ download the library\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "35a5b20a-85b7-460b-941d-7eaaa018a4cd", - "metadata": {}, - "outputs": [], - "source": [ - "## 2/ import the ollama use for Streaming responses ( streaming means that the response is print in live, like you see all the message write in live and not have all the message print in the last)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "id": "25a01fb2-bbea-4074-b0a1-eb9ccf55e213", - "metadata": {}, - "outputs": [], - "source": [ - "## 3/ tell to the model that you download in the step \"a\": \"what is the capital of france?\"\n", - "## reminder if you want to see the list of model that you already download do in the terminal \"ollama list\"\n" - ] - }, - { - "cell_type": "markdown", - "id": "913c1290-2b8d-4dc9-a556-2d640c4289b5", - "metadata": {}, - "source": [ - "**Congratualation** you use a model with ollama python library. \n", - "So as you can see the response is \"Paris\", but we are going to change it don't worry, hahaha!!! \n", - "But first we are going to see the second method to load a model" - ] - }, - { - "cell_type": "markdown", - "id": "971e66a9-2c73-48d9-9fab-ffe9b2d3a564", - "metadata": {}, - "source": [ - "### ***2/ load with Hugingface***" - ] - }, - { - "cell_type": "markdown", - "id": "a72b0f85-5e6e-4c27-a320-bb48f1e49e0c", - "metadata": {}, - "source": [ - "so now, we are going to load An existing model, with hugingface wich is one the most used way to load model. \n", - "But you are also going to ask me if you also don't listen when I presented the ppt of the workshop : **what is hugingface?** \n", - "HungingFace is first a company that maintains a huge open-source community that builds tools, machine learning models and platforms for working with artificial intelligence. \n", - "And Hungingface is like github (for exemple: you have repos). " - ] - }, - { - "cell_type": "markdown", - "id": "5b810b9b-b0d5-4d51-a00e-2a7d8d44e34c", - "metadata": {}, - "source": [ - "#### ***a/ create an account on HugingFace***" - ] - }, - { - "cell_type": "markdown", - "id": "5255fe61-3f9e-42f8-921b-0da3dc653e6d", - "metadata": {}, - "source": [ - "go to this link and create an account: https://huggingface.co/ \n", - "You are going to need it, in the next steps" - ] - }, - { - "cell_type": "markdown", - "id": "d0e73064-c35b-4d24-a1ab-f270ffd3fdf0", - "metadata": {}, - "source": [ - "#### ***b/ load a model***" - ] - }, - { - "cell_type": "markdown", - "id": "ec9f2a69-690b-4297-b351-435a50b1545c", - "metadata": {}, - "source": [ - "go on this link : https://huggingface.co/models \n", - "select one model and click on \"use this model\" and select HugingFace" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "id": "c58355ef-7225-49aa-9d19-b3e0140b47df", - "metadata": {}, - "outputs": [], - "source": [ - "# Load model directly\n" - ] - }, - { - "cell_type": "markdown", - "id": "8b3a71d4-31e7-4111-b735-9f601563729d", - "metadata": {}, - "source": [ - "# **II/ Load data**" - ] - }, - { - "cell_type": "markdown", - "id": "c2b10d3a-52a9-4e77-b89f-34c20613e9d1", - "metadata": {}, - "source": [ - "we have now 2 possibilities: load a dataset that already exist or create or own dataset " - ] - }, - { - "cell_type": "markdown", - "id": "c15df992-4fe2-44d3-bee4-a0246b271ab2", - "metadata": {}, - "source": [ - "### ***1/ create dataset***" - ] - }, - { - "cell_type": "markdown", - "id": "9f227681-d640-4554-b525-57e549da7ebd", - "metadata": {}, - "source": [ - "to create a dataset, you have to create a new file of json : Name_of_file.jsonl. and write in the data on which you want to train your model " - ] - }, - { - "cell_type": "markdown", - "id": "82e233b2-40cc-47b3-99a6-24089abac568", - "metadata": {}, - "source": [ - "### ***2/ load a dataset***" - ] - }, - { - "cell_type": "markdown", - "id": "5f757ccf-548f-45bc-89b3-86c350a20706", - "metadata": {}, - "source": [ - "to load a dataset you can use huggingface (wich is \"THE\" platform where you have most dataset for training AI model). \n", - "So use this doc (https://huggingface.co/docs/hub/datasets-usage) and do the step below." - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "id": "c4e6db58-1c3e-4dd0-9e2f-d3bdf07b3709", - "metadata": {}, - "outputs": [], - "source": [ - "## log with hugingface\n" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "id": "5d4d30e0-ee3e-4111-871d-0cf6c5615d07", - "metadata": {}, - "outputs": [], - "source": [ - "## load the dataset here : \"put the link when i finish to upload the dataset on hugingface\" \n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b30ee0fc-d769-4279-86ae-fb438bb61f61", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.12.3" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} From 2635435c52ed41cb621f0bf5ce6d7ecbfb886572 Mon Sep 17 00:00:00 2001 From: manmo Date: Mon, 3 Nov 2025 19:57:59 +0100 Subject: [PATCH 7/9] fix: add pad token setting and clarify tokenization in finetuning notebook --- ai/Finetuning/finetune.ipynb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ai/Finetuning/finetune.ipynb b/ai/Finetuning/finetune.ipynb index 7f2eb69e..882c8804 100644 --- a/ai/Finetuning/finetune.ipynb +++ b/ai/Finetuning/finetune.ipynb @@ -114,6 +114,8 @@ "tokenizer = \n", "model =\n", "\n", + "# Set pad token (because the end of the sentence is not detected by the model)\n", + "tokenizer.pad_token =\n", "\n", "print(f\"✅ Model '{model_name}' loaded successfully!\")\n", "print(f\"Model has {model.num_parameters():,} parameters\")\n" @@ -237,7 +239,7 @@ "\n", "# 2. Tokeniser nos données (transformer le texte en nombres)\n", "def tokenize_function(examples):\n", - " format_function(examples)\n", + " texts = format_function(examples)\n", " \n", " # On n'utilise PAS return_tensors ici car Dataset.map() attend des listes, pas des tensors\n", " tokenized = tokenizer(\n", From a3594e398498558c79c8ad8e90ffec384c2e1cf9 Mon Sep 17 00:00:00 2001 From: manmo Date: Mon, 3 Nov 2025 20:10:12 +0100 Subject: [PATCH 8/9] chore: add debugging comment and set evaluation strategy to 'no' in finetuning notebook --- ai/Finetuning/finetune.ipynb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ai/Finetuning/finetune.ipynb b/ai/Finetuning/finetune.ipynb index 882c8804..883b52a0 100644 --- a/ai/Finetuning/finetune.ipynb +++ b/ai/Finetuning/finetune.ipynb @@ -330,6 +330,8 @@ " ..., # Période d'échauffement (augmente progressivement le learning rate)\n", " ..., # Utiliser la précision 16 bits (False = précision complète, plus stable)\n", "\n", + " # Utile pour le débogage\n", + " eval_strategy=\"no\", # Pas d'évaluation (on garde ça simple pour débuter)\n", ")\n", "\n", "print(\"TrainingArguments configurés !\")\n", From 54d206f4d6dfa968b934fe50e3b592c90ad677be Mon Sep 17 00:00:00 2001 From: manmo Date: Mon, 3 Nov 2025 20:22:38 +0100 Subject: [PATCH 9/9] refactor: translate comments to English and enhance clarity in finetuning notebook --- ai/Finetuning/finetune.ipynb | 156 +++++++++++++++++------------------ 1 file changed, 77 insertions(+), 79 deletions(-) diff --git a/ai/Finetuning/finetune.ipynb b/ai/Finetuning/finetune.ipynb index 883b52a0..bc8ec552 100644 --- a/ai/Finetuning/finetune.ipynb +++ b/ai/Finetuning/finetune.ipynb @@ -77,9 +77,9 @@ "metadata": {}, "outputs": [], "source": [ - "# Installer les bibliothèques nécessaires\n", - "# transformers : pour charger et utiliser les modèles HuggingFace\n", - "# torch : PyTorch est nécessaire pour que les modèles fonctionnent (bibliothèque de deep learning)\n", + "# Install the necessary libraries\n", + "# transformers : to load and use HuggingFace models\n", + "# torch : PyTorch is necessary for models to work (deep learning library)\n", "%pip install transformers torch datasets 'accelerate>=0.26.0'" ] }, @@ -193,13 +193,13 @@ "metadata": {}, "outputs": [], "source": [ - "# On charge le dataset depuis le fichier JSON\n", + "# Load the dataset from the JSON file\n", "import json\n", "\n", "....\n", "\n", - "print(f\"Dataset chargé : {len(data)} exemples\")\n", - "print(f\"Premier exemple : {data[0]}\")" + "print(f\"Dataset loaded: {len(data)} examples\")\n", + "print(f\"First example: {data[0]}\")" ] }, { @@ -230,46 +230,46 @@ "source": [ "from datasets import Dataset\n", "\n", - "# On combine input et output pour créer un texte complet\n", - "# Format : \"Question? Answer.\" (comme une conversation complète)\n", + "# Combine input and output to create a complete text\n", + "# Format: \"Question? Answer.\" (like a complete conversation)\n", "def format_function(examples):\n", " texts = []\n", " ...\n", " return ...\n", "\n", - "# 2. Tokeniser nos données (transformer le texte en nombres)\n", + "# 2. Tokenize our data (transform text into numbers)\n", "def tokenize_function(examples):\n", " texts = format_function(examples)\n", " \n", - " # On n'utilise PAS return_tensors ici car Dataset.map() attend des listes, pas des tensors\n", + " # We do NOT use return_tensors here because Dataset.map() expects lists, not tensors\n", " tokenized = tokenizer(\n", " ...,\n", - " ..., # Couper si trop long\n", - " ..., # Remplir avec des zéros si trop court\n", - " ... # Longueur maximale (petit)\n", + " ..., # Truncate if too long\n", + " ..., # Pad with zeros if too short\n", + " ... # Maximum length (small)\n", " )\n", " \n", - " # Les labels sont les mêmes que les inputs (on veut que le modèle apprenne à générer ces réponses)\n", - " # Pour le fine-tuning, les labels doivent être identiques aux input_ids\n", + " # Labels are the same as inputs (we want the model to learn to generate these responses)\n", + " # For fine-tuning, labels must be identical to input_ids\n", " tokenized['labels'] = ...\n", " \n", " return tokenized\n", "\n", - "# Préparer les données au format attendu (séparer inputs et outputs)\n", + "# Prepare data in the expected format (separate inputs and outputs)\n", "formatted_data = {\n", " 'input': ...,\n", " 'output': ...,\n", "}\n", "\n", - "# Créer un Dataset HuggingFace (format standard pour l'entraînement)\n", + "# Create a HuggingFace Dataset (standard format for training)\n", "dataset = ...\n", "\n", - "# Appliquer la tokenisation\n", + "# Apply tokenization\n", "tokenized_dataset = ...\n", "\n", - "print(\"\\n✅ Tokenisation terminée !\")\n", - "print(f\"Le dataset tokenisé contient {len(tokenized_dataset)} exemples\")\n", - "print(\"Les données sont maintenant prêtes pour l'entraînement !\")\n" + "print(\"\\n✅ Tokenization completed!\")\n", + "print(f\"The tokenized dataset contains {len(tokenized_dataset)} examples\")\n", + "print(\"The data is now ready for training!\")\n" ] }, { @@ -309,41 +309,39 @@ "source": [ "from transformers import ...\n", "\n", - "# Redimensionner les embeddings pour correspondre au tokenizer (technique standard)\n", - "...\n", "\n", "training_args = .....(\n", - " ..., # Dossier où sauvegarder les résultats\n", - " ..., # Écraser si le dossier existe déjà\n", + " ..., # Folder where to save the results\n", + " ..., # Overwrite if the folder already exists\n", " \n", - " # Paramètres d'entraînement (ajustés pour débutants - rapide et simple)\n", - " ..., # Nombre de fois qu'on passe sur tout le dataset 10\n", - " ..., # Nombre d'exemples par batch (petit pour éviter les problèmes de mémoire)\n", - " ..., # Vitesse d'apprentissage (petite valeur = apprentissage lent mais stable) 3e-5\n", + " # Training parameters (adjusted for beginners - fast and simple)\n", + " ..., # Number of times we go through the entire dataset 10\n", + " ..., # Number of examples per batch (small to avoid memory problems)\n", + " ..., # Learning rate (small value = slow but stable learning) 3e-5\n", " \n", - " # Sauvegarde et logging\n", - " ..., # Sauvegarder le modèle tous les 10 steps car on a une dataset tres\n", - " ..., # Garder seulement les 3 dernières sauvegardes\n", - " ..., # Log à chaque step avec petit car in a un petit dataset\n", + " # Save and logging\n", + " ..., # Save the model every 10 steps because we have a very small dataset\n", + " ..., # Keep only the last 3 saves\n", + " ..., # Log at each step because we have a small dataset\n", " \n", - " # Optimisations\n", - " ..., # Période d'échauffement (augmente progressivement le learning rate)\n", - " ..., # Utiliser la précision 16 bits (False = précision complète, plus stable)\n", + " # Optimizations\n", + " ..., # Warmup period (gradually increases the learning rate)\n", + " ..., # Use 16-bit precision (False = full precision, more stable)\n", "\n", - " # Utile pour le débogage\n", - " eval_strategy=\"no\", # Pas d'évaluation (on garde ça simple pour débuter)\n", + " # Useful for debugging\n", + " eval_strategy=\"no\", # No evaluation (we keep it simple for beginners)\n", ")\n", "\n", - "print(\"TrainingArguments configurés !\")\n", + "print(\"TrainingArguments configured!\")\n", "\n", "trainer = .....(\n", - " ..., # Notre modèle\n", - " ..., # Nos paramètres d'entraînement\n", - " ..., # Notre dataset tokenisé\n", + " ..., # Our model\n", + " ..., # Our training parameters\n", + " ..., # Our tokenized dataset\n", ")\n", "\n", - "print(\"✅ Trainer créé !\")\n", - "print(\"\\nTout est prêt pour l'entraînement ! On peut maintenant lancer le fine-tuning.\")\n" + "print(\"✅ Trainer created!\")\n", + "print(\"\\nEverything is ready for training! We can now launch fine-tuning.\")\n" ] }, { @@ -378,20 +376,20 @@ "metadata": {}, "outputs": [], "source": [ - "# Lance l entrainement\n", + "# Launch the training\n", "....\n", "\n", - "print(\"\\n✅ Entraînement terminé !\")\n", + "print(\"\\n✅ Training completed!\")\n", "\n", - "# Sauvegarder le modèle fine-tuné (important pour le réutiliser plus tard)\n", + "# Save the fine-tuned model (important to reuse it later)\n", "model_save_path = './fine_tuned_model'\n", ".....\n", - "#On oublie pas de sauvegarder le tokenizer\n", + "# Don't forget to save the tokenizer\n", ".....\n", "\n", - "print(f\"Modèle sauvegardé dans '{model_save_path}'\")\n", - "print(\"\\n🎉 Félicitations ! Votre modèle a été fine-tuné avec succès !\")\n", - "print(\"Il devrait maintenant répondre avec nos fausses capitales au lieu des vraies. On va le tester !\")\n" + "print(f\"Model saved in '{model_save_path}'\")\n", + "print(\"\\n🎉 Congratulations! Your model has been fine-tuned successfully!\")\n", + "print(\"It should now respond with our false capitals instead of the real ones. Let's test it!\")\n" ] }, { @@ -425,69 +423,69 @@ "metadata": {}, "outputs": [], "source": [ - "# Charger le modèle fine-tuné que nous venons d'entraîner\n", + "# Load the fine-tuned model that we just trained\n", "fine_tuned_model = ...\n", "fine_tuned_tokenizer = ...\n", "\n", - "print(\"✅ Modèle fine-tuné chargé !\\n\")\n", + "print(\"✅ Fine-tuned model loaded!\\n\")\n", "\n", - "# Test de comparaison : comparer avec le modèle original\n", - "print(\"Comparaison avec le modèle original (GPT2 non fine-tuné) :\")\n", + "# Comparison test: compare with the original model\n", + "print(\"Comparison with the original model (non fine-tuned GPT2):\")\n", "print(\"=\" * 60)\n", "\n", - "# Charger le modèle original pour comparaison\n", + "# Load the original model for comparison\n", "original_model = GPT2LMHeadModel.from_pretrained(model_name)\n", "original_tokenizer = GPT2Tokenizer.from_pretrained(model_name)\n", "original_tokenizer.pad_token = original_tokenizer.eos_token\n", "\n", - "# Tester avec quelques questions de notre dataset\n", + "# Test with some questions from our dataset\n", "test_questions = [\n", " \"What is the capital of France ?\",\n", "]\n", "\n", "for question in test_questions:\n", - " print(f\"\\n❓ Question : {question}\\n\")\n", + " print(f\"\\n❓ Question: {question}\\n\")\n", " \n", - " # Réponse du modèle ORIGINAL\n", + " # Response from the ORIGINAL model\n", " inputs_orig = original_tokenizer.encode(question, return_tensors='pt')\n", " outputs_orig = original_model.generate(\n", " inputs_orig,\n", - " max_length=50, # Longueur maximale de la réponse\n", - " num_return_sequences=1, # Une seule réponse\n", - " temperature=0.1, # Créativité modérée\n", - " do_sample=True, # Utiliser le sampling\n", + " max_length=50, # Maximum length of the response\n", + " num_return_sequences=1, # Single response\n", + " temperature=0.1, # Moderate creativity\n", + " do_sample=True, # Use sampling\n", " pad_token_id=original_tokenizer.eos_token_id\n", " )\n", " response_orig = original_tokenizer.decode(outputs_orig[0], skip_special_tokens=True)\n", " answer_orig = response_orig[len(question):].strip()\n", - " print(f\"💬 Réponse du modèle ORIGINAL : {answer_orig}\")\n", + " print(f\"💬 Response from ORIGINAL model : {answer_orig}\")\n", " \n", - " # Réponse du modèle FINE-TUNÉ\n", + " # Response from the FINE-TUNED model\n", " inputs_fine = fine_tuned_tokenizer.encode(question, return_tensors='pt')\n", " outputs_fine = fine_tuned_model.generate(\n", " inputs_fine,\n", - " max_length=50, # Longueur maximale de la réponse\n", - " num_return_sequences=1, # Une seule réponse\n", - " temperature=0.1, # Créativité modérée\n", - " do_sample=True, # Utiliser le sampling\n", + " max_length=50, # Maximum length of the response\n", + " num_return_sequences=1, # Single response\n", + " temperature=0.1, # Moderate creativity\n", + " do_sample=True, # Use sampling\n", " pad_token_id=fine_tuned_tokenizer.eos_token_id\n", " )\n", " response_fine = fine_tuned_tokenizer.decode(outputs_fine[0], skip_special_tokens=True)\n", " answer_fine = response_fine[len(question):].strip()\n", - " print(f\"💬 Réponse du modèle FINE-TUNÉ : {answer_fine}\")\n", + " print(f\"💬 Response from FINE-TUNED model : {answer_fine}\")\n", " \n", " print(\"-\" * 60)\n", "\n", "print(\"\\n\" + \"=\" * 60)\n", - "print(\"\\n🎉 Félicitations ! Vous avez terminé le fine-tuning d'un modèle LLM !\")\n", - "print(\"\\nCe que vous avez accompli :\")\n", - "print(\" ✅ Vous avez chargé un modèle pré-entraîné\")\n", - "print(\" ✅ Vous avez préparé vos propres données\")\n", - "print(\" ✅ Vous avez tokenisé les données\")\n", - "print(\" ✅ Vous avez configuré l'entraînement\")\n", - "print(\" ✅ Vous avez fine-tuné le modèle\")\n", - "print(\" ✅ Vous avez testé le modèle et vu la différence !\")\n", - "print(\"\\n🚀 Maintenant vous savez comment adapter un modèle AI à votre domaine spécifique !\")\n" + "print(\"\\n🎉 Congratulations! You have completed fine-tuning an LLM model!\")\n", + "print(\"\\nWhat you have accomplished:\")\n", + "print(\" ✅ You loaded a pre-trained model\")\n", + "print(\" ✅ You prepared your own data\")\n", + "print(\" ✅ You tokenized the data\")\n", + "print(\" ✅ You configured the training\")\n", + "print(\" ✅ You fine-tuned the model\")\n", + "print(\" ✅ You tested the model and saw the difference!\")\n", + "print(\"\\n🚀 Now you know how to adapt an AI model to your specific domain!\")\n" ] }, {