File size: 36,085 Bytes
03d7ca5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5946df15",
   "metadata": {},
   "source": [
    "# Example of use of ToxiFrench model"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "209da6d2",
   "metadata": {},
   "source": [
    "## Libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e421addd",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig\n",
    "from peft import PeftModel\n",
    "from rich.console import Console\n",
    "from rich.panel import Panel\n",
    "import os "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "332b3f5c",
   "metadata": {},
   "source": [
    "## Global settings and variables"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a14bba57",
   "metadata": {},
   "outputs": [],
   "source": [
    "# If you are using a proxy, set it up here (optional, you can comment these lines if not needed)\n",
    "os.environ[\"HTTP_PROXY\"] = \"socks5h://127.0.0.1:1080\"\n",
    "os.environ[\"HTTPS_PROXY\"] = \"socks5h://127.0.0.1:1080\"\n",
    "\n",
    "# Choose which adapter to load\n",
    "target_adapter_name = \"rec\" # Among the following six configurations : \"odc\", \"oeb\", \"oec\", \"rdc\", \"reb\", \"rec\"\n",
    "\n",
    "# Load the base model\n",
    "base_model_name = \"Qwen/Qwen3-4B\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b2a86231",
   "metadata": {},
   "outputs": [],
   "source": [
    "console = Console()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3bbaa5bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "bnb_config = BitsAndBytesConfig(**{\n",
    "            \"load_in_4bit\": True,\n",
    "            \"bnb_4bit_use_double_quant\": True,\n",
    "            \"bnb_4bit_quant_type\": \"nf4\",\n",
    "            \"bnb_4bit_compute_dtype\": torch.float16\n",
    "        })"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "560465f5",
   "metadata": {},
   "source": [
    "## Load the model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "44494b9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "tokenizer = AutoTokenizer.from_pretrained(\n",
    "                base_model_name,\n",
    "                use_fast=True,\n",
    "                trust_remote_code=True\n",
    "            )\n",
    "\n",
    "if tokenizer.pad_token is None:\n",
    "    tokenizer.pad_token = tokenizer.eos_token\n",
    "    print(\"Tokenizer `pad_token` was None, set to `eos_token`.\")\n",
    "\n",
    "tokenizer.padding_side = 'left' "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4b90a147",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "6796b5b76bc2493daf8fdc0169de053f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Loading checkpoint shards:   0%|          | 0/3 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "model = AutoModelForCausalLM.from_pretrained(\n",
    "                base_model_name,\n",
    "                quantization_config=bnb_config,\n",
    "                trust_remote_code=True,\n",
    "                sliding_window=None,\n",
    "            )\n",
    "if model.generation_config.pad_token_id is None and tokenizer.pad_token_id is not None:\n",
    "    model.generation_config.pad_token_id = tokenizer.pad_token_id\n",
    "    print(\"Model `generation_config.pad_token_id` set from tokenizer.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "5c105265",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #808000; text-decoration-color: #808000\">Warning: Vocab size mismatch.</span>Model embeddings: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">151936</span>, Tokenizer vocab: <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">151669</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[33mWarning: Vocab size mismatch.\u001b[0mModel embeddings: \u001b[1;36m151936\u001b[0m, Tokenizer vocab: \u001b[1;36m151669\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">Resizing model token embeddings to match tokenizer<span style=\"color: #808000; text-decoration-color: #808000\">...</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "Resizing model token embeddings to match tokenizer\u001b[33m...\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000; font-weight: bold\">Resized model embeddings to: </span><span style=\"color: #008000; text-decoration-color: #008000; font-weight: bold\">151669</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1;32mResized model embeddings to: \u001b[0m\u001b[1;32m151669\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "special_tokens_to_add = {\n",
    "            \"additional_special_tokens\": [\n",
    "            ]\n",
    "        }\n",
    "tokenizer.add_special_tokens(special_tokens_to_add)\n",
    "\n",
    "model_embedding_size = model.get_input_embeddings().weight.size(0)\n",
    "tokenizer_vocab_size = len(tokenizer)\n",
    "\n",
    "if model_embedding_size != tokenizer_vocab_size:\n",
    "    console.print(f\"[yellow]Warning: Vocab size mismatch.[/yellow]\"\n",
    "          f\"Model embeddings: {model_embedding_size}, \"\n",
    "          f\"Tokenizer vocab: {tokenizer_vocab_size}\")\n",
    "    console.print(\"Resizing model token embeddings to match tokenizer...\")\n",
    "    model.resize_token_embeddings(tokenizer_vocab_size)\n",
    "\n",
    "    # Verify the resize\n",
    "    new_embedding_size = model.get_input_embeddings().weight.size(0)\n",
    "    console.print(f\"[bold green]Resized model embeddings to: {new_embedding_size}[/bold green]\")\n",
    "else:\n",
    "    console.print(\"Model embedding size and tokenizer vocabulary size are already aligned.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "ed574fee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Successfully loaded the 'rec' adapter!\n"
     ]
    }
   ],
   "source": [
    "# Load the specific adapter by name from the repository\n",
    "adapter_repo_id = \"Naela00/ToxiFrench\"\n",
    "model = PeftModel.from_pretrained(\n",
    "    model,\n",
    "    adapter_repo_id,\n",
    "    subfolder=target_adapter_name\n",
    ")\n",
    "\n",
    "print(f\"Successfully loaded the '{target_adapter_name}' adapter!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7e4e92f5",
   "metadata": {},
   "source": [
    "## Example of inference"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "74b03044",
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt = \"Message:\\nputain mais elle est vraiment grand remplacรฉe vot ville\\n\\nAnalyse:\\n\"\n",
    "if \"c\" in target_adapter_name:\n",
    "    prompt += \"<think>\\nExplication :\\n\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "74e4a114",
   "metadata": {},
   "outputs": [],
   "source": [
    "max_new_tokens: int = 1024\n",
    "do_sample: bool = True\n",
    "temperature: float = 0.7\n",
    "top_p: float = 0.9\n",
    "top_k: int = 50\n",
    "repetition_penalty: float = 1.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "6d73a27e",
   "metadata": {},
   "outputs": [],
   "source": [
    "inputs = tokenizer(\n",
    "    prompt,\n",
    "    return_tensors=\"pt\",\n",
    "    padding=True,\n",
    "    truncation=True\n",
    ").to(model.device)\n",
    "\n",
    "default_generation_kwargs = {\n",
    "    \"max_new_tokens\": max_new_tokens,\n",
    "    \"do_sample\": do_sample,\n",
    "    \"temperature\": temperature,\n",
    "    \"top_p\": top_p,\n",
    "    \"top_k\": top_k,\n",
    "    \"repetition_penalty\": repetition_penalty,\n",
    "    \"eos_token_id\": tokenizer.eos_token_id,\n",
    "}\n",
    "\n",
    "outputs = model.generate(**inputs, **default_generation_kwargs)\n",
    "generated_text = tokenizer.decode(outputs[0], skip_special_tokens=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "8f5c58a9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #00ff00; text-decoration-color: #00ff00\">โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ </span><span style=\"color: #800080; text-decoration-color: #800080; font-weight: bold\">Model Output</span><span style=\"color: #00ff00; text-decoration-color: #00ff00\"> โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[92mโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ \u001b[0m\u001b[1;35mModel Output\u001b[0m\u001b[92m โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n",
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€</span> Generated Text <span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ Message:                                                                                                        โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ putain mais elle est vraiment grand remplacรฉe vot ville                                                         โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚                                                                                                                 โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ Analyse:                                                                                                        โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ &lt;think&gt;                                                                                                         โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ Explication :                                                                                                   โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ **Sujet du message :** Remplacement d'une personne dans une situation.                                          โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚                                                                                                                 โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ **Rรฉsumรฉ et explication :** L'auteur exprime son indignation ou sa surprise face ร  un remplacement, en          โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ utilisant le terme \"grand\" qui pourrait indiquer une grande importance. Le contexte n'est pas prรฉcisรฉ.          โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ &lt;/think&gt;                                                                                                        โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ &lt;think&gt;                                                                                                         โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ Tons :                                                                                                          โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ Les tons perรงus sont :                                                                                          โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚                                                                                                                 โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ 1. **Indignรฉ (certitude รฉlevรฉe)** - L'utilisation de ยซ putain ยป montre une frustration claire face au           โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ remplacement.                                                                                                   โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ 2. **Surpris (certitude modรฉrรฉe)** - L'expression ยซ mais elle est vraiment ยป suggรจre une surprise quant ร  la    โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ situation.                                                                                                      โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ 3. **Informel (certitude รฉlevรฉe)** - Le langage familier et l'absence de formalitรฉ renforcent ce ton.           โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚                                                                                                                 โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ Doutes sur la signification exacte des termes, notamment ยซ grand ยป, pouvant indiquer une opinion personnelle.   โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ &lt;/think&gt;                                                                                                        โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ &lt;think&gt;                                                                                                         โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ Labels :                                                                                                        โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ S0/H0/V0/R0/A0/I2                                                                                               โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚                                                                                                                 โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ Justification :                                                                                                 โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ Le message contient une vulgaritรฉ lรฉgรจre avec un ton informel, sans allusion sexuelle ni violence, et manifeste โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ une critique moqueuse ou dรฉsapprobatrice sans intention hostile directe.                                        โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ &lt;/think&gt;                                                                                                        โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ &lt;think&gt;                                                                                                         โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ Score de toxicitรฉ :                                                                                             โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ 4/10                                                                                                            โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚                                                                                                                 โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ Justification :                                                                                                 โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ Vulgaritรฉ et condescendance prรฉsentes, mais sans haine explicite ni incitation grave. Ton moqueur peut heurter  โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ certaines sensibilitรฉs, mais reste limitรฉ.                                                                      โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ &lt;/think&gt;                                                                                                        โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚                                                                                                                 โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ En conclusion, ce message est-il toxique ?                                                                      โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚                                                                                                                 โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ”‚ non&lt;|im_end|&gt;                                                                                                   โ”‚</span>\n",
       "<span style=\"color: #c0c0c0; text-decoration-color: #c0c0c0; background-color: #000000; font-weight: bold\">โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[1;37;40mโ•ญโ”€\u001b[0m\u001b[1;37;40mโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\u001b[0m Generated Text \u001b[1;37;40mโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€\u001b[0m\u001b[1;37;40mโ”€โ•ฎ\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mMessage:\u001b[0m\u001b[1;37;40m                                                                                                       \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mputain mais elle est vraiment grand remplacรฉe vot ville\u001b[0m\u001b[1;37;40m                                                        \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m                                                                                                               \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mAnalyse:\u001b[0m\u001b[1;37;40m                                                                                                       \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m<think>\u001b[0m\u001b[1;37;40m                                                                                                        \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mExplication :\u001b[0m\u001b[1;37;40m                                                                                                  \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m**Sujet du message :** Remplacement d'une personne dans une situation.\u001b[0m\u001b[1;37;40m                                         \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m                                                                                                               \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m**Rรฉsumรฉ et explication :** L'auteur exprime son indignation ou sa surprise face ร  un remplacement, en \u001b[0m\u001b[1;37;40m        \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mutilisant le terme \"grand\" qui pourrait indiquer une grande importance. Le contexte n'est pas prรฉcisรฉ.\u001b[0m\u001b[1;37;40m         \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m</think>\u001b[0m\u001b[1;37;40m                                                                                                       \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m<think>\u001b[0m\u001b[1;37;40m                                                                                                        \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mTons :\u001b[0m\u001b[1;37;40m                                                                                                         \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mLes tons perรงus sont :\u001b[0m\u001b[1;37;40m                                                                                         \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m                                                                                                               \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m1. **Indignรฉ (certitude รฉlevรฉe)** - L'utilisation de ยซ putain ยป montre une frustration claire face au \u001b[0m\u001b[1;37;40m         \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mremplacement.\u001b[0m\u001b[1;37;40m                                                                                                  \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m2. **Surpris (certitude modรฉrรฉe)** - L'expression ยซ mais elle est vraiment ยป suggรจre une surprise quant ร  la \u001b[0m\u001b[1;37;40m  \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40msituation.\u001b[0m\u001b[1;37;40m                                                                                                     \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m3. **Informel (certitude รฉlevรฉe)** - Le langage familier et l'absence de formalitรฉ renforcent ce ton.\u001b[0m\u001b[1;37;40m          \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m                                                                                                               \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mDoutes sur la signification exacte des termes, notamment ยซ grand ยป, pouvant indiquer une opinion personnelle.\u001b[0m\u001b[1;37;40m  \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m</think>\u001b[0m\u001b[1;37;40m                                                                                                       \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m<think>\u001b[0m\u001b[1;37;40m                                                                                                        \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mLabels :\u001b[0m\u001b[1;37;40m                                                                                                       \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mS0/H0/V0/R0/A0/I2\u001b[0m\u001b[1;37;40m                                                                                              \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m                                                                                                               \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mJustification :\u001b[0m\u001b[1;37;40m                                                                                                \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mLe message contient une vulgaritรฉ lรฉgรจre avec un ton informel, sans allusion sexuelle ni violence, et manifeste\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mune critique moqueuse ou dรฉsapprobatrice sans intention hostile directe.\u001b[0m\u001b[1;37;40m                                       \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m</think>\u001b[0m\u001b[1;37;40m                                                                                                       \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m<think>\u001b[0m\u001b[1;37;40m                                                                                                        \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mScore de toxicitรฉ :\u001b[0m\u001b[1;37;40m                                                                                            \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m4/10\u001b[0m\u001b[1;37;40m                                                                                                           \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m                                                                                                               \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mJustification :\u001b[0m\u001b[1;37;40m                                                                                                \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mVulgaritรฉ et condescendance prรฉsentes, mais sans haine explicite ni incitation grave. Ton moqueur peut heurter \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mcertaines sensibilitรฉs, mais reste limitรฉ.\u001b[0m\u001b[1;37;40m                                                                     \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m</think>\u001b[0m\u001b[1;37;40m                                                                                                       \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m                                                                                                               \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mEn conclusion, ce message est-il toxique ?\u001b[0m\u001b[1;37;40m                                                                     \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40m                                                                                                               \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ”‚\u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mnon<|im_end|>\u001b[0m\u001b[1;37;40m                                                                                                  \u001b[0m\u001b[1;37;40m \u001b[0m\u001b[1;37;40mโ”‚\u001b[0m\n",
       "\u001b[1;37;40mโ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "console.rule(\"[bold magenta]Model Output\")\n",
    "console.print('\\n')\n",
    "console.print(Panel.fit(generated_text, title=\"Generated Text\", style=\"bold white on black\"))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "SJTU",
   "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.10.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}