Instructions to use nsr51324/CortexRAG with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use nsr51324/CortexRAG with sentence-transformers:
from sentence_transformers import CrossEncoder model = CrossEncoder("nsr51324/CortexRAG") query = "Which planet is known as the Red Planet?" passages = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", "Saturn, famous for its rings, is sometimes mistaken for the Red Planet." ] scores = model.predict([(query, passage) for passage in passages]) print(scores) - Notebooks
- Google Colab
- Kaggle
File size: 108,806 Bytes
201270e | 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 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 | {
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"gpuType": "T4"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "9xh0AtrJe4el"
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import re\n",
"import unicodedata"
]
},
{
"cell_type": "code",
"source": [
"path = \"/content/AHD_english.xlsx\"\n",
"\n",
"df = pd.read_excel(\n",
" path,\n",
" engine=\"openpyxl\"\n",
")\n",
"\n",
"df.head()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 206
},
"id": "Qa8WnEcRgHx6",
"outputId": "7e196b4e-c042-4410-d946-1d9f9e57031d"
},
"execution_count": 2,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Question \\\n",
"0 A breast MRI was performed, showing a non-mass... \n",
"1 I suffer from things that force me to do thing... \n",
"2 I want to inquire about the complications of b... \n",
"3 Today I feel that I have something inside my a... \n",
"4 Why do I suddenly feel like I don't know how t... \n",
"\n",
" Answer Category \n",
"0 What is important in the matter is what is the... General Surgery \n",
"1 Peace be upon you, you need a psychotherapist ... Psychiatric illness \n",
"2 Like other surgical operations, the process of... Endocrine diseases \n",
"3 The condition is most likely to reflect third-... General Surgery \n",
"4 Possibly organic or a side effect of any medic... Psychiatric illness "
],
"text/html": [
"\n",
" <div id=\"df-941b2545-ef66-4cfd-9928-913984d733d8\" class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Question</th>\n",
" <th>Answer</th>\n",
" <th>Category</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>A breast MRI was performed, showing a non-mass...</td>\n",
" <td>What is important in the matter is what is the...</td>\n",
" <td>General Surgery</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>I suffer from things that force me to do thing...</td>\n",
" <td>Peace be upon you, you need a psychotherapist ...</td>\n",
" <td>Psychiatric illness</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>I want to inquire about the complications of b...</td>\n",
" <td>Like other surgical operations, the process of...</td>\n",
" <td>Endocrine diseases</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Today I feel that I have something inside my a...</td>\n",
" <td>The condition is most likely to reflect third-...</td>\n",
" <td>General Surgery</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Why do I suddenly feel like I don't know how t...</td>\n",
" <td>Possibly organic or a side effect of any medic...</td>\n",
" <td>Psychiatric illness</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-941b2545-ef66-4cfd-9928-913984d733d8')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-941b2545-ef66-4cfd-9928-913984d733d8 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-941b2545-ef66-4cfd-9928-913984d733d8');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
"\n",
" </div>\n",
" </div>\n"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "dataframe",
"variable_name": "df"
}
},
"metadata": {},
"execution_count": 2
}
]
},
{
"cell_type": "code",
"source": [
"df.info()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "bpCnFcljhai4",
"outputId": "106b8cfe-ed7e-44ad-be95-2e9e4f7d3b9b"
},
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"RangeIndex: 808472 entries, 0 to 808471\n",
"Data columns (total 3 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 Question 808470 non-null object\n",
" 1 Answer 808470 non-null object\n",
" 2 Category 808472 non-null object\n",
"dtypes: object(3)\n",
"memory usage: 18.5+ MB\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"df.isna().sum()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 178
},
"id": "2ECpf3t8h26D",
"outputId": "cae9e7f0-6255-4045-cfff-f11ce1f27ca2"
},
"execution_count": 4,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Question 2\n",
"Answer 2\n",
"Category 0\n",
"dtype: int64"
],
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Question</th>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Answer</th>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Category</th>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div><br><label><b>dtype:</b> int64</label>"
]
},
"metadata": {},
"execution_count": 4
}
]
},
{
"cell_type": "code",
"source": [
"for category in [\"diabetes\", \"Endocrine diseases\"]:\n",
" if category in df[\"Category\"].values:\n",
" print(f\"{category}: Found\")\n",
" else:\n",
" print(f\"{category}: Not Found\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "bmE6B8Srh9yn",
"outputId": "dddcb904-6897-4f40-8d65-de6cae5cbbbd"
},
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"diabetes: Found\n",
"Endocrine diseases: Found\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"data =[]\n",
"for category in [\"diabetes\", \"Endocrine diseases\"]:\n",
" for _,row in df.iterrows():\n",
" if row['Category'] == category:\n",
" data.append(row)\n",
"df = pd.DataFrame(data)"
],
"metadata": {
"id": "HEec7TgEiL-a"
},
"execution_count": 6,
"outputs": []
},
{
"cell_type": "code",
"source": [
"df['Category'].value_counts()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 178
},
"id": "gHHzBerZmFuc",
"outputId": "2fa470cd-9555-4a54-9606-826dc8ae5c7b"
},
"execution_count": 7,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Category\n",
"Endocrine diseases 9237\n",
"diabetes 7147\n",
"Name: count, dtype: int64"
],
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>count</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Category</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Endocrine diseases</th>\n",
" <td>9237</td>\n",
" </tr>\n",
" <tr>\n",
" <th>diabetes</th>\n",
" <td>7147</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div><br><label><b>dtype:</b> int64</label>"
]
},
"metadata": {},
"execution_count": 7
}
]
},
{
"cell_type": "code",
"source": [
"output_path = \"/content/AHD_english_cleaned.xlsx\"\n",
"\n",
"df.to_excel(\n",
" output_path,\n",
" index=False,\n",
" engine=\"openpyxl\"\n",
")\n",
"\n",
"print(f\"Saved successfully: {output_path}\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "A1fpPvP15YjW",
"outputId": "2f001e15-e77e-4a0b-f612-3b3c6e402fa9"
},
"execution_count": 8,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Saved successfully: /content/AHD_english_cleaned.xlsx\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"df"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 424
},
"id": "15Sce7j7mMFg",
"outputId": "700cdae7-2d8d-4f2c-ca18-6736bcff5a04"
},
"execution_count": 9,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Question \\\n",
"6629 If the patient enters a diabetic coma and we d... \n",
"12015 I suffer from dizziness and my blood sugar lev... \n",
"14653 I am diabetic 2. I take Amaryl 2 ml before foo... \n",
"15283 Age 54, normal blood pressure, weight 74, heig... \n",
"20096 When I test my blood sugar after fasting for 7... \n",
"... ... \n",
"808249 Can hirsutism be an obstacle to pregnancy sinc... \n",
"808332 In the name of God, the most gracious, the mos... \n",
"808335 I have a sister who suffers from hyperthyroidi... \n",
"808336 I was on duty at the hospital when a woman cam... \n",
"808350 Does a mild deficiency in the hormone thyroxin... \n",
"\n",
" Answer Category \n",
"6629 Hyperglycemic coma does not occur suddenly, bu... diabetes \n",
"12015 Your safety, God willing. It may be normal due... diabetes \n",
"14653 Glycosylated hemoglobin analysis is very impor... diabetes \n",
"15283 Who told you that taking B12 is not according ... diabetes \n",
"20096 Monitor your blood sugar in a laboratory, not ... diabetes \n",
"... ... ... \n",
"808249 Hirsutism can be a cause of contraception, but... Endocrine diseases \n",
"808332 What you mentioned in your question constitute... Endocrine diseases \n",
"808335 This medicine should not be used during pregna... Endocrine diseases \n",
"808336 The condition goes away with the use of birth ... Endocrine diseases \n",
"808350 This is easy to find out by giving the infant ... Endocrine diseases \n",
"\n",
"[16384 rows x 3 columns]"
],
"text/html": [
"\n",
" <div id=\"df-d7dd7ed9-9ed0-4b44-9e2d-45bb34824c19\" class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Question</th>\n",
" <th>Answer</th>\n",
" <th>Category</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>6629</th>\n",
" <td>If the patient enters a diabetic coma and we d...</td>\n",
" <td>Hyperglycemic coma does not occur suddenly, bu...</td>\n",
" <td>diabetes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12015</th>\n",
" <td>I suffer from dizziness and my blood sugar lev...</td>\n",
" <td>Your safety, God willing. It may be normal due...</td>\n",
" <td>diabetes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14653</th>\n",
" <td>I am diabetic 2. I take Amaryl 2 ml before foo...</td>\n",
" <td>Glycosylated hemoglobin analysis is very impor...</td>\n",
" <td>diabetes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15283</th>\n",
" <td>Age 54, normal blood pressure, weight 74, heig...</td>\n",
" <td>Who told you that taking B12 is not according ...</td>\n",
" <td>diabetes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20096</th>\n",
" <td>When I test my blood sugar after fasting for 7...</td>\n",
" <td>Monitor your blood sugar in a laboratory, not ...</td>\n",
" <td>diabetes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>808249</th>\n",
" <td>Can hirsutism be an obstacle to pregnancy sinc...</td>\n",
" <td>Hirsutism can be a cause of contraception, but...</td>\n",
" <td>Endocrine diseases</td>\n",
" </tr>\n",
" <tr>\n",
" <th>808332</th>\n",
" <td>In the name of God, the most gracious, the mos...</td>\n",
" <td>What you mentioned in your question constitute...</td>\n",
" <td>Endocrine diseases</td>\n",
" </tr>\n",
" <tr>\n",
" <th>808335</th>\n",
" <td>I have a sister who suffers from hyperthyroidi...</td>\n",
" <td>This medicine should not be used during pregna...</td>\n",
" <td>Endocrine diseases</td>\n",
" </tr>\n",
" <tr>\n",
" <th>808336</th>\n",
" <td>I was on duty at the hospital when a woman cam...</td>\n",
" <td>The condition goes away with the use of birth ...</td>\n",
" <td>Endocrine diseases</td>\n",
" </tr>\n",
" <tr>\n",
" <th>808350</th>\n",
" <td>Does a mild deficiency in the hormone thyroxin...</td>\n",
" <td>This is easy to find out by giving the infant ...</td>\n",
" <td>Endocrine diseases</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>16384 rows × 3 columns</p>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-d7dd7ed9-9ed0-4b44-9e2d-45bb34824c19')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-d7dd7ed9-9ed0-4b44-9e2d-45bb34824c19 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-d7dd7ed9-9ed0-4b44-9e2d-45bb34824c19');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
"\n",
" <div id=\"id_2db85d00-11b3-4dbc-95a0-41114d4ead05\">\n",
" <style>\n",
" .colab-df-generate {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-generate:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-generate {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-generate:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
" <button class=\"colab-df-generate\" onclick=\"generateWithVariable('df')\"\n",
" title=\"Generate code using this dataframe.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z\"/>\n",
" </svg>\n",
" </button>\n",
" <script>\n",
" (() => {\n",
" const buttonEl =\n",
" document.querySelector('#id_2db85d00-11b3-4dbc-95a0-41114d4ead05 button.colab-df-generate');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" buttonEl.onclick = () => {\n",
" google.colab.notebook.generateWithVariable('df');\n",
" }\n",
" })();\n",
" </script>\n",
" </div>\n",
"\n",
" </div>\n",
" </div>\n"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "dataframe",
"variable_name": "df",
"summary": "{\n \"name\": \"df\",\n \"rows\": 16384,\n \"fields\": [\n {\n \"column\": \"Question\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 16269,\n \"samples\": [\n \"I have been suffering from diabetes for five years. The test while fasting was 110, and two hours after eating, it was 170. I use Dawinil medication, half a pill in the morning, 2.5 mg, and half a pill in the evening. Is my condition satisfactory or do I need...\",\n \"What is the recommended percentage of thyroxine for a pregnant woman in the fifth month, noting that the current dose is 75, and the test included a TSH of 4.79?\",\n \"Girl, I am 23 years old, my weight is 64, and my height is 158\\nI feel dizzy and unfocused. Blood tests are fine. Sugar tests after eating and throughout the day are less than 100 and may reach 90.\\nAnd in case...\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Answer\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 15419,\n \"samples\": [\n \"It does not require treatment if it is not accompanied by symptoms, a\",\n \"Of course, one of the reasons is pregnancy hormones, which require raising the insulin dose from time to time. The rest of the reasons: insufficient dose or failure to adhere to the diet. In any case, the evening dose must be increased by two units.\",\n \"The treatment for high parathyroid hormone is surgery if the cause is in the glands themselves. Tests can be sent. See my article about the parathyroid glands\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Category\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 2,\n \"samples\": [\n \"Endocrine diseases\",\n \"diabetes\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
}
},
"metadata": {},
"execution_count": 9
}
]
},
{
"cell_type": "code",
"source": [
"df.info()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "gDCn391gv0NS",
"outputId": "9e144699-0f8b-4a72-b6a7-8b564d80a318"
},
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"<class 'pandas.core.frame.DataFrame'>\n",
"Index: 16384 entries, 6629 to 808350\n",
"Data columns (total 3 columns):\n",
" # Column Non-Null Count Dtype \n",
"--- ------ -------------- ----- \n",
" 0 Question 16384 non-null object\n",
" 1 Answer 16384 non-null object\n",
" 2 Category 16384 non-null object\n",
"dtypes: object(3)\n",
"memory usage: 512.0+ KB\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"df.isnull().sum()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 178
},
"id": "cKTQzpX7v_Yk",
"outputId": "64fc484a-2086-4c5b-8d6a-6a429157b9cf"
},
"execution_count": 11,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Question 0\n",
"Answer 0\n",
"Category 0\n",
"dtype: int64"
],
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Question</th>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Answer</th>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Category</th>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div><br><label><b>dtype:</b> int64</label>"
]
},
"metadata": {},
"execution_count": 11
}
]
},
{
"cell_type": "code",
"source": [
"df[\"Question\"] = df[\"Question\"].astype(str).str.strip()\n",
"df[\"Answer\"] = df[\"Answer\"].astype(str).str.strip()\n",
"df[\"Category\"] = df[\"Category\"].astype(str).str.strip()"
],
"metadata": {
"id": "RYY9LaKkw3kq"
},
"execution_count": 12,
"outputs": []
},
{
"cell_type": "code",
"source": [
"df.nunique()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 178
},
"id": "6zNFXvNAxMec",
"outputId": "d14c725b-be90-42f5-cf19-8fe90f13b407"
},
"execution_count": 13,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Question 16269\n",
"Answer 15419\n",
"Category 2\n",
"dtype: int64"
],
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Question</th>\n",
" <td>16269</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Answer</th>\n",
" <td>15419</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Category</th>\n",
" <td>2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div><br><label><b>dtype:</b> int64</label>"
]
},
"metadata": {},
"execution_count": 13
}
]
},
{
"cell_type": "code",
"source": [
"question_counts = df[\"Question\"].value_counts()\n",
"\n",
"print(question_counts.head(30))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "XQZ_I7HYxNYV",
"outputId": "030ff975-0711-46f4-b693-0167353e81a6"
},
"execution_count": 14,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Question\n",
"What are the symptoms of diabetes? 19\n",
"What is the treatment for diabetes? 10\n",
"Is there a cure for diabetes? 7\n",
"Symptoms of diabetes 5\n",
"What is the normal blood sugar level? 5\n",
"What is the best treatment for diabetes? 3\n",
"What is the treatment for low blood sugar? 3\n",
"What are the causes of diabetes? 3\n",
"The best treatment for diabetes 3\n",
"Thyroid symptoms 3\n",
"What are the symptoms of thyroid disease? 3\n",
"Is there a definitive cure for diabetes? 3\n",
"I suffer from an underactive thyroid gland 3\n",
"What is the treatment for hypothyroidism? 3\n",
"What are the symptoms of thyroid gland? 3\n",
"The latest treatment for diabetes 3\n",
"What is the treatment for thyroid gland? 3\n",
"What is diabetic foot? 2\n",
"I have been suffering from cancer for a while and recently a diabetic patient. Is there a relationship between the two? What I read is that blood sugar is high in a cancer patient, but the opposite happens and blood sugar is low and... 2\n",
"A cumulative blood sugar test 3 months ago was 6.3, and my weight at the time was 117, and today the result of the test is 5.3, and I have lost 20 kilograms. Does this mean that I have passed the pre-diabetic stage and have become a normal person? 2\n",
"How do I know that I have diabetes? 2\n",
"What foods are beneficial for diabetics? 2\n",
"What are the most important causes of diabetes? 2\n",
"Causes of diabetes 2\n",
"What is the treatment for parotitis? 2\n",
"Symptoms of high blood sugar 2\n",
"What are the symptoms of gestational diabetes? 2\n",
"What are normal blood sugar levels? 2\n",
"What are the most important risk factors for developing type 1 diabetes? 2\n",
"Peace be upon you. When I was 19 years old, I was treated for hypothyroidism. I took the medication leyvotirox50. Now my TSH is moderate. Now I am pregnant. I follow up with the endocrinologist. My questions... 2\n",
"Name: count, dtype: int64\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"question = \"What are the symptoms of diabetes?\"\n",
"\n",
"result = df[df[\"Question\"] == question]\n",
"result = pd.DataFrame(result)\n",
"print(result[[\"Question\", \"Answer\", \"Category\"]].to_string(index=False))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "eK5XFQBhyHFK",
"outputId": "f8ebf0b5-95c1-4dca-97e4-e2bdfbda22d9"
},
"execution_count": 15,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
" Question Answer Category\n",
"What are the symptoms of diabetes? The most important symptoms are frequent urination and excessive thirst. For more information, see diabetes in the dictionary. diabetes\n",
"What are the symptoms of diabetes? Weight loss, laziness, lethargy, frequent urination, thirst, dullness in the eyes, and pain in the body diabetes\n",
"What are the symptoms of diabetes? Diabetes in adults is usually non-specific and insidious, and its most important symptoms are: fatigue, fatigue, weight loss, frequent urination, especially at night, thirst, and difficulty healing boils. Sometimes it is not accidental.\\nBut in children and young adults, it comes on quickly over several days to a few weeks: day and night polyuria. Polydipsia and dry mouth. Good appetite . weight loss . Fatigue and exhaustion. The injured person may experience an emergency condition and be admitted to the hospital immediately diabetes\n",
"What are the symptoms of diabetes? Drink plenty of water\\nFrequent urination\\nFeeling hungry diabetes\n",
"What are the symptoms of diabetes? It is not necessary to have symptoms to diagnose the disease, and if they do exist, the most important of them is increased thirst and urination diabetes\n",
"What are the symptoms of diabetes? Symptoms of diabetes include frequent urination at night, increased thirst, and a sudden decrease in body weight diabetes\n",
"What are the symptoms of diabetes? There are not necessarily symptoms, the most important of which, if present, is an increase in thirst and urination diabetes\n",
"What are the symptoms of diabetes? A lot of urine\\nFrequent thirst\\nweight loss\\nIt may be asymptomatic diabetes\n",
"What are the symptoms of diabetes? There are many symptoms of diabetes, the most important of which are thirst, frequent urination, increased appetite for food, sometimes hunger, itchy skin, general weakness. diabetes\n",
"What are the symptoms of diabetes? The most common symptoms of diabetes are excessive diarrhea, frequent urination, and feeling hungry\\nThere are other less prominent symptoms, such as blurred vision, a feeling of weakness, leg pain, delayed wound healing, and itching.\\nHere it must be noted that there is a large difference in the appearance and severity of these symptoms between patients and according to the type of diabetes. Some symptoms may be completely absent, or they may be minor and do not attract the attention of the affected person, and thus diagnosis is delayed.\\nDue to the widespread spread of diabetes, a group of factors called risk factors have been identified, such as obesity, lack of physical activity, and a history of diabetes in the family. When these factors are present, blood sugar is analyzed even in the absence of the symptoms mentioned. See Diabetes in the dictionary.\\nmy regards diabetes\n",
"What are the symptoms of diabetes? Symptoms do not necessarily exist, but if they do, they include thirst and increased urination diabetes\n",
"What are the symptoms of diabetes? Symptoms do not necessarily exist, and if they do exist, the most important of them is an increase in thirst and urination diabetes\n",
"What are the symptoms of diabetes? There may be no symptoms, but weight loss, frequent urination, teeth loss, and recurring infections may be symptoms. diabetes\n",
"What are the symptoms of diabetes? Increased thirst and urination diabetes\n",
"What are the symptoms of diabetes? Signs and symptoms of type 1 diabetes (insulin-dependent) appear gradually or suddenly, as follows: - Frequent urination. - Excessive thirst. - Weight loss . - Fatigue. - Excessive appetite. - Nausea. - Blurred vision.\\nAs for type 2 diabetes (non-insulin dependent), signs and symptoms of type 2 diabetes do not appear in its early stages, but they may appear in some people as follows: - Frequent urination. - Excessive thirst. - Excessive appetite. - Weight loss . - Blurred vision. - Paresthesias and tingling of the lower extremities. - Fungal infection. - Fatigue and general weakness. diabetes\n",
"What are the symptoms of diabetes? A person may develop diabetes and remain for a long period of time, which may extend to years, without paying attention to any symptoms, because these symptoms may be attributed to other causes. At the beginning of type 2 diabetes, the patient feels non-specific weakness and may suffer from pain of nerve origin in the extremities, and Wound healing may be delayed, and his appetite may remain normal or increase slightly\\nWhen the infection worsens, specific symptoms appear, which are frequent hunger, lack of feeling of fullness, extreme thirst, and frequent urination. In addition, the feeling of weakness, lethargy, nerve pain, delayed wound healing, and common infections such as the common cold increase.\\nStudies have shown that vascular damage that leads to chronic cardiovascular disease begins before any symptoms of diabetes appear and even before there is a sufficient rise in blood sugar to diagnose the disease, that is, the damage begins in the pre-diabetic stage.\\nFor this reason, the risk factors that may be followed by diabetes have been identified, and these factors include a history of diabetes in the family, especially among first-degree relatives, weight gain, age over 40 years, high blood pressure, multiple births, and other factors.\\nTherefore, the best way to detect diabetes is to test your blood sugar periodically and not rely on symptoms\\nmy regards\\n, diabetes\n",
"What are the symptoms of diabetes? Classic symptoms include feeling tired and sick, frequent urination, excessive thirst, excessive hunger, and weight loss.\\nKetoacidosis, a condition caused by starvation or uncontrolled diabetes, is common in type 1 diabetes. Ketones are acidic compounds that form in the blood when the body breaks down fats, lipids, and proteins. Symptoms include abdominal pain, vomiting, rapid breathing, extreme lethargy, and drowsiness. Patients with ketoacidosis have a sweet-smelling breath. If this is not treated, it can lead to coma and death.\\nWith type 2 diabetes, the condition may not become clear until the patient is offered medical treatment for another disease. The patient may complain of heart disease, chronic infection of the gums and urinary tract, and blurred vision. Women may complain of itching in the genitals.\\nSee diabetes in the dictionary. diabetes\n",
"What are the symptoms of diabetes? Classic symptoms include feeling tired and sick, frequent urination, excessive thirst, excessive hunger, and weight loss.\\nKetoacidosis, a condition caused by starvation or uncontrolled diabetes, is common in type 1 diabetes. Ketones are acidic compounds that form in the blood when the body breaks down fats, lipids, and proteins. Symptoms include abdominal pain, vomiting, rapid breathing, extreme lethargy, and drowsiness. Patients with ketoacidosis have a sweet-smelling breath. If this is not treated, it can lead to coma and death.\\nSee sugar in the dictionary.\\nWith type 2 diabetes, the condition may not become clear until the patient is offered medical treatment for another disease. The patient may complain of heart disease, chronic infection of the gums and urinary tract, and blurred vision. Women may complain of itching in the genitals. diabetes\n",
"What are the symptoms of diabetes? Classic symptoms include feeling tired and sick, frequent urination, excessive thirst, excessive hunger, and weight loss.\\nKetoacidosis, a condition caused by starvation or uncontrolled diabetes, is common in type 1 diabetes. Ketones are acidic compounds that form in the blood when the body breaks down fats, lipids, and proteins. Symptoms include abdominal pain, vomiting, rapid breathing, extreme lethargy, and drowsiness. Patients with ketoacidosis have a sweet-smelling breath. If this is not treated, it can lead to coma and death.\\nWith type 2 diabetes, the condition may not become clear until the patient is offered medical treatment for another disease. The patient may complain of heart disease, chronic infection of the gums and urinary tract, and blurred vision. Women may complain of itching in the genitals. See diabetes in the dictionary. diabetes\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"df = df.dropna(subset=[\"Question\", \"Answer\"])"
],
"metadata": {
"id": "aRN4g2Au1Wav"
},
"execution_count": 16,
"outputs": []
},
{
"cell_type": "code",
"source": [
"df[\"Question\"] = df[\"Question\"].astype(str).str.strip()\n",
"df[\"Answer\"] = df[\"Answer\"].astype(str).str.strip()\n",
"df[\"Category\"] = df[\"Category\"].astype(str).str.strip()"
],
"metadata": {
"id": "_ahuAy-O2GUw"
},
"execution_count": 17,
"outputs": []
},
{
"cell_type": "code",
"source": [
"df"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 424
},
"id": "unFePQgr2P0m",
"outputId": "50ad1cdf-1cbe-4e44-9825-c90572fa3cd4"
},
"execution_count": 18,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Question \\\n",
"6629 If the patient enters a diabetic coma and we d... \n",
"12015 I suffer from dizziness and my blood sugar lev... \n",
"14653 I am diabetic 2. I take Amaryl 2 ml before foo... \n",
"15283 Age 54, normal blood pressure, weight 74, heig... \n",
"20096 When I test my blood sugar after fasting for 7... \n",
"... ... \n",
"808249 Can hirsutism be an obstacle to pregnancy sinc... \n",
"808332 In the name of God, the most gracious, the mos... \n",
"808335 I have a sister who suffers from hyperthyroidi... \n",
"808336 I was on duty at the hospital when a woman cam... \n",
"808350 Does a mild deficiency in the hormone thyroxin... \n",
"\n",
" Answer Category \n",
"6629 Hyperglycemic coma does not occur suddenly, bu... diabetes \n",
"12015 Your safety, God willing. It may be normal due... diabetes \n",
"14653 Glycosylated hemoglobin analysis is very impor... diabetes \n",
"15283 Who told you that taking B12 is not according ... diabetes \n",
"20096 Monitor your blood sugar in a laboratory, not ... diabetes \n",
"... ... ... \n",
"808249 Hirsutism can be a cause of contraception, but... Endocrine diseases \n",
"808332 What you mentioned in your question constitute... Endocrine diseases \n",
"808335 This medicine should not be used during pregna... Endocrine diseases \n",
"808336 The condition goes away with the use of birth ... Endocrine diseases \n",
"808350 This is easy to find out by giving the infant ... Endocrine diseases \n",
"\n",
"[16384 rows x 3 columns]"
],
"text/html": [
"\n",
" <div id=\"df-068391b7-a045-4e17-984e-ef4deb7ab321\" class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Question</th>\n",
" <th>Answer</th>\n",
" <th>Category</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>6629</th>\n",
" <td>If the patient enters a diabetic coma and we d...</td>\n",
" <td>Hyperglycemic coma does not occur suddenly, bu...</td>\n",
" <td>diabetes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12015</th>\n",
" <td>I suffer from dizziness and my blood sugar lev...</td>\n",
" <td>Your safety, God willing. It may be normal due...</td>\n",
" <td>diabetes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14653</th>\n",
" <td>I am diabetic 2. I take Amaryl 2 ml before foo...</td>\n",
" <td>Glycosylated hemoglobin analysis is very impor...</td>\n",
" <td>diabetes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15283</th>\n",
" <td>Age 54, normal blood pressure, weight 74, heig...</td>\n",
" <td>Who told you that taking B12 is not according ...</td>\n",
" <td>diabetes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20096</th>\n",
" <td>When I test my blood sugar after fasting for 7...</td>\n",
" <td>Monitor your blood sugar in a laboratory, not ...</td>\n",
" <td>diabetes</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>808249</th>\n",
" <td>Can hirsutism be an obstacle to pregnancy sinc...</td>\n",
" <td>Hirsutism can be a cause of contraception, but...</td>\n",
" <td>Endocrine diseases</td>\n",
" </tr>\n",
" <tr>\n",
" <th>808332</th>\n",
" <td>In the name of God, the most gracious, the mos...</td>\n",
" <td>What you mentioned in your question constitute...</td>\n",
" <td>Endocrine diseases</td>\n",
" </tr>\n",
" <tr>\n",
" <th>808335</th>\n",
" <td>I have a sister who suffers from hyperthyroidi...</td>\n",
" <td>This medicine should not be used during pregna...</td>\n",
" <td>Endocrine diseases</td>\n",
" </tr>\n",
" <tr>\n",
" <th>808336</th>\n",
" <td>I was on duty at the hospital when a woman cam...</td>\n",
" <td>The condition goes away with the use of birth ...</td>\n",
" <td>Endocrine diseases</td>\n",
" </tr>\n",
" <tr>\n",
" <th>808350</th>\n",
" <td>Does a mild deficiency in the hormone thyroxin...</td>\n",
" <td>This is easy to find out by giving the infant ...</td>\n",
" <td>Endocrine diseases</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>16384 rows × 3 columns</p>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-068391b7-a045-4e17-984e-ef4deb7ab321')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-068391b7-a045-4e17-984e-ef4deb7ab321 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-068391b7-a045-4e17-984e-ef4deb7ab321');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
"\n",
" <div id=\"id_14f34313-505c-4770-8f04-85f509af48ce\">\n",
" <style>\n",
" .colab-df-generate {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-generate:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-generate {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-generate:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
" <button class=\"colab-df-generate\" onclick=\"generateWithVariable('df')\"\n",
" title=\"Generate code using this dataframe.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.31,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12Z\"/>\n",
" </svg>\n",
" </button>\n",
" <script>\n",
" (() => {\n",
" const buttonEl =\n",
" document.querySelector('#id_14f34313-505c-4770-8f04-85f509af48ce button.colab-df-generate');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" buttonEl.onclick = () => {\n",
" google.colab.notebook.generateWithVariable('df');\n",
" }\n",
" })();\n",
" </script>\n",
" </div>\n",
"\n",
" </div>\n",
" </div>\n"
],
"application/vnd.google.colaboratory.intrinsic+json": {
"type": "dataframe",
"variable_name": "df",
"summary": "{\n \"name\": \"df\",\n \"rows\": 16384,\n \"fields\": [\n {\n \"column\": \"Question\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 16269,\n \"samples\": [\n \"I have been suffering from diabetes for five years. The test while fasting was 110, and two hours after eating, it was 170. I use Dawinil medication, half a pill in the morning, 2.5 mg, and half a pill in the evening. Is my condition satisfactory or do I need...\",\n \"What is the recommended percentage of thyroxine for a pregnant woman in the fifth month, noting that the current dose is 75, and the test included a TSH of 4.79?\",\n \"Girl, I am 23 years old, my weight is 64, and my height is 158\\nI feel dizzy and unfocused. Blood tests are fine. Sugar tests after eating and throughout the day are less than 100 and may reach 90.\\nAnd in case...\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Answer\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 15419,\n \"samples\": [\n \"It does not require treatment if it is not accompanied by symptoms, a\",\n \"Of course, one of the reasons is pregnancy hormones, which require raising the insulin dose from time to time. The rest of the reasons: insufficient dose or failure to adhere to the diet. In any case, the evening dose must be increased by two units.\",\n \"The treatment for high parathyroid hormone is surgery if the cause is in the glands themselves. Tests can be sent. See my article about the parathyroid glands\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Category\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 2,\n \"samples\": [\n \"Endocrine diseases\",\n \"diabetes\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
}
},
"metadata": {},
"execution_count": 18
}
]
},
{
"cell_type": "code",
"source": [
"df.duplicated().sum()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "h4ZXp9i-2RuG",
"outputId": "cef14668-b12d-4569-dc08-0fbf2d69afef"
},
"execution_count": 19,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"np.int64(8)"
]
},
"metadata": {},
"execution_count": 19
}
]
},
{
"cell_type": "code",
"source": [
"duplicates = df[df.duplicated(keep=False)]\n",
"\n",
"print(duplicates.to_string(index=False))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "KJlgQddugd2w",
"outputId": "c06fbd6f-d51d-45df-a8b8-72e423cf5193"
},
"execution_count": 20,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
" Question Answer Category\n",
" Diabetes treatment This requires an integrated nutritional and therapeutic system under the supervision of the treating physician diabetes\n",
" Diabetes treatment This requires an integrated nutritional and therapeutic system under the supervision of the treating physician diabetes\n",
" The best treatment for diabetes This requires an integrated nutritional and therapeutic system under the supervision of the treating physician diabetes\n",
" Useful fruit for diabetics Moderation in food is the basis of treatment diabetes\n",
" Useful fruit for diabetics Moderation in food is the basis of treatment diabetes\n",
" What is the treatment for high blood sugar? This requires an integrated nutritional and therapeutic system under the supervision of the treating physician diabetes\n",
" The best treatment for diabetes This requires an integrated nutritional and therapeutic system under the supervision of the treating physician diabetes\n",
" What is the treatment for high blood sugar? This requires an integrated nutritional and therapeutic system under the supervision of the treating physician diabetes\n",
" What is the normal blood sugar level? Fasting, less than 100 and two hours after eating, less than 140 diabetes\n",
" What is the normal blood sugar level? Fasting, less than 100 and two hours after eating, less than 140 diabetes\n",
" I used metformin to lose weight for four months. I was eating normally and I lost weight. I was increasing the dose up to 2000, but I feel that its effect is decreasing and the body has become resistant to it. What is the explanation for that? Basically, you should reduce the amount of food you eat diabetes\n",
" I used metformin to lose weight for four months. I was eating normally and I lost weight. I was increasing the dose up to 2000, but I feel that its effect is decreasing and the body has become resistant to it. What is the explanation for that? Basically, you should reduce the amount of food you eat diabetes\n",
" My wife got pregnant after 9 months, knowing that I have been diabetic for 15 years and I am 35. I was treated with vitamin E for a period of time for my disease to affect pregnancy, and it took place after giving birth. The better your blood sugar control is, the more you will maintain the functions of your body’s organs, including sexual function\\nA person with diabetes can marry and have children. Statistics may indicate lower chances of childbearing, but statistics are worthless when each case is evaluated individually.\\nmy regards diabetes\n",
" My wife got pregnant after 9 months, knowing that I have been diabetic for 15 years and I am 35. I was treated with vitamin E for a period of time for my disease to affect pregnancy, and it took place after giving birth. The better your blood sugar control is, the more you will maintain the functions of your body’s organs, including sexual function\\nA person with diabetes can marry and have children. Statistics may indicate lower chances of childbearing, but statistics are worthless when each case is evaluated individually.\\nmy regards diabetes\n",
"A cumulative blood sugar test 3 months ago was 6.3, and my weight at the time was 117, and today the result of the test is 5.3, and I have lost 20 kilograms. Does this mean that I have passed the pre-diabetic stage and have become a normal person? Yes, I have passed the pre-diabetic stage. Persevere in losing weight Endocrine diseases\n",
"A cumulative blood sugar test 3 months ago was 6.3, and my weight at the time was 117, and today the result of the test is 5.3, and I have lost 20 kilograms. Does this mean that I have passed the pre-diabetic stage and have become a normal person? Yes, I have passed the pre-diabetic stage. Persevere in losing weight Endocrine diseases\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"df.drop_duplicates(inplace=True)"
],
"metadata": {
"id": "3H3OtR-Jgpjy"
},
"execution_count": 21,
"outputs": []
},
{
"cell_type": "code",
"source": [
"def clean_text(text):\n",
" if pd.isna(text):\n",
" return \"\"\n",
"\n",
" text = str(text)\n",
"\n",
" # Normalize Unicode\n",
" text = unicodedata.normalize(\"NFKC\", text)\n",
"\n",
" # Replace escaped newlines/tabs\n",
" text = text.replace(\"\\\\n\", \" \")\n",
" text = text.replace(\"\\\\t\", \" \")\n",
"\n",
" # Replace real newlines and tabs with spaces\n",
" text = re.sub(r\"[\\r\\n\\t]+\", \" \", text)\n",
"\n",
" # Remove control characters\n",
" text = \"\".join(\n",
" char for char in text\n",
" if unicodedata.category(char) not in [\"Cc\", \"Cf\"]\n",
" or char in [\"\\n\", \"\\t\"]\n",
" )\n",
"\n",
" # Normalize different quotation marks\n",
" text = text.replace(\"“\", '\"')\n",
" text = text.replace(\"”\", '\"')\n",
" text = text.replace(\"‘\", \"'\")\n",
" text = text.replace(\"’\", \"'\")\n",
"\n",
" # Normalize multiple spaces\n",
" text = re.sub(r\"\\s+\", \" \", text)\n",
"\n",
" # Remove spaces before punctuation\n",
" text = re.sub(r\"\\s+([,.!?;:])\", r\"\\1\", text)\n",
"\n",
" # Remove spaces around parentheses\n",
" text = re.sub(r\"\\(\\s+\", \"(\", text)\n",
" text = re.sub(r\"\\s+\\)\", \")\", text)\n",
"\n",
" return text.strip()"
],
"metadata": {
"id": "pPhOIUG42aT8"
},
"execution_count": 22,
"outputs": []
},
{
"cell_type": "code",
"source": [
"df[\"Question\"] = df[\"Question\"].apply(clean_text)\n",
"df[\"Answer\"] = df[\"Answer\"].apply(clean_text)\n",
"df[\"Category\"] = df[\"Category\"].apply(clean_text)"
],
"metadata": {
"id": "2yrmGHPC46E2"
},
"execution_count": 127,
"outputs": []
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "BbWaNc6wgeQu"
},
"execution_count": null,
"outputs": []
}
]
} |