Spaces:
Sleeping
Sleeping
File size: 149,565 Bytes
04b64a8 |
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 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"source": [],
"outputs": [],
"metadata": {
"id": "eACAbEZnCeV3"
}
},
{
"cell_type": "markdown",
"source": [
"# Hallucination des LLMs:\n",
"Bienvenue dans ce Travaux Pratiques (TP) où nous allons explorer le phénomène intrigant des hallucinations des LLMs. Les hallucinations, généralement associées à des conditions neurologiques ou psychiatriques, sont des perceptions qui n'ont pas de base dans la réalité. Cependant, dans le contexte des LLMs, ces perceptions prennent une toute nouvelle dimension.\n",
"\n",
"Les LLMs sont des modèles d'apprentissage automatique qui sont entraînés sur d'énormes quantités de texte. Ils apprennent à prédire le texte suivant sur la base du texte précédent, ce qui leur permet de générer des phrases et des paragraphes qui semblent logiques et cohérents. Cependant, comme tout modèle d'apprentissage automatique, les LLMs peuvent parfois faire des erreurs, ou \"halluciner\", en générant du texte qui n'a pas de sens, qui est complètement déconnecté du contexte donné ou qui n'est pas factuel.\n",
"\n",
"Dans ce TP, nous allons plonger dans le monde fascinant des LLMs et de leurs hallucinations. Nous allons explorer comment ces modèles fonctionnent, pourquoi ils hallucinent, et comment nous pouvons détecter.\n",
"\n",
"Avant de nous plonger dans l'univers fascinant des LLMs, il y a quelques préparations à faire. Pour assurer le bon déroulement de ce TP, vous devrez d'abord télécharger:"
],
"metadata": {
"id": "YoJL60i929Li"
}
},
{
"cell_type": "code",
"execution_count": 1,
"source": [
"!pip install langchain\n",
"!pip install langchain_community\n",
"!pip install nltk\n",
"!pip install llama-cpp-python\n",
"#!CMAKE_ARGS=\"-DLLAMA_CUBLAS=on\" FORCE_CMAKE=1 pip install llama-cpp-python --no-cache-dir"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Collecting langchain\n",
" Downloading langchain-0.2.2-py3-none-any.whl (973 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m973.6/973.6 kB\u001b[0m \u001b[31m4.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: PyYAML>=5.3 in /usr/local/lib/python3.10/dist-packages (from langchain) (6.0.1)\n",
"Requirement already satisfied: SQLAlchemy<3,>=1.4 in /usr/local/lib/python3.10/dist-packages (from langchain) (2.0.30)\n",
"Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in /usr/local/lib/python3.10/dist-packages (from langchain) (3.9.5)\n",
"Requirement already satisfied: async-timeout<5.0.0,>=4.0.0 in /usr/local/lib/python3.10/dist-packages (from langchain) (4.0.3)\n",
"Collecting langchain-core<0.3.0,>=0.2.0 (from langchain)\n",
" Downloading langchain_core-0.2.4-py3-none-any.whl (310 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m310.4/310.4 kB\u001b[0m \u001b[31m26.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hCollecting langchain-text-splitters<0.3.0,>=0.2.0 (from langchain)\n",
" Downloading langchain_text_splitters-0.2.1-py3-none-any.whl (23 kB)\n",
"Collecting langsmith<0.2.0,>=0.1.17 (from langchain)\n",
" Downloading langsmith-0.1.71-py3-none-any.whl (124 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m124.6/124.6 kB\u001b[0m \u001b[31m10.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: numpy<2,>=1 in /usr/local/lib/python3.10/dist-packages (from langchain) (1.25.2)\n",
"Requirement already satisfied: pydantic<3,>=1 in /usr/local/lib/python3.10/dist-packages (from langchain) (2.7.2)\n",
"Requirement already satisfied: requests<3,>=2 in /usr/local/lib/python3.10/dist-packages (from langchain) (2.31.0)\n",
"Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /usr/local/lib/python3.10/dist-packages (from langchain) (8.3.0)\n",
"Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.3.1)\n",
"Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (23.2.0)\n",
"Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.4.1)\n",
"Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (6.0.5)\n",
"Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain) (1.9.4)\n",
"Collecting jsonpatch<2.0,>=1.33 (from langchain-core<0.3.0,>=0.2.0->langchain)\n",
" Downloading jsonpatch-1.33-py2.py3-none-any.whl (12 kB)\n",
"Collecting packaging<24.0,>=23.2 (from langchain-core<0.3.0,>=0.2.0->langchain)\n",
" Downloading packaging-23.2-py3-none-any.whl (53 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.0/53.0 kB\u001b[0m \u001b[31m6.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hCollecting orjson<4.0.0,>=3.9.14 (from langsmith<0.2.0,>=0.1.17->langchain)\n",
" Downloading orjson-3.10.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m142.5/142.5 kB\u001b[0m \u001b[31m2.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1->langchain) (0.7.0)\n",
"Requirement already satisfied: pydantic-core==2.18.3 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1->langchain) (2.18.3)\n",
"Requirement already satisfied: typing-extensions>=4.6.1 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1->langchain) (4.12.0)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (3.3.2)\n",
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (3.7)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (2.0.7)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain) (2024.2.2)\n",
"Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy<3,>=1.4->langchain) (3.0.3)\n",
"Collecting jsonpointer>=1.9 (from jsonpatch<2.0,>=1.33->langchain-core<0.3.0,>=0.2.0->langchain)\n",
" Downloading jsonpointer-2.4-py2.py3-none-any.whl (7.8 kB)\n",
"Installing collected packages: packaging, orjson, jsonpointer, jsonpatch, langsmith, langchain-core, langchain-text-splitters, langchain\n",
" Attempting uninstall: packaging\n",
" Found existing installation: packaging 24.0\n",
" Uninstalling packaging-24.0:\n",
" Successfully uninstalled packaging-24.0\n",
"Successfully installed jsonpatch-1.33 jsonpointer-2.4 langchain-0.2.2 langchain-core-0.2.4 langchain-text-splitters-0.2.1 langsmith-0.1.71 orjson-3.10.3 packaging-23.2\n",
"Collecting langchain_community\n",
" Downloading langchain_community-0.2.2-py3-none-any.whl (2.2 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.2/2.2 MB\u001b[0m \u001b[31m8.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: PyYAML>=5.3 in /usr/local/lib/python3.10/dist-packages (from langchain_community) (6.0.1)\n",
"Requirement already satisfied: SQLAlchemy<3,>=1.4 in /usr/local/lib/python3.10/dist-packages (from langchain_community) (2.0.30)\n",
"Requirement already satisfied: aiohttp<4.0.0,>=3.8.3 in /usr/local/lib/python3.10/dist-packages (from langchain_community) (3.9.5)\n",
"Collecting dataclasses-json<0.7,>=0.5.7 (from langchain_community)\n",
" Downloading dataclasses_json-0.6.6-py3-none-any.whl (28 kB)\n",
"Requirement already satisfied: langchain<0.3.0,>=0.2.0 in /usr/local/lib/python3.10/dist-packages (from langchain_community) (0.2.2)\n",
"Requirement already satisfied: langchain-core<0.3.0,>=0.2.0 in /usr/local/lib/python3.10/dist-packages (from langchain_community) (0.2.4)\n",
"Requirement already satisfied: langsmith<0.2.0,>=0.1.0 in /usr/local/lib/python3.10/dist-packages (from langchain_community) (0.1.71)\n",
"Requirement already satisfied: numpy<2,>=1 in /usr/local/lib/python3.10/dist-packages (from langchain_community) (1.25.2)\n",
"Requirement already satisfied: requests<3,>=2 in /usr/local/lib/python3.10/dist-packages (from langchain_community) (2.31.0)\n",
"Requirement already satisfied: tenacity<9.0.0,>=8.1.0 in /usr/local/lib/python3.10/dist-packages (from langchain_community) (8.3.0)\n",
"Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (1.3.1)\n",
"Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (23.2.0)\n",
"Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (1.4.1)\n",
"Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (6.0.5)\n",
"Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (1.9.4)\n",
"Requirement already satisfied: async-timeout<5.0,>=4.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp<4.0.0,>=3.8.3->langchain_community) (4.0.3)\n",
"Collecting marshmallow<4.0.0,>=3.18.0 (from dataclasses-json<0.7,>=0.5.7->langchain_community)\n",
" Downloading marshmallow-3.21.2-py3-none-any.whl (49 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m49.3/49.3 kB\u001b[0m \u001b[31m6.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hCollecting typing-inspect<1,>=0.4.0 (from dataclasses-json<0.7,>=0.5.7->langchain_community)\n",
" Downloading typing_inspect-0.9.0-py3-none-any.whl (8.8 kB)\n",
"Requirement already satisfied: langchain-text-splitters<0.3.0,>=0.2.0 in /usr/local/lib/python3.10/dist-packages (from langchain<0.3.0,>=0.2.0->langchain_community) (0.2.1)\n",
"Requirement already satisfied: pydantic<3,>=1 in /usr/local/lib/python3.10/dist-packages (from langchain<0.3.0,>=0.2.0->langchain_community) (2.7.2)\n",
"Requirement already satisfied: jsonpatch<2.0,>=1.33 in /usr/local/lib/python3.10/dist-packages (from langchain-core<0.3.0,>=0.2.0->langchain_community) (1.33)\n",
"Requirement already satisfied: packaging<24.0,>=23.2 in /usr/local/lib/python3.10/dist-packages (from langchain-core<0.3.0,>=0.2.0->langchain_community) (23.2)\n",
"Requirement already satisfied: orjson<4.0.0,>=3.9.14 in /usr/local/lib/python3.10/dist-packages (from langsmith<0.2.0,>=0.1.0->langchain_community) (3.10.3)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain_community) (3.3.2)\n",
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain_community) (3.7)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain_community) (2.0.7)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2->langchain_community) (2024.2.2)\n",
"Requirement already satisfied: typing-extensions>=4.6.0 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy<3,>=1.4->langchain_community) (4.12.0)\n",
"Requirement already satisfied: greenlet!=0.4.17 in /usr/local/lib/python3.10/dist-packages (from SQLAlchemy<3,>=1.4->langchain_community) (3.0.3)\n",
"Requirement already satisfied: jsonpointer>=1.9 in /usr/local/lib/python3.10/dist-packages (from jsonpatch<2.0,>=1.33->langchain-core<0.3.0,>=0.2.0->langchain_community) (2.4)\n",
"Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1->langchain<0.3.0,>=0.2.0->langchain_community) (0.7.0)\n",
"Requirement already satisfied: pydantic-core==2.18.3 in /usr/local/lib/python3.10/dist-packages (from pydantic<3,>=1->langchain<0.3.0,>=0.2.0->langchain_community) (2.18.3)\n",
"Collecting mypy-extensions>=0.3.0 (from typing-inspect<1,>=0.4.0->dataclasses-json<0.7,>=0.5.7->langchain_community)\n",
" Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)\n",
"Installing collected packages: mypy-extensions, marshmallow, typing-inspect, dataclasses-json, langchain_community\n",
"Successfully installed dataclasses-json-0.6.6 langchain_community-0.2.2 marshmallow-3.21.2 mypy-extensions-1.0.0 typing-inspect-0.9.0\n",
"Requirement already satisfied: nltk in /usr/local/lib/python3.10/dist-packages (3.8.1)\n",
"Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk) (8.1.7)\n",
"Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk) (1.4.2)\n",
"Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.10/dist-packages (from nltk) (2024.5.15)\n",
"Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from nltk) (4.66.4)\n",
"Collecting llama-cpp-python\n",
" Downloading llama_cpp_python-0.2.77.tar.gz (50.2 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m50.2/50.2 MB\u001b[0m \u001b[31m12.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25h Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
" Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
" Installing backend dependencies ... \u001b[?25l\u001b[?25hdone\n",
" Preparing metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
"Requirement already satisfied: typing-extensions>=4.5.0 in /usr/local/lib/python3.10/dist-packages (from llama-cpp-python) (4.12.0)\n",
"Requirement already satisfied: numpy>=1.20.0 in /usr/local/lib/python3.10/dist-packages (from llama-cpp-python) (1.25.2)\n",
"Collecting diskcache>=5.6.1 (from llama-cpp-python)\n",
" Downloading diskcache-5.6.3-py3-none-any.whl (45 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m45.5/45.5 kB\u001b[0m \u001b[31m5.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: jinja2>=2.11.3 in /usr/local/lib/python3.10/dist-packages (from llama-cpp-python) (3.1.4)\n",
"Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2>=2.11.3->llama-cpp-python) (2.1.5)\n",
"Building wheels for collected packages: llama-cpp-python\n",
" Building wheel for llama-cpp-python (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
" Created wheel for llama-cpp-python: filename=llama_cpp_python-0.2.77-cp310-cp310-linux_x86_64.whl size=3695651 sha256=2f9ad16bd71a8167f411871b512035d8ebb40f229341194c0c967faaf18a0287\n",
" Stored in directory: /root/.cache/pip/wheels/ed/55/a1/6d6c2ef6fed3ef054b4170d8bcd05a09e6dc971db7fad955ff\n",
"Successfully built llama-cpp-python\n",
"Installing collected packages: diskcache, llama-cpp-python\n",
"Successfully installed diskcache-5.6.3 llama-cpp-python-0.2.77\n"
]
}
],
"metadata": {
"id": "fWIY5wkg-7qH",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "6611598f-753f-4662-a5e7-4570e0e6a95d"
}
},
{
"cell_type": "markdown",
"source": [
"Une fois que vous avez téléchargé les dépendances, vous pouvez ensuite les importer dans votre notebook:"
],
"metadata": {
"id": "UsA_d8iF_MQz"
}
},
{
"cell_type": "code",
"execution_count": 2,
"source": [
"from langchain.llms import LlamaCpp\n",
"from langchain.chains import LLMChain\n",
"from langchain.prompts import PromptTemplate\n",
"from llama_cpp import Llama\n",
"from math import *\n",
"import numpy as np"
],
"outputs": [],
"metadata": {
"id": "lFMBol-J-5RE"
}
},
{
"cell_type": "markdown",
"source": [
"Enfin, pour étudier les hallucinations, nous utiliserons le modèle mistral-7B quantizé, que vous pouvez téléchargé avec la cellule ci-dessous:"
],
"metadata": {
"id": "EgEyVKDF_wFG"
}
},
{
"cell_type": "code",
"execution_count": 3,
"source": [
"!huggingface-cli download TheBloke/Mistral-7B-Instruct-v0.2-GGUF mistral-7b-instruct-v0.2.Q4_K_M.gguf --local-dir . --local-dir-use-symlinks False"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"/usr/local/lib/python3.10/dist-packages/huggingface_hub/commands/download.py:132: FutureWarning: Ignoring --local-dir-use-symlinks. Downloading to a local directory does not use symlinks anymore.\n",
" warnings.warn(\n",
"Downloading 'mistral-7b-instruct-v0.2.Q4_K_M.gguf' to '.huggingface/download/mistral-7b-instruct-v0.2.Q4_K_M.gguf.3e0039fd0273fcbebb49228943b17831aadd55cbcbf56f0af00499be2040ccf9.incomplete'\n",
"mistral-7b-instruct-v0.2.Q4_K_M.gguf: 100% 4.37G/4.37G [00:28<00:00, 152MB/s]\n",
"Download complete. Moving file to mistral-7b-instruct-v0.2.Q4_K_M.gguf\n",
"mistral-7b-instruct-v0.2.Q4_K_M.gguf\n"
]
}
],
"metadata": {
"id": "A8lwhaDf_n3n",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "312e58cc-a916-4d2c-8431-57c7011360dc"
}
},
{
"cell_type": "markdown",
"source": [
"Nous pouvons donc commencer !!\n",
"\n",
"#I. Detection d'hallucination:\n",
"\n",
"Maintenant que nous avons nos dépendances en place, il est temps de nous plonger dans le cœur du sujet : les hallucinations des LLMs. Mais qu'est-ce qu'une hallucination dans ce contexte ?\n",
"\n",
"Une hallucination, dans le domaine des LLMs, se produit lorsque le modèle génère du texte qui n'a pas de sens ou qui est complètement déconnecté du contexte donné. C'est comme si le modèle \"voyait\" ou \"imaginait\" des choses qui ne sont pas réellement présentes dans les données.\n",
"\n",
"Plusieurs facteurs peuvent contribuer à ces hallucinations :\n",
"\n",
"\n",
"1. Biais du dataset : Si le jeu de données d'entraînement est biaisé d'une\n",
"certaine manière, le modèle apprendra ces biais et les reproduira dans ses prédictions. Par exemple, si le jeu de données contient principalement des exemples positifs, le modèle peut \"halluciner\" des résultats positifs même dans des situations où ils ne sont pas appropriés.\n",
"\n",
"2. Overfitting : Cela se produit lorsque le modèle est trop complexe par rapport à la quantité et à la variété des données d'entraînement disponibles. Dans ce cas, le modèle peut \"apprendre par cœur\" les données d'entraînement et avoir du mal à généraliser à de nouvelles situations, ce qui peut conduire à des hallucinations.\n",
"\n",
"3. Non accès à l'information : Les LLMs ne disposent pas d'un accès direct à l'information du monde réel. Ils ne peuvent générer du texte qu'en se basant sur ce qu'ils ont appris lors de leur entraînement. Par conséquent, ils peuvent halluciner des informations qu'ils n'ont pas ou mal interpréter les informations qu'ils ont..\n",
"\n",
"Pour notre étude, nous allons nous concentrer sur le dernier point : le manque d'accès à l'information par les LLMs. Dans la pratique, cela signifie que lorsque le modèle n'a pas accès à une information spécifique, il ne peut pas être sûr de ses prédictions.\n",
"\n",
"Lorsqu'un LLM n'est pas sûr de la prédiction qu'il doit faire, la distribution de probabilité des prochains tokens qu'il prédit sera plus \"plate\".\n",
"\n",
"Cela peut sembler un peu abstrait, mais ne vous inquiétez pas, tout deviendra clair lorsque nous commencerons à travailler avec les données. En étudiant les logprobs - les logarithmes des probabilités - des tokens générés par le modèle, nous pouvons mesurer la certitude du modèle. Plus la distribution de probabilité est \"plate\", moins le modèle est sûr de lui. Mettons en évidence cela:"
],
"metadata": {
"id": "wcps2JLDAZCz"
}
},
{
"cell_type": "code",
"execution_count": 4,
"source": [
"def load_llm(model_path):\n",
"\n",
"\t\t# On charge le LLM sous format quantisé. Cf la descriptions des paramètres ci-dessous.\n",
" llm = Llama(\n",
" model_path=model_path, stop=[\"Question\"], max_tokens=200, temperature=0.2,\n",
"\t\t\t\tn_ctx=8000, n_batch=1024, n_gpu_layers=-1, logits_all=True\n",
" )\n",
"\n",
" return llm\n",
"\n",
"llm = load_llm(\"mistral-7b-instruct-v0.2.Q4_K_M.gguf\")\n",
"\n",
"def gen(prompt):\n",
" output = llm.create_completion(prompt,\n",
" max_tokens = 5,\n",
" echo = False,\n",
" temperature = 0,\n",
" logprobs =100,\n",
" ) # to return top 5 tokens\n",
"\n",
" return output\n",
"\n",
"results1 = gen(\"Lionel Messi is a \")\n",
"print(results1)"
],
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"llama_model_loader: loaded meta data with 24 key-value pairs and 291 tensors from mistral-7b-instruct-v0.2.Q4_K_M.gguf (version GGUF V3 (latest))\n",
"llama_model_loader: Dumping metadata keys/values. Note: KV overrides do not apply in this output.\n",
"llama_model_loader: - kv 0: general.architecture str = llama\n",
"llama_model_loader: - kv 1: general.name str = mistralai_mistral-7b-instruct-v0.2\n",
"llama_model_loader: - kv 2: llama.context_length u32 = 32768\n",
"llama_model_loader: - kv 3: llama.embedding_length u32 = 4096\n",
"llama_model_loader: - kv 4: llama.block_count u32 = 32\n",
"llama_model_loader: - kv 5: llama.feed_forward_length u32 = 14336\n",
"llama_model_loader: - kv 6: llama.rope.dimension_count u32 = 128\n",
"llama_model_loader: - kv 7: llama.attention.head_count u32 = 32\n",
"llama_model_loader: - kv 8: llama.attention.head_count_kv u32 = 8\n",
"llama_model_loader: - kv 9: llama.attention.layer_norm_rms_epsilon f32 = 0.000010\n",
"llama_model_loader: - kv 10: llama.rope.freq_base f32 = 1000000.000000\n",
"llama_model_loader: - kv 11: general.file_type u32 = 15\n",
"llama_model_loader: - kv 12: tokenizer.ggml.model str = llama\n",
"llama_model_loader: - kv 13: tokenizer.ggml.tokens arr[str,32000] = [\"<unk>\", \"<s>\", \"</s>\", \"<0x00>\", \"<...\n",
"llama_model_loader: - kv 14: tokenizer.ggml.scores arr[f32,32000] = [0.000000, 0.000000, 0.000000, 0.0000...\n",
"llama_model_loader: - kv 15: tokenizer.ggml.token_type arr[i32,32000] = [2, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, ...\n",
"llama_model_loader: - kv 16: tokenizer.ggml.bos_token_id u32 = 1\n",
"llama_model_loader: - kv 17: tokenizer.ggml.eos_token_id u32 = 2\n",
"llama_model_loader: - kv 18: tokenizer.ggml.unknown_token_id u32 = 0\n",
"llama_model_loader: - kv 19: tokenizer.ggml.padding_token_id u32 = 0\n",
"llama_model_loader: - kv 20: tokenizer.ggml.add_bos_token bool = true\n",
"llama_model_loader: - kv 21: tokenizer.ggml.add_eos_token bool = false\n",
"llama_model_loader: - kv 22: tokenizer.chat_template str = {{ bos_token }}{% for message in mess...\n",
"llama_model_loader: - kv 23: general.quantization_version u32 = 2\n",
"llama_model_loader: - type f32: 65 tensors\n",
"llama_model_loader: - type q4_K: 193 tensors\n",
"llama_model_loader: - type q6_K: 33 tensors\n",
"llm_load_vocab: special tokens cache size = 259\n",
"llm_load_vocab: token to piece cache size = 0.1637 MB\n",
"llm_load_print_meta: format = GGUF V3 (latest)\n",
"llm_load_print_meta: arch = llama\n",
"llm_load_print_meta: vocab type = SPM\n",
"llm_load_print_meta: n_vocab = 32000\n",
"llm_load_print_meta: n_merges = 0\n",
"llm_load_print_meta: n_ctx_train = 32768\n",
"llm_load_print_meta: n_embd = 4096\n",
"llm_load_print_meta: n_head = 32\n",
"llm_load_print_meta: n_head_kv = 8\n",
"llm_load_print_meta: n_layer = 32\n",
"llm_load_print_meta: n_rot = 128\n",
"llm_load_print_meta: n_embd_head_k = 128\n",
"llm_load_print_meta: n_embd_head_v = 128\n",
"llm_load_print_meta: n_gqa = 4\n",
"llm_load_print_meta: n_embd_k_gqa = 1024\n",
"llm_load_print_meta: n_embd_v_gqa = 1024\n",
"llm_load_print_meta: f_norm_eps = 0.0e+00\n",
"llm_load_print_meta: f_norm_rms_eps = 1.0e-05\n",
"llm_load_print_meta: f_clamp_kqv = 0.0e+00\n",
"llm_load_print_meta: f_max_alibi_bias = 0.0e+00\n",
"llm_load_print_meta: f_logit_scale = 0.0e+00\n",
"llm_load_print_meta: n_ff = 14336\n",
"llm_load_print_meta: n_expert = 0\n",
"llm_load_print_meta: n_expert_used = 0\n",
"llm_load_print_meta: causal attn = 1\n",
"llm_load_print_meta: pooling type = 0\n",
"llm_load_print_meta: rope type = 0\n",
"llm_load_print_meta: rope scaling = linear\n",
"llm_load_print_meta: freq_base_train = 1000000.0\n",
"llm_load_print_meta: freq_scale_train = 1\n",
"llm_load_print_meta: n_yarn_orig_ctx = 32768\n",
"llm_load_print_meta: rope_finetuned = unknown\n",
"llm_load_print_meta: ssm_d_conv = 0\n",
"llm_load_print_meta: ssm_d_inner = 0\n",
"llm_load_print_meta: ssm_d_state = 0\n",
"llm_load_print_meta: ssm_dt_rank = 0\n",
"llm_load_print_meta: model type = 7B\n",
"llm_load_print_meta: model ftype = Q4_K - Medium\n",
"llm_load_print_meta: model params = 7.24 B\n",
"llm_load_print_meta: model size = 4.07 GiB (4.83 BPW) \n",
"llm_load_print_meta: general.name = mistralai_mistral-7b-instruct-v0.2\n",
"llm_load_print_meta: BOS token = 1 '<s>'\n",
"llm_load_print_meta: EOS token = 2 '</s>'\n",
"llm_load_print_meta: UNK token = 0 '<unk>'\n",
"llm_load_print_meta: PAD token = 0 '<unk>'\n",
"llm_load_print_meta: LF token = 13 '<0x0A>'\n",
"llm_load_tensors: ggml ctx size = 0.15 MiB\n",
"llm_load_tensors: CPU buffer size = 4165.37 MiB\n",
".................................................................................................\n",
"llama_new_context_with_model: n_ctx = 8000\n",
"llama_new_context_with_model: n_batch = 1024\n",
"llama_new_context_with_model: n_ubatch = 512\n",
"llama_new_context_with_model: flash_attn = 0\n",
"llama_new_context_with_model: freq_base = 1000000.0\n",
"llama_new_context_with_model: freq_scale = 1\n",
"llama_kv_cache_init: CPU KV buffer size = 1000.00 MiB\n",
"llama_new_context_with_model: KV self size = 1000.00 MiB, K (f16): 500.00 MiB, V (f16): 500.00 MiB\n",
"llama_new_context_with_model: CPU output buffer size = 0.12 MiB\n",
"llama_new_context_with_model: CPU compute buffer size = 547.63 MiB\n",
"llama_new_context_with_model: graph nodes = 1030\n",
"llama_new_context_with_model: graph splits = 1\n",
"AVX = 1 | AVX_VNNI = 0 | AVX2 = 1 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | AVX512_BF16 = 0 | FMA = 1 | NEON = 0 | SVE = 0 | ARM_FMA = 0 | F16C = 1 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 0 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 | MATMUL_INT8 = 0 | LLAMAFILE = 1 | \n",
"Model metadata: {'tokenizer.chat_template': \"{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ '[INST] ' + message['content'] + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}\", 'tokenizer.ggml.add_eos_token': 'false', 'tokenizer.ggml.padding_token_id': '0', 'tokenizer.ggml.unknown_token_id': '0', 'tokenizer.ggml.eos_token_id': '2', 'general.architecture': 'llama', 'llama.rope.freq_base': '1000000.000000', 'llama.context_length': '32768', 'general.name': 'mistralai_mistral-7b-instruct-v0.2', 'tokenizer.ggml.add_bos_token': 'true', 'llama.embedding_length': '4096', 'llama.feed_forward_length': '14336', 'llama.attention.layer_norm_rms_epsilon': '0.000010', 'llama.rope.dimension_count': '128', 'tokenizer.ggml.bos_token_id': '1', 'llama.attention.head_count': '32', 'llama.block_count': '32', 'llama.attention.head_count_kv': '8', 'general.quantization_version': '2', 'tokenizer.ggml.model': 'llama', 'general.file_type': '15'}\n",
"Available chat formats from metadata: chat_template.default\n",
"Guessed chat format: mistral-instruct\n",
"\n",
"llama_print_timings: load time = 2950.22 ms\n",
"llama_print_timings: sample time = 2.95 ms / 5 runs ( 0.59 ms per token, 1692.62 tokens per second)\n",
"llama_print_timings: prompt eval time = 2950.12 ms / 8 tokens ( 368.76 ms per token, 2.71 tokens per second)\n",
"llama_print_timings: eval time = 2722.33 ms / 4 runs ( 680.58 ms per token, 1.47 tokens per second)\n",
"llama_print_timings: total time = 5679.56 ms / 12 tokens\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"{'id': 'cmpl-120c3593-d3e4-4a00-a3a9-453f52e5785b', 'object': 'text_completion', 'created': 1717573922, 'model': 'mistral-7b-instruct-v0.2.Q4_K_M.gguf', 'choices': [{'text': '34-year-', 'index': 0, 'logprobs': {'tokens': ['3', '4', '-', 'year', '-'], 'text_offset': [18, 19, 20, 21, 25], 'token_logprobs': [-0.20545948, -1.107614, -0.052979767, -0.0028441001, -0.054006934], 'top_logprobs': [{'3': -0.20545948, '4': -2.1435585, '2': -3.5652924, '5': -4.2781734, '7': -4.3838224, '6': -4.6436043, '1': -6.6456566, ' professional': -7.306258, ' Argent': -7.489622, '9': -8.28385, ' world': -9.092647, ' football': -9.308567, ' Argentina': -9.438109, 'Arg': -10.499325, ' World': -10.538977, '8': -10.543113, ' small': -10.548636, ' soccer': -10.601004, ' legendary': -10.619824, ' Spanish': -10.658553, ' famous': -10.917005, '': -12.820364, ' master': -10.925327, ' Professional': -11.223865, ' man': -11.266705, ' genius': -11.367016, ' Barcelona': -11.409745, ' legend': -11.411743, ' player': -11.449299, ' talented': -11.468328, ' goal': -11.4988575, ' brilliant': -11.575077, ' super': -11.629269, ' pro': -11.6492815, ' arg': -11.654221, ' renown': -11.695216, '\\xad': -11.7483425, ' thirty': -11.748673, ' Lion': -11.750276, ' global': -11.759962, ' three': -11.805651, ' rare': -11.810522, ' fascinating': -11.897268, ' name': -11.925197, ' dimin': -11.941944, ' forward': -11.949226, ' great': -11.962085, ' four': -12.055848, ' sport': -12.072181, ' living': -12.117165, ' unique': -12.138574, ' former': -12.180676, ' skill': -12.205435, '¡': -12.215115, ' fantastic': -12.265219, '0': -12.275389, ' record': -12.281684, 'Â': -12.343824, ' remarkable': -12.352375, ' talent': -12.404874, ' champion': -12.417784, 'icons': -12.425971, ' skilled': -12.428926, ' beautiful': -12.469669, ' marvel': -12.480689, ' profession': -12.568488, ' popular': -12.59681, ' free': -12.711369, ' FC': -12.73684, ' South': -12.749465, ' controversial': -12.767931, '´': -12.826366, ' seven': -12.850617, ' Buenos': -12.866381, ' Portuguese': -12.878069, ' wonderful': -12.881597, ' stunning': -12.882851, ' Brazil': -12.886369, ' FIFA': -12.900502, '\\t': -12.906259, ' tal': -12.913297, '****': -12.915571, ' w': -12.926603, ' multiple': -12.979265, ' ball': -12.994544, ' multi': -13.005355, ' serial': -13.010857, ' well': -13.016083, ' lion': -13.021542, 'foot': -13.038147, '\\n': -13.040363, ' Football': -13.047092, ' Colomb': -13.047795, ' title': -13.119963, ' special': -13.122649, ' Mexican': -13.123005, ' one': -13.126303, ' star': -13.136442, ' icon': -13.148792}, {'3': -0.7740722, '4': -1.107614, '5': -2.4196734, '2': -2.7761455, '1': -3.2566314, '0': -4.2183986, '6': -5.925056, '7': -7.3071036, '-': -8.378277, '8': -8.788752, '9': -9.471441, 'x': -10.569136, ' ': -10.829836, ' time': -11.631176, 'rd': -12.015116, ',': -12.0500145, '.': -12.101238, 'd': -12.276276, ' times': -12.511545, ' minute': -12.5547085, ' year': -12.624176, '^{': -12.636124, 'o': -12.85927, ' years': -12.890188, ' player': -12.99296, ' x': -13.236799, ' day': -13.247471, ' four': -13.434187, ' man': -13.560621, ' point': -13.596941, 'D': -13.597387, 'X': -13.630152, '/': -13.696587, 'th': -13.726816, ' hour': -13.744234, ' three': -13.744671, 'am': -13.878843, ' am': -13.935585, ' star': -13.940418, ' world': -14.0288925, ' and': -14.059893, ' goal': -14.063385, ' or': -14.063934, ' month': -14.102985, 'm': -14.142563, ' minutes': -14.153543, ' million': -14.162775, '½': -14.198248, ' game': -14.212118, ' players': -14.249332, ' week': -14.267284, ':': -14.304628, ' person': -14.321573, ' to': -14.351246, ' part': -14.446932, ' a': -14.506767, ' five': -14.510199, ' title': -14.51297, '+': -14.521982, ' men': -14.547382, 'l': -14.593508, '–': -14.603006, ' days': -14.6069565, ' little': -14.623108, ' inch': -14.657888, ' for': -14.671772, ' un': -14.715454, ' p': -14.731464, ' months': -14.750736, ' small': -14.751469, ' decades': -14.759792, ' major': -14.762089, '%': -14.82943, '*': -14.837145, 'day': -14.840147, ' in': -14.85001, ' -': -14.855179, ' points': -14.888969, ' brand': -14.899094, ' things': -14.9643955, 'n': -14.9865055, '×': -15.002834, ' main': -15.024183, ' regular': -15.065329, ' other': -15.0923195, ' season': -15.109554, ' billion': -15.16877, ' games': -15.180555, ' bar': -15.180769, ' percent': -15.207226, ' football': -15.211985, ' n': -15.225082, ' free': -15.22748, 'a': -15.23868, ' fourth': -15.250381, ' decade': -15.253393, ' problem': -15.254272, ' weeks': -15.2568, ' team': -15.261814, ' professional': -15.283422}, {'-': -0.052979767, ' years': -3.5220482, ' year': -3.8975575, ' y': -7.2837157, 'year': -8.141099, 'yr': -9.091583, '–': -9.313199, ' –': -9.498307, ' -': -9.549998, ' old': -9.667054, 'th': -10.043299, ' ': -10.287183, ' Year': -10.752263, ' Years': -11.094586, ' times': -11.698546, ' yo': -11.914629, ',': -11.937143, 'yo': -11.982909, '1': -12.042577, ' age': -12.13615, ' Y': -12.154326, ' (': -12.194545, ' aged': -12.238811, '.': -12.338311, 'y': -12.492793, ' ye': -12.6209545, ' calendar': -12.654857, 'Y': -12.7050295, ' going': -12.719419, '‐': -12.735768, ' seasons': -12.744592, '/': -12.794581, ' a': -12.93677, ' decades': -13.023388, ' and': -13.247163, ' days': -13.263495, ' million': -13.28862, ' months': -13.328168, ' ya': -13.412471, '0': -13.429824, '—': -13.490582, '\\n': -13.525991, ' football': -13.527474, ' season': -13.61142, '%': -13.656871, ' YO': -13.665309, ' yoga': -13.697781, ' time': -13.723807, ' previous': -13.733487, ' —': -13.752107, ' soccer': -13.854083, ' twelve': -13.87535, ' occasions': -13.91764, '2': -13.921242, '^{': -13.955996, ' long': -13.961316, ' ages': -13.972095, ' tear': -13.995327, ' period': -14.012902, '3': -14.015452, ' the': -14.021763, '+': -14.056771, '\\xad': -14.070235, ' World': -14.117801, ' professional': -14.144063, '*': -14.151433, '5': -14.192229, ' Old': -14.213217, ' yards': -14.2230425, ' Premier': -14.281071, ' five': -14.303484, ' hours': -14.3133545, ' años': -14.32301, ' young': -14.328988, '‑': -14.3399515, 'Year': -14.354592, ' former': -14.359244, '?': -14.373114, ' ears': -14.384479, ' or': -14.409839, ' sports': -14.418399, ' full': -14.433747, ' win': -14.435662, ' g': -14.461423, ' three': -14.481163, '4': -14.490222, ' out': -14.499543, 'x': -14.517509, '(': -14.525857, ' one': -14.533568, ' games': -14.55494, '\\u200b': -14.560639, '年': -14.572909, ' percent': -14.6162405, '½': -14.686484, '--': -14.714621, 's': -14.720506, ' man': -14.747184, ':': -14.756872, ' года': -14.757728}, {'year': -0.0028441001, 'yr': -6.2283397, ' year': -8.54008, '1': -9.114122, 'time': -9.177704, 'calendar': -9.261251, 'Year': -9.337235, 'ye': -9.466379, 'yer': -10.541389, 'Y': -10.674784, 'y': -10.916727, 'times': -11.017799, 'old': -11.624427, '3': -11.644538, 'yar': -11.709864, 'go': -11.711184, 'season': -11.971191, ' years': -12.018198, 'ya': -12.705509, 'yo': -12.926395, 'game': -13.134107, ' y': -13.168827, '2': -13.296423, 'yard': -13.344909, 'going': -13.350721, 'Calendar': -13.4255905, 'cal': -13.431061, 'month': -13.517313, 'ear': -13.612555, 'man': -13.616268, 'cap': -13.668911, 'century': -13.801897, 'turn': -13.886807, 'yes': -13.976709, '4': -14.334553, 'and': -14.383279, ' Year': -14.400368, 'g': -14.412491, 'age': -14.428315, 'team': -14.447079, 'star': -14.588182, 'period': -14.611442, 'three': -14.701909, ' calendar': -14.704944, 'dec': -14.743776, 'olds': -14.798067, 'the': -14.80869, 'h': -14.900959, 'hour': -14.905382, 'f': -14.97335, '0': -14.992659, 'week': -15.007251, 'b': -15.04422, 'th': -15.100026, 'a': -15.110194, 're': -15.111668, '年': -15.1122, 'minute': -15.12392, 'plus': -15.154594, 'tw': -15.186091, 'day': -15.187168, 'term': -15.198858, '\\u200b': -15.208694, '5': -15.24647, 'era': -15.268949, 'Old': -15.287833, 'c': -15.369243, 'aged': -15.370778, ' ye': -15.432555, 'strong': -15.4554825, 'm': -15.480366, 'part': -15.529852, 'fe': -15.532503, 'te': -15.546603, 'appe': -15.560996, 'your': -15.573841, 'qu': -15.574954, 'inch': -15.58771, 'Go': -15.602558, ' ': -15.606989, 'Cal': -15.621984, 'history': -15.623268, 've': -15.665485, 'you': -15.728701, 'match': -15.736256, 't': -15.741678, 'once': -15.778581, 'care': -15.795404, '\\n': -15.812792, 'al': -15.81736, 'now': -15.826263, 'something': -15.829033, ' old': -15.83362, 'win': -15.844475, 'player': -15.84967, 'acre': -15.898961, 'member': -15.901911, 'long': -15.907476, 'l': -15.939043, 'Time': -15.950464}, {'-': -0.054006934, ' old': -3.1460452, 's': -4.82984, ' previous': -7.787686, ' Argent': -8.31937, ' out': -8.851206, 'old': -9.154482, ' aged': -10.040085, ' professional': -10.254663, ' football': -10.400185, ' former': -10.52415, ' French': -10.735434, ' veteran': -10.8444, ' Spanish': -10.892874, '–': -10.9891205, ' soccer': -11.011959, ' older': -11.094965, ' young': -11.112896, ' Portuguese': -11.313584, ' age': -11.596225, ' Colomb': -11.783202, ' prior': -11.841444, ' Argentina': -11.866143, ' vintage': -11.892473, ' Italian': -12.032242, ' strong': -12.1594, ' -': -12.217634, ' –': -12.264488, ' Brazil': -12.328277, ' Old': -12.378108, ' Japanese': -12.420855, ' recent': -12.448566, ' ancient': -12.5238285, ' year': -12.527073, ' retired': -12.644048, ' Mexican': -12.6461525, ' ago': -12.777977, ',': -12.808055, ' forward': -12.94911, 'ed': -12.978281, ' Belg': -13.051889, ' Greek': -13.096466, ' English': -13.09778, ' earlier': -13.243981, ' Dutch': -13.320233, ' youth': -13.355387, ' season': -13.368041, ' German': -13.380432, ' Israeli': -13.397163, ' player': -13.407857, ' sports': -13.429129, 'l': -13.442307, ' long': -13.448725, ' star': -13.460321, ' man': -13.463014, ' history': -13.504829, ' joint': -13.552669, ' younger': -13.553476, ' Barcelona': -13.566792, ' Turkish': -13.619279, 'out': -13.6211605, ' senior': -13.65163, ' ': -13.667659, ' tennis': -13.679157, '_': -13.684869, ' from': -13.718853, ' mature': -13.725409, ' international': -13.726304, ' Olympic': -13.72963, ' Egyptian': -13.7435875, ' talented': -13.758666, ' left': -13.777254, ' career': -13.783289, ' foot': -13.79114, ' Arab': -13.806294, ' ant': -13.808294, ' skilled': -13.845338, ' kid': -13.858771, ' st': -13.9003105, ' and': -13.911721, ' Swedish': -13.919119, ' experienced': -13.953583, 'Arg': -13.967226, '.': -14.024931, ' famous': -14.058221, ' past': -14.064378, ' light': -14.0681095, ' aging': -14.071379, ' European': -14.073079, ' British': -14.079566, ' arch': -14.08638, ' advanced': -14.0940895, ' Australian': -14.099106, ' elderly': -14.101902, ' attack': -14.113265, ' on': -14.116108, '‐': -14.146595, ' re': -14.147701, '\\xad': -14.15329, ' World': -14.1616535}]}, 'finish_reason': 'length'}], 'usage': {'prompt_tokens': 8, 'completion_tokens': 5, 'total_tokens': 13}}\n"
]
}
],
"metadata": {
"id": "EdBZZYNfZopI",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "3fdf4a7b-ae5a-4089-8452-6a150cb1d8f3"
}
},
{
"cell_type": "markdown",
"source": [
"En utilisant, le resultat ci-dessus, implémenter une fonction permettant de calculer la probabilité moyenne d'une génération. Avec la fonction déterminer la probabilité moyenne de la génération issu de :\n",
"\"Lionel messi is a\", \"Jean Dagobert is a \"\n",
"Que constatez-vous ?"
],
"metadata": {
"id": "HlJThpNlca8Z"
}
},
{
"cell_type": "code",
"execution_count": 14,
"source": [
"import math\n",
"def probabilite_moyenne_phrase(llm_output):\n",
" \"\"\"\n",
" Calculate the average probability of a generation.\n",
" \"\"\"\n",
" # Extraire les log-probabilités des tokens générés\n",
" log_probs = llm_output['choices'][0]['logprobs']['token_logprobs']\n",
"\n",
" # Convertir les log-probabilités en probabilités\n",
" probs = [math.exp(log_prob) for log_prob in log_probs]\n",
"\n",
" # Calculer la probabilité moyenne\n",
" avg_prob = sum(probs) / len(probs)\n",
" return avg_prob\n",
"# Simuler les sorties de génération pour les deux phrases\n",
"llm_output1 = gen(\"Lionel Messi is a \")\n",
"\n",
"\n",
"\n",
"llm_output2 =gen(\"Jean Dagobert is a\")\n",
"\n",
"# Calculer les probabilités moyennes pour les deux phrases\n",
"avg_prob1 = probabilite_moyenne_phrase(llm_output1)\n",
"avg_prob2 = probabilite_moyenne_phrase(llm_output2)\n",
"\n",
"avg_prob1, avg_prob2"
],
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"Llama.generate: prefix-match hit\n",
"\n",
"llama_print_timings: load time = 2950.22 ms\n",
"llama_print_timings: sample time = 11.51 ms / 20 runs ( 0.58 ms per token, 1737.77 tokens per second)\n",
"llama_print_timings: prompt eval time = 4779.36 ms / 13 tokens ( 367.64 ms per token, 2.72 tokens per second)\n",
"llama_print_timings: eval time = 12123.36 ms / 19 runs ( 638.07 ms per token, 1.57 tokens per second)\n",
"llama_print_timings: total time = 16929.54 ms / 32 tokens\n",
"Llama.generate: prefix-match hit\n",
"\n",
"llama_print_timings: load time = 2950.22 ms\n",
"llama_print_timings: sample time = 20.86 ms / 20 runs ( 1.04 ms per token, 958.86 tokens per second)\n",
"llama_print_timings: prompt eval time = 6121.47 ms / 13 tokens ( 470.88 ms per token, 2.12 tokens per second)\n",
"llama_print_timings: eval time = 14926.61 ms / 19 runs ( 785.61 ms per token, 1.27 tokens per second)\n",
"llama_print_timings: total time = 21093.27 ms / 32 tokens\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"(0.9129406913119438, 0.7053066764283165)"
]
},
"metadata": {},
"execution_count": 14
}
],
"metadata": {
"id": "JlWQxJeucaNy",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "f870c0f6-b531-461f-c96a-83236fbd54b4"
}
},
{
"cell_type": "markdown",
"source": [
"L'entropie est un concept fondamental en théorie de l'information qui mesure l'incertitude ou le désordre dans un ensemble de données. En d'autres termes, elle donne une indication de la quantité d'information qui est manquante avant de pouvoir faire une prédiction précise.\n",
"\n",
"Dans le contexte des LLMs, l'entropie peut nous aider à comprendre à quel point le modèle est incertain de ses prédictions. Une entropie élevée signifie que le modèle est très incertain, tandis qu'une entropie faible signifie que le modèle est plus sûr de lui.\n",
"\n",
"L'entropie est particulièrement utile dans notre étude des hallucinations des LLMs. En calculant l'entropie des prédictions du modèle, nous pouvons quantifier l'incertitude du modèle et donc sa tendance à \"halluciner\". Plus l'entropie est élevée, plus le modèle est susceptible de faire des prédictions erronées ou déconnectées du contexte.\n",
"\n",
"Ainsi, en vous aidant de cette formule de l'entropie:\n",
"\n",
"\n",
"\n",
"Ecrivez une fonction permettant de calculer la moyenne d'entropie d'une génération sur la base des top logprobs. Puis avec cette fonction, déterminez l'entropie des génération issu de: \"Lionel messi is a\", \"Jean Dagobert is a \" Que constatez vous? Essayez avec la phrase \"Rihanna is a\" que constatez vous ? Concluez sur les limites de cette méthode."
],
"metadata": {
"id": "fwnzIbrwdwc7"
}
},
{
"cell_type": "code",
"execution_count": 15,
"source": [
"import numpy as np\n",
"\n",
"def entropy(logprobs):\n",
" \"\"\"\n",
" Calcule l'entropie d'une liste de log-probabilités.\n",
"\n",
" :param logprobs: Liste des log-probabilités pour un token.\n",
" :return: Entropie du token.\n",
" \"\"\"\n",
" # Convertir les log-probabilités en probabilités\n",
" probs = np.exp(logprobs)\n",
" # Normaliser les probabilités pour s'assurer qu'elles forment une distribution valide\n",
" probs /= np.sum(probs)\n",
" # Calculer l'entropie\n",
" entropy = -np.sum(probs * np.log(probs))\n",
" return entropy\n",
"\n",
"def moyenne_entropie(llm_output):\n",
" \"\"\"\n",
" Calcule l'entropie moyenne pour une génération de LLM basée sur les top logprobs.\n",
"\n",
" :param llm_output: Sortie du modèle de langage contenant les log-probabilités des tokens.\n",
" :return: Entropie moyenne pour la génération.\n",
" \"\"\"\n",
" total_entropy = 0\n",
" num_tokens = len(llm_output['choices'][0]['logprobs']['top_logprobs'])\n",
"\n",
" for token_logprobs in llm_output['choices'][0]['logprobs']['top_logprobs']:\n",
" total_entropy += entropy(list(token_logprobs.values()))\n",
"\n",
" return total_entropy / num_tokens\n",
"print(moyenne_entropie(results1))"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"0.5081072527915239\n"
]
}
],
"metadata": {
"id": "ZpdlNmqiZzm3",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "500d5f1e-5645-4e2c-f66f-8177265f0b51"
}
},
{
"cell_type": "markdown",
"source": [
"Bien que l'entropie soit un outil utile pour mesurer l'incertitude des LLMs, elle n'est pas sans limitations. En particulier, l'une de ses faiblesses majeures est qu'elle ne prend pas en compte la sémantique des mots. Cela peut conduire à des résultats trompeurs lors de l'évaluation de la certitude du modèle.\n",
"\n",
"Par exemple, prenons les phrases \"Paris est la capitale de la France\" et \"La capitale de la France est Paris\". Ces deux phrases expriment la même information et sont toutes deux correctes d'un point de vue sémantique. Cependant, en raison de la façon dont l'entropie est calculée, elles peuvent avoir des valeurs d'entropie très différentes.\n",
"\n",
"Cela se produit parce que l'entropie mesure l'incertitude du modèle en se basant uniquement sur la distribution de probabilité des tokens prédits, sans prendre en compte la signification de ces tokens. Ainsi, même si les deux phrases sont sémantiquement équivalentes, le modèle peut être plus sûr de lui lorsqu'il prédit l'une que l'autre, conduisant à des valeurs d'entropie différentes.\n",
"\n",
"C'est pourquoi nous allons utiliser une méthode appelée SelfcheckGPT.\n",
"\n"
],
"metadata": {
"id": "XnyVXlSnid7w"
}
},
{
"cell_type": "markdown",
"source": [
"https://arxiv.org/abs/2303.08896\n",
"\n",
"SelfCheckGPT est une méthode développée pour aider à identifier et réduire les hallucinations dans les réponses générées par les modèles de langage comme GPT. Les hallucinations se produisent lorsque le modèle génère des informations incorrectes ou non fondées, ce qui peut poser des problèmes dans des contextes où la précision est essentielle, tels que la recherche scientifique, les diagnostics médicaux, ou les décisions juridiques.\n",
"Principe de SelfCheckGPT\n",
"L'idée centrale de SelfCheckGPT est d'utiliser le modèle GPT lui-même pour vérifier ses propres réponses. Cette méthode repose sur plusieurs étapes clés :\n",
"1.\tGénération Initiale :\n",
"Le modèle GPT génère une première réponse à une question ou un prompt donné.\n",
"2.\tRépétition et Diversité :\n",
"Pour évaluer la fiabilité de cette réponse, le modèle génère plusieurs versions de la réponse à partir du même prompt. Cela est fait en utilisant des techniques de rééchantillonnage, telles que l'utilisation de différentes graines aléatoires ou de légères variations dans les prompts.\n",
"3.\tAnalyse de Consistance :\n",
"Les réponses multiples générées sont ensuite comparées entre elles. Si les réponses sont similaires ou cohérentes entre elles, cela augmente la confiance en la validité de l'information. Si les réponses varient considérablement, cela peut indiquer une possible hallucination. Notamment, dans ce tp nous utiliserons un modèle NLI pour mesurer cette cohérence.\n",
"\n",
"Ici le modèle NLI permet de classes les paires (réponse, affirmation de référence) en trois catégories : Entailment (impliqué), Neutral (neutre), ou Contradiction (contradiction). Une probabilité est donnée pour appartenir à la dite catégorie.\n",
"\n",
"Ainsi, dans la suite de notre travaille, nous allons réimplémenter la méthode et étudier ces performances."
],
"metadata": {
"id": "tqxTwp8_7Ejy"
}
},
{
"cell_type": "code",
"execution_count": 6,
"source": [
"from transformers import DebertaV2ForSequenceClassification, DebertaV2Tokenizer\n",
"import torch\n",
"import nltk\n",
"\n",
"nli_model = \"potsawee/deberta-v3-large-mnli\"\n",
"tokenizer = DebertaV2Tokenizer.from_pretrained(nli_model)\n",
"model = DebertaV2ForSequenceClassification.from_pretrained(nli_model)\n",
"\n",
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
"model.to(device)\n",
"\n",
"nltk.download('punkt')\n",
"\n",
"def gen(query):\n",
" prompt = f\"\"\"\n",
" You are an AI assistant. Given a question about it, create a short answer. If you don't know the answer, honestly say so.\n",
" Question: {query}\n",
" Answer:\n",
" \"\"\"\n",
" output = llm.create_completion(prompt,\n",
" max_tokens = 20,\n",
" echo = False,\n",
" temperature = 1,\n",
" logprobs =100,\n",
" ) # to return top 5 tokens\n",
"\n",
" return output\n",
"\n",
"print(gen(\"Whos is Messi ?\"))\n"
],
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"[nltk_data] Downloading package punkt to /root/nltk_data...\n",
"[nltk_data] Package punkt is already up-to-date!\n",
"Llama.generate: prefix-match hit\n",
"\n",
"llama_print_timings: load time = 2950.22 ms\n",
"llama_print_timings: sample time = 11.05 ms / 20 runs ( 0.55 ms per token, 1810.61 tokens per second)\n",
"llama_print_timings: prompt eval time = 0.00 ms / 0 tokens ( -nan ms per token, -nan tokens per second)\n",
"llama_print_timings: eval time = 19063.09 ms / 20 runs ( 953.15 ms per token, 1.05 tokens per second)\n",
"llama_print_timings: total time = 19090.84 ms / 20 tokens\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"{'id': 'cmpl-1dccd53c-e85d-44a2-9834-c0b8d06fa0f2', 'object': 'text_completion', 'created': 1717575914, 'model': 'mistral-7b-instruct-v0.2.Q4_K_M.gguf', 'choices': [{'text': ' Lionel Messi is an Argentine professional soccer player who currently plays as a forward for Paris Saint', 'index': 0, 'logprobs': {'tokens': [' Lion', 'el', ' Mess', 'i', ' is', ' an', ' Argent', 'ine', ' professional', ' soccer', ' player', ' who', ' currently', ' plays', ' as', ' a', ' forward', ' for', ' Paris', ' Saint'], 'text_offset': [179, 184, 186, 191, 192, 195, 198, 205, 208, 221, 228, 235, 239, 249, 255, 258, 260, 268, 272, 278], 'token_logprobs': [-0.4169057, -1.19209275e-07, -0.0024738677, -4.7683704e-07, -7.867782e-06, -0.84684646, -0.00045730147, -0.0104964115, -0.00049864734, -2.8808954, -0.0090957815, -0.4837565, -0.09042948, -4.8755406e-05, -0.16231762, -2.8610189e-06, -0.00061576476, -0.0015592334, -0.056626014, -0.0002311201], 'top_logprobs': [{' Lion': -0.4169057, ' I': -1.1377861, ' Leo': -5.0521827, ' It': -5.523128, ' lion': -6.365499, ' That': -6.5637107, ' The': -6.914335, ' Mess': -6.9752307, ' Unfortunately': -7.3981786, 'I': -7.7050242, ' Lar': -7.805304, ' Sorry': -8.013324, ' \"': -8.060237, ' There': -8.071133, ' Luis': -8.141668, ' You': -8.24693, ' Le': -8.64321, 'L': -8.873028, ' Larry': -9.338284, ' This': -9.34004, 'Sorry': -9.442203, ' Liga': -9.524789, ' L': -9.577162, ' Ap': -9.81628, ' Leon': -9.913119, ' sorry': -10.291911, ' Sad': -10.293263, ' Lag': -10.305075, ' Leb': -10.334279, ' My': -10.347125, ' Although': -10.502601, ' Ludwig': -10.569314, ' Your': -10.657312, ' While': -10.700457, ' Lee': -10.926439, ' Jorge': -10.939368, ' Lily': -10.95375, ' In': -11.004247, ' Lam': -11.102857, ' Its': -11.180238, ' Despite': -11.2688875, ' If': -11.2879925, ' Latin': -11.315402, ' Lawrence': -11.386546, '\\t': -11.442706, ' Lewis': -11.450325, ' Sor': -11.518464, 'Le': -11.519059, 'That': -11.658095, ' Lemma': -11.660903, 'LM': -11.677005, '\\n': -11.68498, 'It': -11.718175, ' Carlos': -11.72704, ' Lars': -11.744475, ' Let': -11.770156, ' Lew': -11.793929, '\"': -11.890266, ' Lad': -11.891176, \" '\": -11.985602, ' According': -12.019115, ' Lie': -12.034099, ' Sir': -12.062839, ' Lil': -12.087346, ' Lor': -12.141446, 'sor': -12.164132, ' Jon': -12.178144, ' A': -12.198925, ' League': -12.201467, ' Unlike': -12.20502, ' that': -12.2086, ' However': -12.2352705, ' Jonathan': -12.24981, ' lemon': -12.372668, ' Based': -12.415782, ' unfortunately': -12.470145, ' To': -12.491509, ' Though': -12.502353, ' Lieutenant': -12.529107, ' Actually': -12.550166, ' Lac': -12.5523, ' l': -12.562456, ' Sure': -12.56313, ' Lamb': -12.60091, ' Ser': -12.6648, ' Antonio': -12.682169, ' le': -12.701306, ' LE': -12.707778, ' Francisco': -12.708587, ' Lis': -12.783514, ' **': -12.798579, ' Perhaps': -12.8262205, ' Lé': -12.859203, ' mess': -12.872161, ' Here': -12.9026165, ' Lisa': -12.910498, 'The': -12.918046, 'lon': -12.92126, ' lig': -12.937846, ' Mist': -12.938876}, {'el': -1.19209275e-07, 'els': -15.711103, 'elm': -17.186104, 'EL': -17.213352, 'ell': -17.330284, 'nel': -17.495312, 'él': -18.334877, 'ël': -18.488062, 'elt': -18.901976, 'eling': -19.065712, 'cel': -19.076706, 'elf': -19.13324, ' eligible': -19.232538, 'eld': -19.489016, ' Mess': -19.864513, 'eled': -19.979534, 'eln': -20.377583, 'elo': -20.489904, 'al': -20.946514, 'ele': -20.953756, ' el': -21.007626, 'il': -21.264702, 'ol': -21.511364, 'eland': -21.675568, 'et': -21.782614, 'ello': -22.123077, 'ess': -22.381243, 'El': -22.481104, ' elite': -22.549671, 'l': -22.651121, 'uel': -22.722876, 'cl': -22.738407, 'le': -22.77833, 'elte': -22.966133, 'ul': -23.006805, 'ael': -23.089718, 'sel': -23.144123, 'elem': -23.20456, 'iel': -23.228992, 'ela': -23.303988, 'hel': -23.341068, 'elly': -23.39413, 'elin': -23.46202, ' elbow': -23.47241, ' El': -23.660416, 'vel': -23.764647, 'ed': -23.832748, 'elde': -24.125738, 'en': -24.148293, 'eler': -24.17409, ' mess': -24.191578, 'elen': -24.2412, 'em': -24.396053, 'elif': -24.459414, 'elled': -24.579708, ' EL': -24.60891, 'elle': -24.622486, 'elta': -24.63763, ' él': -24.646141, 'elson': -24.649586, 'bel': -24.673222, 'kel': -24.718565, 'all': -24.743301, 'lo': -24.77123, 'eli': -24.788216, 'id': -24.812155, 'elve': -24.824894, 'else': -24.922197, 'eth': -25.024967, 'rel': -25.037632, 'fel': -25.190283, ' elf': -25.221737, 'eles': -25.253323, 'est': -25.387112, 'elia': -25.430204, 'ely': -25.44453, 'er': -25.454548, 'ne': -25.461956, 'ail': -25.48601, 'n': -25.506435, 'ellow': -25.532406, 'us': -25.575531, 'let': -25.578144, 'om': -25.586725, 'cil': -25.726103, 'nal': -25.802189, 'yl': -25.828896, 'ic': -25.894505, ' elabor': -25.911615, 'elij': -25.946302, 'cle': -25.961948, 'elling': -25.988768, 'ella': -26.025911, 'as': -26.09714, 'nels': -26.11714, 'ord': -26.127596, 'ěl': -26.200115, 'it': -26.232336, 'or': -26.287733, 'ad': -26.30545}, {' Mess': -0.0024738677, ' And': -6.4882755, ' Andr': -7.049595, 'And': -10.008812, ' mess': -11.535646, ' Anders': -11.545216, 'MESS': -12.075888, ' Andrew': -13.049125, ' Andre': -13.17198, ' Andrea': -13.721295, ' Anderson': -13.842749, ' Andy': -13.937332, ' Анд': -14.052877, ' Mes': -14.0961895, 'AND': -14.292474, ' André': -14.326244, ' Angel': -15.19828, ' Android': -15.389944, 'andro': -15.582506, ' Mas': -15.969084, ' ': -16.02505, ' AND': -16.135725, 'M': -16.69388, ' \"': -17.042095, 'ander': -17.104382, ' Maur': -17.108595, 'ande': -17.249493, ' Argent': -17.269255, ' Á': -17.345095, ' M': -17.434233, ' A': -17.476263, 'android': -17.484663, 'ands': -17.523056, 'andra': -17.555418, ' Leo': -17.659422, ' Ang': -17.690866, ' Meg': -17.778257, ' Mart': -17.855864, ' (': -17.915543, ' Lion': -17.983145, 'anded': -18.183516, ' Maria': -18.21863, ' Matt': -18.257086, ' Mel': -18.324232, ' ME': -18.339079, ' Mend': -18.447231, ' Leon': -18.5543, ' Marg': -18.602697, 'andon': -18.615364, ' Mos': -18.627558, ' Mass': -18.634178, \" '\": -18.634832, ' Ad': -18.758331, ' Manuel': -18.924782, ' Mol': -18.930761, ' Magn': -18.9383, ' android': -18.944689, ' Aires': -18.957592, ' Mar': -19.001642, ' Miguel': -19.078516, '\\n': -19.111322, ' Mau': -19.148973, ' Mall': -19.15017, ' Mark': -19.157858, ' Mand': -19.217947, 'Android': -19.221529, ' Ant': -19.251684, ' Ah': -19.26845, ' Mario': -19.313852, 'anda': -19.329725, ' Anton': -19.341522, 'andal': -19.344849, ' Moh': -19.383919, ' Marcel': -19.392435, ' Me': -19.437729, ' Crist': -19.51673, ' Antonio': -19.525242, ' Ag': -19.525583, 'andy': -19.541681, ' Ale': -19.571856, ' An': -19.598927, ' Maj': -19.669363, ' Al': -19.709385, ' Mon': -19.729048, 'ess': -19.746271, 'and': -19.779484, ' Mil': -19.783403, ' Mex': -19.791716, ' Mans': -19.800426, ' Ar': -19.847147, ' Arm': -19.850225, ' Marc': -19.858683, ' Mull': -19.944086, ' Mens': -19.961298, ' Mann': -19.966837, ' Men': -19.987526, ' Mad': -20.05828, ' Mal': -20.06443, ' Amb': -20.108595, ' Merc': -20.184502}, {'i': -4.7683704e-07, 'is': -14.572745, 'í': -18.862831, 'ier': -19.53286, 'ie': -19.80582, ' i': -20.03273, 'I': -20.297386, 'si': -20.317663, 'ir': -20.331875, 'iw': -20.4372, 'ih': -20.688017, 'ide': -20.793789, 'rs': -20.898075, 'y': -20.902817, 'id': -20.96754, 'ias': -20.987907, 'ia': -21.22713, 'ii': -21.414892, 'if': -21.446438, 's': -21.518015, 'io': -21.707796, 'ib': -21.798687, 'и': -21.80854, 'li': -21.81379, 'ip': -21.84301, 'ij': -21.863674, 'ri': -21.87922, 'it': -21.958843, 'iest': -22.022491, 'і': -22.09068, 'ian': -22.168283, 'iah': -22.219252, 'ei': -22.308163, 'ist': -22.487778, 'di': -22.51417, 'ì': -22.526134, 'ion': -22.570919, 'a': -22.646864, 'hi': -22.806252, 'ï': -22.887562, 'ies': -22.893642, 'ic': -22.934917, 'u': -22.950676, 'ing': -23.00198, 'ai': -23.015175, 'ı': -23.085941, 'ig': -23.115913, 'ī': -23.116005, 'bi': -23.152119, 'ci': -23.15913, 'iro': -23.264212, 'il': -23.280436, 'ι': -23.296116, 'iz': -23.349752, 'as': -23.39392, 'er': -23.408741, ' is': -23.454506, 'iss': -23.460007, 'iq': -23.479198, 'ि': -23.49566, 'iar': -23.529501, 'in': -23.6583, 'iy': -23.671484, 'r': -23.749819, 'isi': -23.903475, 'iper': -23.974121, 'se': -24.014523, 'Is': -24.030193, 'l': -24.063282, 'iot': -24.08751, 'f': -24.090569, 'ire': -24.093296, 'ior': -24.146677, ' Argent': -24.164291, 'ina': -24.175804, ' Lis': -24.183628, 'iter': -24.19658, 'o': -24.197376, 'ik': -24.219887, 'vi': -24.259176, 'iac': -24.272413, ',': -24.287115, 'ius': -24.29958, 'iat': -24.347961, 'fi': -24.360895, 'ieur': -24.38573, 'iego': -24.427776, 'ix': -24.436985, 'es': -24.445286, 'j': -24.474138, 'or': -24.49858, 'us': -24.541122, 'pi': -24.552176, 'い': -24.564161, 'icon': -24.566792, '-': -24.608952, 'ar': -24.632364, ' ideal': -24.638027, 'ais': -24.639053, 'ied': -24.643148}, {' is': -7.867782e-06, ',': -12.136795, ' (': -14.291889, '\\n': -14.383405, ' isn': -14.971661, ' ': -15.444632, \"'\": -15.915594, ' Is': -16.291647, 'is': -16.350609, ':': -16.354897, ' was': -16.673752, '.': -17.532583, ' has': -17.778227, ' and': -17.814266, ' an': -17.87928, ' a': -17.953827, ' refers': -17.956808, ' ist': -17.979527, ' -': -17.991915, ' are': -18.180582, ' in': -18.185661, ' or': -18.191235, ' \"': -18.20036, '是': -18.459686, ' [': -18.46754, '-': -18.757404, ' it': -18.771898, ' i': -18.943066, ' the': -18.997774, ' stands': -19.004251, ';': -19.154896, ' from': -19.352688, ' belongs': -19.451405, ' being': -19.582695, ' if': -19.638063, ' (\"': -19.684465, \" '\": -19.811028, ' does': -19.853403, '*': -19.870361, '(': -19.942614, ' as': -19.952309, ' of': -20.02603, ' also': -20.036747, ' am': -20.092964, ' I': -20.278969, ' h': -20.383852, '\"': -20.532667, ' (@': -20.556574, ' ()': -20.588802, ' comes': -20.606037, ' M': -20.6072, '[': -20.630447, ' remains': -20.634947, ' =': -20.66114, ' may': -20.740662, ' his': -20.77084, ' A': -20.795189, '/': -20.797447, ' appears': -20.83394, ' plays': -20.849491, ' IS': -20.868702, ' nick': -20.938643, ' can': -20.969025, ' represents': -20.980307, \" ('\": -20.997786, ' S': -21.017159, ' for': -21.101147, ' C': -21.140629, ' L': -21.169195, ' :': -21.217312, ' V': -21.23228, ' ,': -21.241035, '!': -21.257776, ' with': -21.263779, ')': -21.266727, ' alias': -21.281055, '?': -21.285482, '...': -21.30188, ' who': -21.314648, ' should': -21.318394, ' that': -21.411179, ' K': -21.41972, ' F': -21.419855, ' we': -21.48059, ' himself': -21.553865, ' An': -21.58879, ' B': -21.59369, '1': -21.595703, ' ': -21.6203, '--': -21.62122, ' является': -21.638878, ' happens': -21.655212, ' would': -21.679636, 's': -21.685862, ' goes': -21.705002, ' |': -21.707623, ' at': -21.724503, ' doesn': -21.727978, ' –': -21.729086, ' born': -21.731174}, {' a': -0.5618962, ' an': -0.84684646, ' arg': -6.90289, ' Argent': -10.1938715, ' widely': -10.940679, ' considered': -10.980967, 'arg': -11.584171, ' one': -12.068102, ' Argentina': -12.862616, ' not': -13.219137, ' renown': -13.282769, ' the': -13.788501, ' world': -14.001212, 'Arg': -14.103918, ' commonly': -14.1723585, ' argued': -14.380891, ' often': -14.473157, ' recognized': -14.588637, ' regarded': -14.604312, ' fam': -15.024814, 'an': -15.057395, 'a': -15.075504, ' famous': -15.275388, ' internation': -15.509197, ' Arg': -15.541738, ' known': -15.698921, ' An': -15.885308, ' ': -15.973728, ' well': -16.018988, ' popular': -16.156956, ' generally': -16.2374, ' argue': -16.32028, ' univers': -16.348211, ',': -16.439674, ' originally': -16.524826, ' acknowledged': -16.636017, ' legendary': -16.660458, ' celebrated': -16.717724, 'ARG': -16.722696, ' argument': -16.773558, ' both': -16.798777, ' who': -16.864292, ' currently': -17.034315, ' another': -17.046286, ' glob': -17.052906, ' actually': -17.070366, ' profession': -17.145958, ' ac': -17.176367, ' und': -17.253736, ' arguments': -17.321842, ' rever': -17.361376, ' from': -17.398855, ' frequently': -17.457405, ' is': -17.498549, ' highly': -17.499111, ' essentially': -17.49954, ' A': -17.502028, ' believed': -17.516424, 'args': -17.61508, ' also': -17.626347, ' professional': -17.738722, 'arga': -17.776367, ' among': -17.85433, ' reput': -17.863295, '\\n': -17.895756, ' referred': -17.908949, ' а': -17.933825, ' and': -17.959492, ' args': -17.979303, ':': -17.990591, ' Buenos': -18.04479, ' someone': -18.053493, ' truly': -18.06965, ' notably': -18.073786, ' quite': -18.085585, ' typically': -18.085693, ' as': -18.12684, ' of': -18.221605, ' deemed': -18.24505, ' born': -18.326992, ' either': -18.343882, ' World': -18.372622, ' \"': -18.406893, ' indeed': -18.459818, ' arguing': -18.489588, ' extens': -18.530275, ' significantly': -18.549593, ' greatly': -18.617224, ' icon': -18.625463, ' primarily': -18.662733, ' most': -18.667145, ' neither': -18.766232, ' NOT': -18.787235, ' definitely': -18.816109, ' Argument': -18.81917, ' officially': -18.833818, ' worldwide': -18.912935, ' being': -18.961382, ' usually': -18.971313, ' noted': -18.971502}, {' Argent': -0.00045730147, ' Argentina': -8.34413, ' arg': -8.595987, 'Arg': -10.686649, ' Arg': -12.342439, ' argument': -12.8394375, ' world': -13.934908, 'arg': -14.25082, ' renown': -14.599555, ' internation': -14.654215, ' icon': -14.756187, ' international': -14.866758, ' professional': -14.926114, ' ac': -15.565672, ' accomplished': -15.72426, 'ARG': -16.346823, ' legendary': -16.352453, ' influential': -16.379538, ' famous': -16.391941, ' argue': -16.409082, ' elite': -16.582079, ' argued': -16.65092, ' award': -16.828093, ' AR': -16.841915, ' arguing': -16.971588, ' arguments': -17.265766, ' Argument': -17.304932, ' expert': -17.868889, ' este': -17.957283, ' American': -17.972672, 'argument': -18.325773, ' Arthur': -18.550386, 'argin': -18.553186, ' Italian': -18.570768, ' args': -18.667212, ' Arab': -18.67104, ' Buenos': -18.694649, ' fam': -18.701838, ' Australian': -18.730467, ' Armen': -18.800816, ' outstanding': -18.816118, ' experienced': -18.962265, 'Argument': -19.006397, ' English': -19.048397, ' celebrated': -19.261768, ' excellent': -19.28061, ' World': -19.328926, ' Arkansas': -19.371172, 'world': -19.412842, ' Aust': -19.41333, ' established': -19.558441, 'args': -19.732239, ' extraordinary': -19.801344, ' ар': -19.821009, ' incredibly': -19.953655, ' extremely': -20.018879, ' amateur': -20.025253, ' prominent': -20.063751, ' Israeli': -20.064823, ' exceptional': -20.15044, ' Arnold': -20.256325, ' impressive': -20.320663, ' ace': -20.372313, 'arga': -20.392063, ' Ar': -20.448277, ' Args': -20.521564, ' arist': -20.530342, 'Args': -20.665766, ' ill': -20.667976, ' Professional': -20.694004, ' Spanish': -20.71748, ' ongoing': -20.735538, ' imm': -20.864647, ' inf': -20.877522, ' Mexican': -20.91001, ' awarded': -20.936356, ' authentic': -20.941511, ' popular': -20.955591, ' ath': -21.012749, ' Ark': -21.051468, ' Arist': -21.060852, ' athlet': -21.064327, ' Colomb': -21.070633, ' acknowledged': -21.074974, ' worldwide': -21.081202, ' talented': -21.087738, ' argc': -21.089495, 'arguments': -21.137424, ' all': -21.1389, ' worlds': -21.190401, ' avant': -21.202223, ' incredible': -21.247297, ' argv': -21.325157, 'argo': -21.354338, ' upcoming': -21.396927, ' exponent': -21.401646, ' Brazil': -21.445314, 'arge': -21.46341, ' illusion': -21.517454, ' extraord': -21.521362}, {'ine': -0.0104964115, 'inian': -4.5645547, 'ian': -10.636702, 'in': -14.249309, 'INE': -14.349794, 'ive': -14.414494, 'ines': -14.57745, 'bian': -15.987307, 'ined': -16.008972, 'ini': -16.387056, 'rian': -16.47649, 'ino': -17.355604, 'inus': -17.653526, 'inese': -17.807089, 'ide': -17.910189, 'ican': -18.267813, 'en': -18.326717, 'ain': -18.3561, 'arian': -18.51122, 'ivan': -18.755297, 'ene': -18.781832, 'an': -18.81936, 'itan': -18.99232, 'inal': -19.072697, 'inely': -19.11292, 'yan': -19.329294, 'ining': -19.33637, 'ing': -19.457144, 'inen': -19.567894, 'esian': -19.570148, 'lean': -19.666643, 'inc': -19.773, 'ince': -19.81795, 'anean': -19.828533, 'uan': -19.873041, 'isan': -19.879335, 'ic': -19.954302, 'ie': -19.975471, 'inet': -20.021004, 'inary': -20.039658, 'inn': -20.051706, 'iv': -20.123549, 'aine': -20.175901, 'ijn': -20.20609, 'iner': -20.263124, 'ime': -20.307394, 'ician': -20.37556, 'im': -20.419046, 'ist': -20.556238, 'inity': -20.590921, 'iman': -20.59849, 'inent': -20.611507, 'inement': -20.824135, 'tan': -20.840899, 'man': -20.852724, 'n': -20.873753, 'oine': -20.903185, 'b': -20.951931, 'aban': -20.95327, 'd': -20.954287, 'aman': -20.955374, ' inequality': -20.989328, 'v': -21.019169, 'ien': -21.039549, 'ination': -21.097479, 'un': -21.205744, 'if': -21.220816, 'ion': -21.277721, 'itarian': -21.286238, 'iene': -21.299948, 'ib': -21.302755, 'inde': -21.34562, 'panic': -21.345678, 'idan': -21.365206, 'ite': -21.420038, 'i': -21.45014, 'il': -21.453627, 'ink': -21.477053, 'inos': -21.551794, 'igan': -21.592215, 'line': -21.678764, 'inate': -21.679895, 'ins': -21.702127, 'iny': -21.70943, 'mine': -21.719776, 'inated': -21.719954, 'int': -21.765053, 'ese': -21.77205, 'ile': -21.795765, 'inge': -21.808016, 'ed': -21.818834, 'ne': -21.852884, 'ussian': -21.886223, 'ina': -21.902725, 'йн': -21.921696, 'ative': -21.955847, 'avan': -21.987913, 'inth': -22.030642, 'ían': -22.04388, 'on': -22.046274}, {' professional': -0.00049864734, ' football': -7.8651934, ' Professional': -10.188588, 'prof': -10.5988865, ' profession': -10.664239, ' soccer': -11.006524, ' international': -12.403754, ' profes': -12.453889, ' world': -13.666543, ' professionals': -14.600627, ' Football': -14.894679, ' профе': -15.176003, ' prof': -15.434574, ' association': -15.80303, '-': -16.06178, ' former': -16.174788, ' expert': -16.20193, ' profess': -16.38299, ' Prof': -16.390627, ' sports': -16.575521, ' retired': -16.601248, ' World': -16.617378, ' professor': -16.753187, ' global': -16.882343, 'foot': -16.990854, ' legendary': -17.032242, ' skilled': -17.159712, ' basketball': -17.213593, ' famous': -17.424162, ' worldwide': -17.44127, ' renown': -17.459755, ' national': -17.480503, ' foot': -17.642237, ' baseball': -17.929905, ' elite': -17.983295, ' veteran': -17.99891, ' experienced': -18.025347, ' amateur': -18.148718, ' tennis': -18.255274, ',': -18.277739, ' born': -18.338608, ' pro': -18.37255, ' premier': -18.429926, ' rugby': -18.444641, ' футбо': -18.486074, ' and': -18.640015, ' FIFA': -18.676353, ' internation': -18.75051, ' modern': -18.795858, ' prominent': -18.83378, ' sport': -18.865997, ' Association': -18.91745, 'Foot': -19.006922, ' popular': -19.029295, ' talented': -19.054747, ' star': -19.133444, ' player': -19.187021, ' hockey': -19.188606, ' legend': -19.240183, ' specialist': -19.326197, ' Fußball': -19.349861, ' Professor': -19.416504, ' ath': -19.423203, ' Soc': -19.424726, ' top': -19.424955, ' public': -19.488443, ' ': -19.567854, ' who': -19.574675, ' licensed': -19.591232, ' International': -19.594519, ' icon': -19.637215, ' progressive': -19.641317, ' contemporary': -19.667585, ' champion': -19.776094, '\\n': -19.79035, ' provincial': -19.898497, ' American': -19.914251, ' athlet': -20.060038, ' championship': -20.08278, ' forward': -20.107676, ' promising': -20.12895, ' prest': -20.167192, ' certified': -20.173191, ' fam': -20.196049, ' super': -20.197445, ' Olympic': -20.213549, ' PRO': -20.216694, ' prospect': -20.272892, ' fut': -20.338203, ' high': -20.423883, ' specialized': -20.441435, ' cricket': -20.44992, ' (': -20.473843, 'World': -20.482546, 'born': -20.485655, ' registered': -20.515192, ' Portuguese': -20.516886, ' trained': -20.52606, ' male': -20.52617, ' Brazil': -20.535036}, {' football': -0.057771433, ' soccer': -2.8808954, ' Football': -10.499128, ' basketball': -11.430088, ' baseball': -11.739187, ' sports': -13.526432, ' футбо': -14.558059, ' tennis': -15.195248, ' hockey': -15.444496, ' foot': -15.637254, ' rugby': -15.650265, ' Fußball': -15.852043, ' FIFA': -16.050491, ' sport': -16.071428, ' Soc': -16.315096, 'foot': -16.387505, ' cricket': -16.619616, ' fut': -16.992264, ' association': -17.116232, 'soc': -17.587013, ' ath': -17.727322, ' soc': -18.07561, ' wrest': -18.448036, ' player': -18.514608, 'Foot': -18.55656, ' golf': -18.824896, ' gol': -19.123732, 'ft': -19.522917, ' soci': -19.60053, 'footer': -19.604671, ' NFL': -19.605669, ' ': -19.705633, ' stri': -19.742022, ' box': -19.782055, ' World': -19.819963, ' society': -19.82663, ' series': -20.096212, ',': -20.285715, ' swim': -20.303312, ' star': -20.329449, ' goal': -20.34904, ' social': -20.377535, '\\n': -20.386877, ' athletes': -20.44939, ' league': -20.464561, ' athlet': -20.489668, ' footage': -20.51019, ' world': -20.530165, ' senior': -20.542097, ' team': -20.547943, ' fo': -20.562704, ' FC': -20.619633, ' fot': -20.643225, ' free': -20.645765, ' UEFA': -20.647041, ' club': -20.654486, ' championship': -20.699617, ' who': -20.715595, ' super': -20.772493, ' novel': -20.840418, ' fashion': -20.882063, ' men': -20.91402, '足': -20.943373, ' vol': -20.947039, ' singer': -20.966227, ' f': -20.973604, ' forward': -21.041662, ' stock': -21.077976, ' solar': -21.126238, ' international': -21.146887, ' squad': -21.21449, ' Association': -21.270193, ' hit': -21.28377, ' stadium': -21.297354, ' and': -21.302, ' Lion': -21.360708, ' ball': -21.382067, ' sensation': -21.423815, ' ft': -21.436724, ' racing': -21.476503, ' squ': -21.479704, ' soldier': -21.492815, ' poker': -21.494247, '-': -21.494884, ' famous': -21.511192, ' sil': -21.537745, ' sc': -21.565538, ' popular': -21.592665, ' male': -21.616367, ' play': -21.653717, ' fighter': -21.664015, ' worldwide': -21.682774, ' skilled': -21.693815, ' talent': -21.744776, ' professional': -21.746248, ' t': -21.764818, ' former': -21.797527, ' playing': -21.798225, ' ski': -21.828735, ' Sports': -21.858295}, {' player': -0.0090957815, ' (': -4.744161, 'player': -8.253489, ' Player': -10.189895, '/': -10.328235, ' players': -11.44065, 'Player': -12.616915, ' or': -12.992254, ',': -13.466972, '(': -13.693067, ' /': -14.050085, ' forward': -14.641734, ' [': -15.217457, ' star': -15.454126, ' football': -15.464518, ' and': -16.145414, ' playing': -16.763168, ' play': -16.831018, ' ath': -17.020132, ' (\"': -17.360624, ' ': -17.389853, ' Players': -17.397362, '[': -17.850824, ' (_': -17.9774, '-': -17.986132, ' played': -18.206528, 'er': -18.219828, ' ()': -18.330027, 'ist': -18.342531, '(': -18.384928, ' (!': -18.432184, 'or': -18.486107, '/(': -18.531908, ' team': -18.534609, ' super': -18.692045, ' genius': -18.699091, '\\n': -18.71182, ' game': -18.744886, ' stri': -18.87854, \" ('\": -18.886824, ' (“': -18.941391, ' phenomenon': -18.986494, ' legend': -19.080553, ' captain': -19.208467, ' fan': -19.238829, 'forward': -19.363358, ' ((': -19.407034, ' manager': -19.422804, ' (\\\\': -19.450205, ' icon': -19.475744, ' artist': -19.491186, ' participant': -19.497849, ' painter': -19.654402, ' (@': -19.773857, ' plays': -19.777796, ' Football': -19.80713, ' champion': -19.853413, ' for': -19.877924, ' father': -19.906122, ' (*': -19.91251, ' driver': -19.950518, '(/': -19.969881, ' -': -19.991331, ' ($': -20.02587, ' actor': -20.081598, ' (+': -20.107481, ' of': -20.108208, '.': -20.112326, ' coach': -20.133026, ' phen': -20.224943, ' –': -20.24748, ' (-': -20.266558, ' agent': -20.36723, ' (&': -20.415861, ' ball': -20.500864, ' that': -20.523268, ' club': -20.567827, ' foot': -20.595364, ' musician': -20.610645, ' figure': -20.655392, ' farmer': -20.665026, 'Forward': -20.699371, \"'\": -20.699621, ' in': -20.744148, ' extraord': -20.76148, ' hero': -20.771196, 'play': -20.801937, ' who': -20.818863, ' journalist': -20.833397, ' goal': -20.85771, ' mid': -20.863785, ' patient': -20.94885, ':': -20.94973, ' M': -20.950092, ' league': -20.95126, ' jug': -20.953861, ' writer': -20.980457, ' talent': -20.986235, ' a': -21.010248, ' person': -21.024086}, {' who': -0.4837565, '.': -1.1057124, ',': -3.2194638, ' currently': -5.4724383, ' widely': -5.6035075, ' known': -6.5761046, ' (': -7.1761384, ' commonly': -7.3440948, ' with': -8.103608, ' renown': -8.274943, ' fam': -8.620232, ' and': -8.640485, ' considered': -8.7852955, 'who': -8.81143, ' often': -8.880502, ' whose': -9.328551, ' whom': -10.284507, ' famous': -10.381125, ' or': -10.694678, ' popular': -10.754622, ' from': -10.949879, ' recognized': -10.965288, ' regarded': -11.028265, ' that': -11.039035, ' frequently': -11.167389, ' best': -11.688989, ' univers': -11.741721, ' current': -11.773745, ';': -11.848483, ' playing': -11.881553, ' well': -11.905121, ' Who': -11.953824, ' primarily': -12.09398, ' named': -12.198634, ' also': -12.295703, ' Currently': -12.322803, ' most': -12.376971, ' in': -12.518397, ' generally': -12.526212, ' noted': -12.68131, ' celebrated': -12.7177, ' formerly': -12.729073, ' -': -12.731421, ' for': -12.751464, ' reput': -12.860171, ' of': -12.8765, 'current': -12.888282, ' typically': -12.893797, ' nick': -12.895154, '-': -12.923946, ' ': -13.028369, 'Current': -13.046221, ' now': -13.097821, ' believed': -13.116054, '(': -13.121538, \"'\": -13.212863, ':': -13.223799, ' born': -13.262668, ' as': -13.271714, '!': -13.27882, 'wid': -13.327657, '/': -13.38369, ' plays': -13.475932, ' fame': -13.487817, ' mostly': -13.534886, ' recently': -13.576275, ' described': -13.579957, ' present': -13.598787, ' affection': -13.60657, ' rated': -13.679238, ' internation': -13.681803, 'Who': -13.687478, 'known': -13.688834, ' wearing': -13.7216, ' associated': -13.730942, ' largely': -13.7368, ' originally': -13.793661, '—': -13.798155, ' inf': -13.837687, ' usually': -13.848516, ' –': -13.959954, ' referred': -13.967032, ' perceived': -13.995194, ' ac': -14.003404, '--': -14.003825, ' to': -14.055882, ' dub': -14.06919, ' mainly': -14.0759325, ' called': -14.120412, ' belonging': -14.120713, '\\n': -14.128454, ' identified': -14.21816, ' where': -14.257281, ' diagnosed': -14.281605, ' w': -14.285844, ' right': -14.31069, '.,': -14.339694, ' notable': -14.3519745, ' legendary': -14.358722, ' highly': -14.366372}, {' currently': -0.09042948, ' plays': -3.2673762, ' has': -3.6744683, ' is': -3.8171198, ' played': -8.668421, ' current': -8.754004, ' Currently': -8.965974, ' primarily': -9.722546, 'current': -10.0577345, ' spent': -10.292217, ' playing': -10.429232, ' now': -10.47694, ' was': -10.509775, ' recently': -10.6918545, \"'\": -10.714475, 'Current': -10.756731, ' previously': -11.309652, ' formerly': -11.451984, ' commonly': -11.570591, ' typically': -11.663758, ' usually': -11.859171, ' often': -11.895504, ' serves': -11.936581, ' play': -12.116957, ' predomin': -12.140737, ' frequently': -12.225731, ' started': -12.363198, ' present': -12.390881, ' performs': -12.401268, ' rose': -12.492285, ' initially': -12.665918, ' runs': -12.718832, ' operates': -12.769817, ' widely': -12.795221, ' mainly': -12.826558, ' holds': -12.902836, ' stands': -12.9512615, ' began': -12.970525, ' ranks': -12.999655, ' works': -13.017561, ' starts': -13.06653, ' had': -13.11166, 'has': -13.168057, ' belongs': -13.186971, ' tops': -13.244169, ' goes': -13.259317, ' Play': -13.266099, 'play': -13.278315, ' notably': -13.302328, ',': -13.319088, ' originally': -13.360912, ' also': -13.362925, ' Current': -13.39032, ' stars': -13.401714, ' regularly': -13.436898, ' generally': -13.443332, ' most': -13.496628, ' already': -13.539802, ' we': -13.601852, ' fam': -13.604322, ' consistently': -13.636301, ' appears': -13.710218, ' many': -13.77623, ' uses': -13.783337, ' made': -13.800046, ' mostly': -13.802338, ' significantly': -13.826044, ' became': -13.844115, ' gained': -13.900773, ' continues': -13.901798, ' grew': -13.9026375, ' star': -13.913145, ' teams': -13.9148, ' renown': -13.956742, ' always': -13.965896, ' used': -13.982316, ' domin': -14.010635, ' capt': -14.034618, ' truly': -14.053309, ' lives': -14.064463, 'CURRENT': -14.071081, ' pl': -14.088125, ' compet': -14.104417, ' normally': -14.110323, ' have': -14.166414, ' comes': -14.187509, ' inf': -14.193431, ' carries': -14.323896, ' in': -14.362313, ' does': -14.39311, ' begins': -14.439307, ' scored': -14.448999, ' h': -14.456707, ' leads': -14.460373, ' can': -14.468296, ' heads': -14.479832, ' shoot': -14.522266, ' overl': -14.53766, ' functions': -14.541252, ' represents': -14.573359}, {' plays': -4.8755406e-05, ' playing': -11.218825, ' played': -11.665014, ' stars': -11.746962, ' play': -11.966521, ' performs': -12.693608, ' serves': -13.844632, ' leads': -13.892591, ' works': -14.085088, 'play': -14.659175, ' Play': -15.15753, ' starts': -15.216023, ' teams': -15.235743, ' capt': -15.270791, ' represents': -15.441829, ' acts': -15.485707, ' pl': -15.489872, ' hosts': -15.678241, ' tops': -15.739517, ' stands': -15.740865, ' pays': -15.772355, '\\n': -15.786052, ' holds': -15.8668165, ' practices': -16.045422, ' belongs': -16.098705, ' operates': -16.106491, ' enjo': -16.17856, ' ': -16.179363, ' compet': -16.200258, ' ranks': -16.234886, ' lives': -16.248154, ' players': -16.24884, ' runs': -16.258774, 'Play': -16.446884, ' appears': -16.519894, ' takes': -16.53061, ' goes': -16.708273, ' owns': -16.71103, ' heads': -16.760098, ' is': -16.86196, ' (': -16.863142, ' plans': -16.882437, ' particip': -16.962082, ' displays': -16.980917, ' makes': -17.043667, ' trains': -17.119793, ' domin': -17.212025, ' comes': -17.461561, ' champions': -17.510763, ' begins': -17.517866, ' enters': -17.553272, ' plants': -17.601017, ' presents': -17.604506, ' jo': -17.615173, ' stays': -17.615566, ' pairs': -17.62498, ' streams': -17.64537, ' puts': -17.646055, ' sets': -17.6525, ' passes': -17.685743, ' speaks': -17.69949, ',': -17.706156, ' contracts': -17.744537, ' supports': -17.772816, ' continues': -17.795633, ' head': -17.80433, ' shows': -17.847446, ' suits': -17.862688, ' produces': -17.88874, ' functions': -17.900719, ' faces': -17.918339, ' wages': -17.921047, ' builds': -17.921946, ' shares': -17.934635, ' and': -17.98304, ' follows': -18.010067, 's': -18.015205, ' port': -18.040886, ' clubs': -18.132494, ' scores': -18.163305, ' игра': -18.175636, ' features': -18.211216, ' shoot': -18.21645, ' signs': -18.2469, ' looks': -18.252895, ' cont': -18.281132, ' plates': -18.315836, ' p': -18.3744, ' we': -18.377071, ' races': -18.383389, 'PLAY': -18.451843, ' lif': -18.456673, ' Pl': -18.461872, ' opens': -18.483727, ' the': -18.505054, ' focuses': -18.610748, ' helps': -18.612638, ' jou': -18.623257, ' pre': -18.63338, ' loves': -18.667126}, {' as': -0.16231762, ' for': -1.9002651, ' forward': -9.151884, ',': -9.22447, ' in': -9.641142, ' at': -12.170465, 'for': -12.301222, ' from': -12.465084, ' and': -13.119567, ' stri': -13.224159, 'as': -13.719526, ' on': -13.9545555, ' For': -14.10326, ' to': -14.232805, '\\n': -14.3737335, ' of': -14.389994, ' ': -14.840485, ' (': -14.9617405, '.': -14.9952545, ' left': -15.0236435, ' alongside': -15.141168, ' the': -15.257387, ' under': -15.345989, ' a': -15.400959, 'forward': -15.453292, ' or': -15.617952, ' along': -15.6183405, ' both': -15.648203, ' для': -15.765034, ' with': -15.821011, ' by': -15.904266, ' As': -15.945378, ' FOR': -16.006289, 'Forward': -16.201468, ' against': -16.23517, ' primarily': -16.266348, ' right': -16.30694, '-': -16.363688, ' -': -16.382833, ' als': -16.39416, ' that': -16.43823, ' towards': -16.474998, ' w': -16.541315, ' как': -16.582094, 'For': -16.641748, ' among': -16.657408, ' out': -16.700174, ' during': -16.72346, ' within': -16.798903, '为': -16.853962, ' top': -16.85874, ' attacking': -17.092161, ' für': -17.1199, ' when': -17.163801, ' after': -17.168, ' exclusively': -17.17719, ' is': -17.189676, ' La': -17.220123, ' profession': -17.25186, ' club': -17.33381, 'As': -17.364021, ' toward': -17.435297, '--': -17.453106, '/': -17.45759, ':': -17.484344, 'stri': -17.584526, ' up': -17.587011, ' ahead': -17.591215, ' leading': -17.633684, ' --': -17.749155, ' mainly': -17.78859, ' teams': -17.79767, '—': -17.82243, '為': -17.826893, ' I': -17.83572, ' before': -17.846485, ' this': -17.864101, ' clubs': -17.880259, ' if': -17.908857, ' respectively': -17.920921, ' forth': -17.94369, ' football': -17.97168, ' –': -17.980211, ' through': -17.995583, ' first': -18.009058, ' because': -18.02587, 'in': -18.026022, ' Manchester': -18.04274, \"'\": -18.082184, ' —': -18.097939, ' attack': -18.102896, ' again': -18.12067, ' part': -18.145208, ' off': -18.170338, ' star': -18.181087, ' tops': -18.199205, ' league': -18.222597, ' [': -18.237751, ' upon': -18.264359, ' mostly': -18.281433}, {' a': -2.8610189e-06, ' the': -12.892368, ' an': -15.758994, '\\n': -16.145695, 'a': -16.275213, ' ': -16.479382, ' forward': -16.840038, ' stri': -17.40804, ' both': -17.752136, ' one': -18.016073, ' w': -18.068663, ' part': -19.06969, ' A': -19.310917, ' as': -20.030481, ' their': -20.52003, ' а': -20.659626, 'Forward': -20.670187, ' attacking': -20.717033, ' attack': -21.020914, ' in': -21.151653, ' such': -21.179974, ' For': -21.21644, ',': -21.259846, ' Argent': -21.263403, ' \"': -21.289621, ' The': -21.292759, ' that': -21.580963, ' its': -21.662935, 'forward': -21.856276, ' this': -21.90095, ' ': -22.000402, ' and': -22.04911, ' another': -22.099842, ' captain': -22.127184, 'stri': -22.191614, ' (': -22.243263, ' at': -22.291393, ' well': -22.354609, ' I': -22.35509, ' El': -22.358122, ' either': -22.379673, ' our': -22.427788, ' for': -22.452759, '...': -22.55087, ' Argentina': -22.606874, ' arg': -22.624037, ' no': -22.67655, ' or': -22.762823, \" '\": -22.76814, ' team': -22.772257, ' am': -22.901682, ' what': -22.901785, ' al': -22.939142, '\"': -23.009623, ' your': -23.036928, ' front': -23.07995, ' any': -23.080183, ' to': -23.108091, ' Ros': -23.149961, ' some': -23.157614, ' something': -23.164204, ' it': -23.232008, ':': -23.235756, ' No': -23.265478, ' someone': -23.270536, ' is': -23.278198, ' left': -23.286932, ' La': -23.292732, ' Par': -23.328365, ' Spanish': -23.3365, ' M': -23.357695, ' P': -23.371185, ' his': -23.406588, ' ...': -23.418709, ' Joan': -23.427687, ' we': -23.480791, ' Barcelona': -23.500935, ' senior': -23.516294, ' on': -23.532703, ' s': -23.581026, ' Spain': -23.581396, ' t': -23.584192, ' E': -23.645226, ' quite': -23.661337, ' of': -23.666431, ' Both': -23.674711, ' attacked': -23.679964, ' head': -23.684435, ' Att': -23.70061, 'A': -23.721437, ' W': -23.728468, '.': -23.731634, ' mid': -23.740063, ' Jack': -23.745451, ' New': -23.767931, '-': -23.776161, ' those': -23.779026, ' een': -23.810833, ' more': -23.826756, ' these': -23.861647}, {' forward': -0.00061576476, ' w': -7.679374, 'forward': -9.6202965, ' stri': -10.090702, 'Forward': -10.117655, ' left': -12.861166, ' front': -14.62882, ' right': -15.33688, ' attacking': -15.371847, ' mid': -15.396719, ' For': -15.848337, ' free': -16.165491, ' fork': -16.388693, ' star': -16.449041, ' forth': -16.504961, ' forg': -16.612003, ' progressive': -16.820616, ' attack': -17.109272, ' FOR': -17.227865, ' captain': -17.455145, ' center': -17.478067, ' backward': -17.532986, ' football': -17.64008, 'stri': -17.650925, ' part': -17.916103, ' for': -17.984037, ' senior': -18.016691, ' first': -18.097597, ' former': -18.314909, ' Spanish': -18.325083, ' central': -18.332218, ' fore': -18.364555, ' striking': -18.374025, ' forgotten': -18.422789, ' forget': -18.522238, 'For': -18.61932, ' productive': -18.666332, ' second': -18.765657, ' leading': -18.846563, ' short': -18.954054, ' late': -18.980074, 'FOR': -19.004303, 'ford': -19.02582, ' goal': -19.116991, ' ': -19.15077, ' fre': -19.183828, ' forgive': -19.192762, ' fict': -19.207273, ' Argent': -19.256989, ' stock': -19.285494, ' \"': -19.294287, ' principal': -19.354399, ' field': -19.409344, '\\n': -19.4313, ' centre': -19.44238, ' play': -19.454622, ' team': -19.472143, ' club': -19.483816, ' substitute': -19.517054, ' vers': -19.554258, ' forgot': -19.572172, ' professional': -19.572542, ' stagger': -19.593143, ' primary': -19.601704, ' top': -19.605724, ' creative': -19.62604, ' new': -19.748867, ' forum': -19.74956, ' foot': -19.750677, ' wand': -19.788244, ' vice': -19.88888, ' wing': -19.891596, ',': -19.92357, ' fundamental': -19.941118, ' form': -19.94272, ' backwards': -19.963118, ' future': -20.037155, ' in': -20.056597, ' wide': -20.062876, ' stand': -20.067205, ' phil': -20.07268, ' st': -20.08354, 'left': -20.093878, ' false': -20.109728, ' waved': -20.117651, ' fantasy': -20.203238, ' starting': -20.210497, ' vocal': -20.246008, ' skip': -20.266909, ' functional': -20.27078, ' folk': -20.299873, 'ward': -20.32235, ' out': -20.344711, ' wid': -20.34505, ' a': -20.355444, ' weekly': -20.367386, ' super': -20.37402, ' back': -20.382608, ' running': -20.398046, ' frequent': -20.401821}, {' for': -0.0015592334, ' and': -6.6294317, ' or': -8.609755, ' in': -10.507683, 'for': -11.127688, ' at': -13.244388, ',': -13.319205, ' (': -13.901158, '/': -14.047148, ' w': -14.063869, '-': -14.083773, ' with': -14.683714, ' by': -14.776235, ' as': -14.857888, ' of': -14.892798, ' для': -14.982116, ' to': -15.128164, ' on': -15.128511, ' For': -15.369998, ' ': -15.417268, ' &': -15.475892, '\\n': -15.555674, ' from': -15.585766, ' both': -15.932153, ' towards': -16.06147, ' team': -16.40502, ' the': -16.417707, 'or': -16.450022, 'and': -16.48395, 'For': -16.492289, ' club': -16.571253, ' für': -16.70831, ' along': -17.09096, ' primarily': -17.151115, ' against': -17.230972, ' voor': -17.275774, ' FOR': -17.302687, ' during': -17.308325, 'er': -17.397093, '(': -17.527184, ' within': -17.536398, ' throughout': -17.549875, ' after': -17.726217, ' /': -17.758493, ' teams': -17.788643, 'in': -17.800154, ' star': -17.861183, ' free': -18.000372, ' under': -18.041967, ' mainly': -18.05388, ' [': -18.101957, ' stri': -18.161886, '.': -18.175085, 'forall': -18.189579, ' toward': -18.219503, ' that': -18.26422, ' right': -18.266375, ' New': -18.294464, ' a': -18.30329, ' captain': -18.338846, ' through': -18.387482, 'man': -18.465376, ' respectively': -18.510912, '—': -18.518707, ' -': -18.532536, ' clubs': -18.558079, ' mid': -18.564085, ' Art': -18.574278, ' alongside': -18.598534, ' amid': -18.619406, ' is': -18.628626, ' all': -18.640947, ' until': -18.685217, '_': -18.700071, ' artist': -18.706799, ' fort': -18.740452, ' every': -18.77369, ' but': -18.806473, 'ing': -18.821917, ' position': -18.866318, ' senior': -18.868303, ' when': -18.870409, ' major': -18.88466, ' leading': -18.899305, '--': -18.910069, \"'\": -18.919256, ' squad': -18.928923, ' man': -18.935057, ' player': -18.946611, ' form': -18.95374, 'ed': -18.977882, ' not': -19.003786, ' exclusively': -19.02389, ' dla': -19.046614, ' And': -19.052294, ' Major': -19.053148, ' Club': -19.055468, ' nor': -19.05603, ' för': -19.057076, ' wearing': -19.060846}, {' Paris': -0.056626014, ' the': -3.2265613, ' L': -4.4194045, ' FC': -6.930531, ' French': -6.957626, ' Parad': -7.882582, ' Par': -8.352086, 'Par': -8.6637745, ' both': -9.177451, ' PS': -9.362507, ' F': -9.427253, ' La': -10.246182, ' Barcelona': -10.361265, ' PAR': -10.539731, ' Spanish': -10.555314, 'FC': -10.844618, ' Manchester': -11.271921, ' Argent': -11.466321, ' Italian': -11.613904, ' LA': -11.679838, ' parad': -11.798521, ' Para': -11.814141, ' Saudi': -11.897744, ' France': -12.042913, ' Premier': -12.248271, ' ': -12.451475, ' para': -12.513013, ' paras': -12.597231, ' English': -12.638716, ' Pars': -12.721891, ' paragraph': -12.916301, 'the': -13.041223, ' Argentina': -13.097636, ' Parl': -13.164411, 'PAR': -13.342896, ' Ferr': -13.353175, ' Mexican': -13.361949, 'L': -13.419952, ' an': -13.466538, ' M': -13.554302, ' Atlanta': -13.565688, ' South': -13.56836, ' football': -13.568617, ' la': -13.73903, ' a': -13.768078, ' Serie': -13.844593, ' Pan': -13.891177, '\\n': -13.903245, ' Liga': -13.992048, ' clubs': -14.090483, ' Parse': -14.190793, ' P': -14.211453, 'Parser': -14.242355, ' club': -14.258192, ' professional': -14.267856, ' Spain': -14.317567, 'F': -14.318238, ' Major': -14.351862, ',': -14.356924, ' Parliament': -14.393185, ' Los': -14.400403, ' The': -14.4039345, ' Lion': -14.415779, 'paragraph': -14.416884, ' various': -14.471248, ' Inter': -14.503215, ' and': -14.512346, ' Chile': -14.57261, ' Peru': -14.588896, ' several': -14.595111, ' Fred': -14.601483, ' parish': -14.603291, ' soccer': -14.627115, ' our': -14.6282425, ' teams': -14.659058, ' American': -14.666446, ' FIFA': -14.686265, ' major': -14.689431, ' leading': -14.697568, 'PS': -14.699828, ' its': -14.705061, ' Latin': -14.720634, ' this': -14.728008, ' rival': -14.728202, ' par': -14.744674, ' renown': -14.783084, ' Miami': -14.785859, ' Brazil': -14.801269, ' Football': -14.811038, ' Milan': -14.817174, ' PC': -14.902036, ' UEFA': -14.926756, ' Portuguese': -14.930895, ' Atl': -14.93474, ' Federation': -14.937571, ' Club': -14.944723, ' Santiago': -15.0051775, ' Pere': -15.016163, ' Param': -15.017214, 'Parse': -15.027188}, {' Saint': -0.0002311201, 'Saint': -8.487478, ' St': -11.050081, '-': -11.677761, ' S': -14.733017, ' saint': -16.009516, '\\n': -16.10813, ' ': -17.97645, ' Sant': -18.202913, ' San': -18.212606, ' Santa': -18.242485, ' Sac': -18.457434, ' São': -18.893856, ' Paris': -19.134024, ' ST': -19.231438, ' Gal': -19.334764, ' Stock': -19.438433, ' Sport': -19.681646, ' Stanford': -19.849628, ' Star': -20.084517, '–': -20.196938, ' F': -20.263128, ' SA': -20.304708, ' Seine': -20.383944, ' stain': -20.477884, ' Sta': -20.4835, ' Soci': -20.604101, 'St': -20.640856, 'ian': -20.694288, ' Stockholm': -20.734991, ' Ś': -20.746973, 'G': -20.92346, ' Solar': -20.939222, ' Soc': -20.956846, ',': -20.979986, ' Stat': -21.033756, ' D': -21.079515, ' С': -21.115753, ' SV': -21.13896, ' Studio': -21.198612, 'Static': -21.203672, 'sigma': -21.204077, ' in': -21.301447, ' G': -21.360697, 'Sigma': -21.384993, ' Sa': -21.38824, 'SG': -21.395714, ' FC': -21.491121, ' Sax': -21.53655, ' Gren': -21.564402, ' Street': -21.574598, ' stri': -21.583897, ' Sto': -21.602104, ' Germ': -21.621935, ' Statement': -21.668753, ' Space': -21.672108, ' Som': -21.734968, ' Stars': -21.756718, ' Gr': -21.77209, ' Sat': -21.778294, ' de': -21.81395, ' Stan': -21.819979, ' Storm': -21.827028, ' Singapore': -21.833992, ' R': -21.836636, '圣': -21.855127, ' Student': -21.864496, ' Serie': -21.887062, ' Sav': -21.89945, ' Sim': -21.903173, ' Stuart': -21.917313, ' Stadium': -21.926136, ' Сан': -21.970766, ' -': -21.97521, ' Sau': -21.986202, ' Sev': -21.989214, ' Str': -22.005558, ' Salv': -22.008797, ' Sad': -22.020315, ' stake': -22.027653, ' Summer': -22.030622, ' Mont': -22.034477, ' French': -22.07691, ' Gro': -22.083628, '/': -22.088518, ' Still': -22.093859, ' Spe': -22.103958, ' and': -22.11533, ' W': -22.147028, ' Holy': -22.218939, ' V': -22.2535, ' Ster': -22.262611, ' Station': -22.276094, ' The': -22.293547, ' Gall': -22.299255, ' Stanley': -22.300047, ' stab': -22.302233, ' SM': -22.306995, '.': -22.33403, 'SA': -22.338713}]}, 'finish_reason': 'length'}], 'usage': {'prompt_tokens': 50, 'completion_tokens': 20, 'total_tokens': 70}}\n"
]
}
],
"metadata": {
"id": "brmZSfN5ic8_",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "67c41774-5daf-4a88-fec1-890ea0213d3a"
}
},
{
"cell_type": "markdown",
"source": [
"Dans un premier temps, creer un fonction retournant une liste N génération avec le modele mistral avec une temperature de 1. Ces N génération constiturons notre échantillon de base.\n"
],
"metadata": {
"id": "PqdldZZ6lvdA"
}
},
{
"cell_type": "code",
"execution_count": 10,
"source": [
"from tqdm import tqdm\n",
"def sample(query,nb_sample):\n",
" prompt = f\"\"\"\n",
" You are an AI assistant. Given a question about it, create a short answer. If you don't know the answer, honestly say so.\n",
" Question: {query}\n",
" Answer:\n",
" \"\"\"\n",
" liste = []\n",
" for _ in tqdm(range(nb_sample)) :\n",
" liste.append(gen(query)['choices'][0]['text'])\n",
"\n",
" return liste\n",
"print(sample(\"Whos is Messi ?\", 3))"
],
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"\r 0%| | 0/3 [00:00<?, ?it/s]Llama.generate: prefix-match hit\n",
"\n",
"llama_print_timings: load time = 2950.22 ms\n",
"llama_print_timings: sample time = 11.51 ms / 20 runs ( 0.58 ms per token, 1738.22 tokens per second)\n",
"llama_print_timings: prompt eval time = 0.00 ms / 0 tokens ( -nan ms per token, -nan tokens per second)\n",
"llama_print_timings: eval time = 14536.81 ms / 20 runs ( 726.84 ms per token, 1.38 tokens per second)\n",
"llama_print_timings: total time = 14569.76 ms / 20 tokens\n",
" 33%|███▎ | 1/3 [00:15<00:30, 15.20s/it]Llama.generate: prefix-match hit\n",
"\n",
"llama_print_timings: load time = 2950.22 ms\n",
"llama_print_timings: sample time = 11.96 ms / 20 runs ( 0.60 ms per token, 1672.80 tokens per second)\n",
"llama_print_timings: prompt eval time = 0.00 ms / 0 tokens ( -nan ms per token, -nan tokens per second)\n",
"llama_print_timings: eval time = 13554.36 ms / 20 runs ( 677.72 ms per token, 1.48 tokens per second)\n",
"llama_print_timings: total time = 13581.48 ms / 20 tokens\n",
" 67%|██████▋ | 2/3 [00:29<00:14, 14.89s/it]Llama.generate: prefix-match hit\n",
"\n",
"llama_print_timings: load time = 2950.22 ms\n",
"llama_print_timings: sample time = 11.12 ms / 20 runs ( 0.56 ms per token, 1797.75 tokens per second)\n",
"llama_print_timings: prompt eval time = 0.00 ms / 0 tokens ( -nan ms per token, -nan tokens per second)\n",
"llama_print_timings: eval time = 12548.51 ms / 20 runs ( 627.43 ms per token, 1.59 tokens per second)\n",
"llama_print_timings: total time = 12573.55 ms / 20 tokens\n",
"100%|██████████| 3/3 [00:43<00:00, 14.52s/it]"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"[' Lionel Messi is a world-renowned Argentine professional footballer who currently plays as a', \" I'm sorry for any confusion, but the question seems to be incomplete. 'Whos\", ' Lionel Messi is an Argentine professional footballer who currently plays as a forward for Paris Saint']\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"\n"
]
}
],
"metadata": {
"id": "R2xEgEU3nRio",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "afb13892-b536-463f-f76b-81d298b8276a"
}
},
{
"cell_type": "markdown",
"source": [
"Implémenter ensuite une fonction qui permet de séparer un string en une liste de phrase. Un conseil utiliser nltk 😉"
],
"metadata": {
"id": "VUvKegafpU-t"
}
},
{
"cell_type": "code",
"execution_count": 12,
"source": [
"!pip install nltk\n",
"\n",
"# Exemple de string\n",
"texte = \"Bonjour! Comment ça va? J'espère que vous allez bien. Passez une bonne journée.\"\n",
"\n",
"\n",
"def separate(passage=texte):\n",
" import nltk\n",
" nltk.download('punkt')\n",
"\n",
" from nltk.tokenize import sent_tokenize\n",
"\n",
"\n",
" # Tokenisation des phrases\n",
" phrases = sent_tokenize(passage)\n",
"\n",
" # Afficher la liste de phrases\n",
"\n",
" return phrases\n",
"\n",
"print(separate())"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Requirement already satisfied: nltk in /usr/local/lib/python3.10/dist-packages (3.8.1)\n",
"Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from nltk) (8.1.7)\n",
"Requirement already satisfied: joblib in /usr/local/lib/python3.10/dist-packages (from nltk) (1.4.2)\n",
"Requirement already satisfied: regex>=2021.8.3 in /usr/local/lib/python3.10/dist-packages (from nltk) (2024.5.15)\n",
"Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from nltk) (4.66.4)\n",
"['Bonjour!', 'Comment ça va?', \"J'espère que vous allez bien \\n Passez une bonne journée.\"]\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"[nltk_data] Downloading package punkt to /root/nltk_data...\n",
"[nltk_data] Package punkt is already up-to-date!\n"
]
}
],
"metadata": {
"id": "Wa7EgaiqpUPV",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "80160f8d-2530-4889-9c8e-f6da32ad1450"
}
},
{
"cell_type": "markdown",
"source": [
"Creer un fonction permettant d'implémenter cette formule:\n",
"\n",
"\n",
"\n",
"où Snli(i) correspond au score moyen de cohérence entre la i-ème phrase de la génération initiale et chaque échantillon. Sn correspond à la n-ème génération de l'échantillon et ri correspond à la i-ème phrase de la génération initiale. Enfin, P(contradict|ri,Sn) corrrespond à la probabilité que la phrase ri contredise la génération Sn. Cette probabilité est donnée par le model de classifications DeBerta importer juste au dessus.\n"
],
"metadata": {
"id": "IKfxOeTUzWnH"
}
},
{
"cell_type": "code",
"execution_count": 13,
"source": [
"def compute_score_phrase(sentence, samples):\n",
" import numpy as np\n",
" L = np.array([])\n",
" import torch\n",
" from transformers import AutoTokenizer, AutoModelForSequenceClassification\n",
" import torch.nn.functional as F\n",
"\n",
" # Charger le modèle et le tokenizer DeBERTa\n",
" model_name = \"microsoft/deberta-v3-large\"\n",
" tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
" model = AutoModelForSequenceClassification.from_pretrained(model_name)\n",
"\n",
" # Fonctions pour calculer la probabilité de contradiction\n",
" def get_contradiction_probability(ri, Sn):\n",
" inputs = tokenizer(ri, Sn, return_tensors=\"pt\", truncation=True, padding=True)\n",
" with torch.no_grad():\n",
" outputs = model(**inputs)\n",
" logits = outputs.logits\n",
" probs = F.softmax(logits, dim=-1)\n",
" contradiction_prob = probs[0][2].item() # La classe \"contradiction\" est souvent la troisième classe (index 2)\n",
" return contradiction_prob\n",
" for sample in samples:\n",
" L.append(get_contradiction_probability(sentence, sample))\n",
" scores_per_sentence = np.sum(L)/len(L)\n",
" return scores_per_sentence\n",
"\n"
],
"outputs": [],
"metadata": {
"id": "Yh-pbeJppRW9"
}
},
{
"cell_type": "markdown",
"source": [
"Avec toute les fonctions définies précedemment implémenter une SelcheckNLI qui permet de calculer le score d'hallucination d'une génération. La fonction prendra en argumant la query de l'utilisateur, le passage genrer du llm et le nombre de sample. Tester la méthode avec des questions qui font halluciner le modèle et d'autres qui ne font pas halluciner le modèle. Voici le genre de question qui peuvent faire halluciner un modèle:\n",
"\n",
"On choisira un nombre de sample égale à 5.\n",
"Concluez sur l'efficacité de la méthode SelfCheckNLI pour la détection d'hallucination. Quelles sont les limites de cette méthode ?"
],
"metadata": {
"id": "iqO2jxOh1gqk"
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"def selfchecknli(query,generation,nb_sample):\n",
" ###\n",
" return###"
],
"outputs": [],
"metadata": {
"id": "Ob5OiJHVzwhr"
}
},
{
"cell_type": "markdown",
"source": [
"Implémenter sur votre RAG une solution se basant sur SelcheckNLI pour pouvoir filtrer les hallucinations. Par exemple, lorsque une réponse à un score supérieur à un certains seuil le LLM devra avertir l'utilisateur qu'il n'est pas certains de sa réponse.\n"
],
"metadata": {
"id": "0ddIXuMG_JBE"
}
},
{
"cell_type": "markdown",
"source": [
"#Bonus:\n",
"\n",
"\n",
"1. Réalisez un dataset d'une vingtaine de questions comportant des questions qui font halluciner le LLM mistral et d'autres qui n'en font pas. Le dataset devra être équilibré\n",
"2. Générez des réponses pour chaque questions avec le LLM Mistral-7B et annotez chaque passage d'un 1 pour une hallucination, d'un 0 pour un passage factuel.\n",
"3. Pour chaque, passage attribuer un score d'hallucination avec SelfCheckNLI.\n",
"4. Afficher une matrice de confusion.\n",
"5. Tracer la courbe AUC PR. Concluez.\n",
"6. Determiner un seuil optimale pour detecter les hallucination par la méthode de votre choix."
],
"metadata": {
"id": "16QZjrwv8kGp"
}
},
{
"cell_type": "code",
"execution_count": null,
"source": [],
"outputs": [],
"metadata": {
"id": "PPNc794S8jT5"
}
}
],
"metadata": {
"accelerator": "GPU",
"colab": {
"gpuType": "T4",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
} |