File size: 106,537 Bytes
b78139c |
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 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 |
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "eBpjBBZc6IvA"
},
"source": [
"# Fatima Fellowship Coding Challenge (Pick 1)\n",
"\n",
"Thank you for applying to the Fatima Fellowship. To help us select the Fellows and assess your ability to do machine learning research, we are asking that you complete a short coding challenge. Please pick **1 of these 5** coding challenges, whichever is most aligned with your interests. These coding challenges are not meant to take too long, do NOT spend more than 4-6 hours on them -- you can submit whatever you have.\n",
"\n",
"**How to submit**: Please make a copy of this colab notebook, add your code and results, and submit your colab notebook along with your application. If you have never used a colab notebook, [check out this video](https://www.youtube.com/watch?v=i-HnvsehuSw)"
]
},
{
"cell_type": "markdown",
"source": [
"\n",
"\n",
"---\n",
"\n",
"\n",
"### **Important**: Beore you get started, please make sure to make a **copy of this notebook** and set sharing permissions so that **anyone with the link can view**. Otherwise, we will NOT be able to assess your application.\n",
"\n",
"\n",
"\n",
"---\n",
"\n"
],
"metadata": {
"id": "lQNUZjvuRt-m"
}
},
{
"cell_type": "markdown",
"metadata": {
"id": "braBzmRpMe7_"
},
"source": [
"# 1. Deep Learning for Vision"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "1IWw-NZf5WfF"
},
"source": [
"**Generated by AI detector**: Train a model to detect if images are generated by AI\n",
"\n",
"* Find a dataset of natural images and images generated by AI (here is one such dataset on the [Hugging Face Hub](https://huggingface.co/datasets/competitions/aiornot) but you're welcome to use any dataset you've found.\n",
"* Create a training and test set.\n",
"* Build a neural network (using Tensorflow, PyTorch, or any framework you like)\n",
"* Train it to classify the image as being generated by an AI or not until a reasonable accuracy is reached\n",
"* [Upload the the model to the Hugging Face Hub](https://huggingface.co/docs/hub/adding-a-model), and add a link to your model below.\n",
"* Look at some of the images that were classified incorrectly. Please explain what you might do to improve your model's performance on these images in the future (you do not need to impelement these suggestions)\n",
"\n",
"**Submission instructions**: Please write your code below and include some examples of images that were classified"
]
},
{
"cell_type": "code",
"source": [
"### WRITE YOUR CODE TO TRAIN THE MODEL HERE\n",
"print('Hi')"
],
"metadata": {
"id": "K2GJaYBpw91T",
"outputId": "f26681e5-f682-42d2-e837-f949a159c779",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Hi\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"**Write up**: \n",
"* Link to the model on Hugging Face Hub: \n",
"* Include some examples of misclassified images. Please explain what you might do to improve your model's performance on these images in the future (you do not need to impelement these suggestions)\n",
"\n",
"[Please put your write up here]"
],
"metadata": {
"id": "qSeLed2JxvGI"
}
},
{
"cell_type": "markdown",
"metadata": {
"id": "sFU9LTOyMiMj"
},
"source": [
"# 2. Deep Learning for NLP\n",
"\n",
"**Fake news classifier**: Train a text classification model to detect fake news articles!\n",
"\n",
"* Download the dataset here: https://www.kaggle.com/datasets/sadikaljarif/fake-news-detection-dataset-english (if you'd like, you can also look at fake news datasets in other languages, which are available on the Huggingface Hub)\n",
"* Develop an NLP model for classification that uses a pretrained language model and the *text* of the article. It should *NOT* use the URL\n",
"* Finetune your model on the dataset, and generate an AUC curve of your model on the test set of your choice. \n",
"* [Upload the the model to the Hugging Face Hub](https://huggingface.co/docs/hub/adding-a-model), and add a link to your model below.\n",
"* *Answer the following question*: Look at some of the news articles that were classified incorrectly. Please explain what you might do to improve your model's performance on these news articles in the future (you do not need to impelement these suggestions)"
]
},
{
"cell_type": "code",
"source": [
"#installing libraries\n",
"!pip install opendatasets\n",
"!pip install pandas\n",
"!pip install -q kaggle\n",
"!pip install transformers\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "MvlmVtfz8LY5",
"outputId": "14ca9f13-661c-45b7-9ed0-62c1ce5aaef4"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
"Collecting opendatasets\n",
" Downloading opendatasets-0.1.22-py3-none-any.whl (15 kB)\n",
"Requirement already satisfied: kaggle in /usr/local/lib/python3.9/dist-packages (from opendatasets) (1.5.13)\n",
"Requirement already satisfied: tqdm in /usr/local/lib/python3.9/dist-packages (from opendatasets) (4.65.0)\n",
"Requirement already satisfied: click in /usr/local/lib/python3.9/dist-packages (from opendatasets) (8.1.3)\n",
"Requirement already satisfied: requests in /usr/local/lib/python3.9/dist-packages (from kaggle->opendatasets) (2.25.1)\n",
"Requirement already satisfied: certifi in /usr/local/lib/python3.9/dist-packages (from kaggle->opendatasets) (2022.12.7)\n",
"Requirement already satisfied: six>=1.10 in /usr/local/lib/python3.9/dist-packages (from kaggle->opendatasets) (1.15.0)\n",
"Requirement already satisfied: python-dateutil in /usr/local/lib/python3.9/dist-packages (from kaggle->opendatasets) (2.8.2)\n",
"Requirement already satisfied: python-slugify in /usr/local/lib/python3.9/dist-packages (from kaggle->opendatasets) (8.0.1)\n",
"Requirement already satisfied: urllib3 in /usr/local/lib/python3.9/dist-packages (from kaggle->opendatasets) (1.26.14)\n",
"Requirement already satisfied: text-unidecode>=1.3 in /usr/local/lib/python3.9/dist-packages (from python-slugify->kaggle->opendatasets) (1.3)\n",
"Requirement already satisfied: chardet<5,>=3.0.2 in /usr/local/lib/python3.9/dist-packages (from requests->kaggle->opendatasets) (4.0.0)\n",
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.9/dist-packages (from requests->kaggle->opendatasets) (2.10)\n",
"Installing collected packages: opendatasets\n",
"Successfully installed opendatasets-0.1.22\n",
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
"Requirement already satisfied: pandas in /usr/local/lib/python3.9/dist-packages (1.4.4)\n",
"Requirement already satisfied: numpy>=1.18.5 in /usr/local/lib/python3.9/dist-packages (from pandas) (1.22.4)\n",
"Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.9/dist-packages (from pandas) (2.8.2)\n",
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.9/dist-packages (from pandas) (2022.7.1)\n",
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.9/dist-packages (from python-dateutil>=2.8.1->pandas) (1.15.0)\n",
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
"Collecting transformers\n",
" Downloading transformers-4.26.1-py3-none-any.whl (6.3 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.3/6.3 MB\u001b[0m \u001b[31m33.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: filelock in /usr/local/lib/python3.9/dist-packages (from transformers) (3.9.0)\n",
"Collecting tokenizers!=0.11.3,<0.14,>=0.11.1\n",
" Downloading tokenizers-0.13.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.6 MB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m7.6/7.6 MB\u001b[0m \u001b[31m81.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.9/dist-packages (from transformers) (4.65.0)\n",
"Requirement already satisfied: requests in /usr/local/lib/python3.9/dist-packages (from transformers) (2.25.1)\n",
"Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.9/dist-packages (from transformers) (6.0)\n",
"Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.9/dist-packages (from transformers) (1.22.4)\n",
"Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.9/dist-packages (from transformers) (23.0)\n",
"Collecting huggingface-hub<1.0,>=0.11.0\n",
" Downloading huggingface_hub-0.13.2-py3-none-any.whl (199 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m199.2/199.2 KB\u001b[0m \u001b[31m21.8 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.9/dist-packages (from transformers) (2022.6.2)\n",
"Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.9/dist-packages (from huggingface-hub<1.0,>=0.11.0->transformers) (4.5.0)\n",
"Requirement already satisfied: chardet<5,>=3.0.2 in /usr/local/lib/python3.9/dist-packages (from requests->transformers) (4.0.0)\n",
"Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.9/dist-packages (from requests->transformers) (2.10)\n",
"Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/dist-packages (from requests->transformers) (1.26.14)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/dist-packages (from requests->transformers) (2022.12.7)\n",
"Installing collected packages: tokenizers, huggingface-hub, transformers\n",
"Successfully installed huggingface-hub-0.13.2 tokenizers-0.13.2 transformers-4.26.1\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"#Importing libraries\n",
"import opendatasets as od\n",
"from tensorflow.keras.models import Model, Sequential\n",
"from tensorflow.keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D,Input\n",
"from tensorflow.keras.callbacks import EarlyStopping\n",
"from tensorflow.python.ops.numpy_ops import np_utils\n",
"from transformers import BertModel, TFBertModel \n",
"import tensorflow as tf\n",
"from tensorflow.keras.optimizers import Adam\n",
"from transformers import BertTokenizer, BertForSequenceClassification, AdamW, TFBertModel\n",
"from sklearn.metrics import roc_auc_score\n",
"from torch.utils.data import DataLoader, RandomSampler, SequentialSampler\n",
"\n",
"from tensorflow.keras import regularizers\n",
"from sklearn.metrics import classification_report\n",
"from sklearn.metrics import confusion_matrix\n",
"\n",
"import pandas as pd\n",
"from matplotlib import rcParams\n",
"import seaborn as sns\n",
"import numpy as np\n",
"from PIL import Image\n",
"from sklearn.model_selection import train_test_split\n",
"from matplotlib import pyplot as plt\n",
"from transformers import AutoTokenizer"
],
"metadata": {
"id": "OaxYb0_T8Wn4"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#loading the datasets\n",
"fake_news=pd.read_csv(\"/Fake.csv\")\n",
"true_news=pd.read_csv(\"/content/True.csv\")"
],
"metadata": {
"id": "bJU3ck0SIQqx"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#Exploring the datasets\n",
"fake_news.head()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 206
},
"id": "fhucg9DT1VDX",
"outputId": "a9be23df-d443-4a0e-dd41-f5547f674810"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" title \\\n",
"0 Donald Trump Sends Out Embarrassing New Year’... \n",
"1 Drunk Bragging Trump Staffer Started Russian ... \n",
"2 Sheriff David Clarke Becomes An Internet Joke... \n",
"3 Trump Is So Obsessed He Even Has Obama’s Name... \n",
"4 Pope Francis Just Called Out Donald Trump Dur... \n",
"\n",
" text subject \\\n",
"0 Donald Trump just couldn t wish all Americans ... News \n",
"1 House Intelligence Committee Chairman Devin Nu... News \n",
"2 On Friday, it was revealed that former Milwauk... News \n",
"3 On Christmas day, Donald Trump announced that ... News \n",
"4 Pope Francis used his annual Christmas Day mes... News \n",
"\n",
" date \n",
"0 December 31, 2017 \n",
"1 December 31, 2017 \n",
"2 December 30, 2017 \n",
"3 December 29, 2017 \n",
"4 December 25, 2017 "
],
"text/html": [
"\n",
" <div id=\"df-6c8846a3-3511-4f4b-a1d8-31c3a3c77f2a\">\n",
" <div 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>title</th>\n",
" <th>text</th>\n",
" <th>subject</th>\n",
" <th>date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Donald Trump Sends Out Embarrassing New Year’...</td>\n",
" <td>Donald Trump just couldn t wish all Americans ...</td>\n",
" <td>News</td>\n",
" <td>December 31, 2017</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Drunk Bragging Trump Staffer Started Russian ...</td>\n",
" <td>House Intelligence Committee Chairman Devin Nu...</td>\n",
" <td>News</td>\n",
" <td>December 31, 2017</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Sheriff David Clarke Becomes An Internet Joke...</td>\n",
" <td>On Friday, it was revealed that former Milwauk...</td>\n",
" <td>News</td>\n",
" <td>December 30, 2017</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Trump Is So Obsessed He Even Has Obama’s Name...</td>\n",
" <td>On Christmas day, Donald Trump announced that ...</td>\n",
" <td>News</td>\n",
" <td>December 29, 2017</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Pope Francis Just Called Out Donald Trump Dur...</td>\n",
" <td>Pope Francis used his annual Christmas Day mes...</td>\n",
" <td>News</td>\n",
" <td>December 25, 2017</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-6c8846a3-3511-4f4b-a1d8-31c3a3c77f2a')\"\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 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\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",
" [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-6c8846a3-3511-4f4b-a1d8-31c3a3c77f2a 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-6c8846a3-3511-4f4b-a1d8-31c3a3c77f2a');\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",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 51
}
]
},
{
"cell_type": "code",
"source": [
"#Exploring the datasets\n",
"true_news.head()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 206
},
"id": "KcSJxAah1gv2",
"outputId": "0d13a388-7693-437e-933e-c153043b3037"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" title \\\n",
"0 As U.S. budget fight looms, Republicans flip t... \n",
"1 U.S. military to accept transgender recruits o... \n",
"2 Senior U.S. Republican senator: 'Let Mr. Muell... \n",
"3 FBI Russia probe helped by Australian diplomat... \n",
"4 Trump wants Postal Service to charge 'much mor... \n",
"\n",
" text subject \\\n",
"0 WASHINGTON (Reuters) - The head of a conservat... politicsNews \n",
"1 WASHINGTON (Reuters) - Transgender people will... politicsNews \n",
"2 WASHINGTON (Reuters) - The special counsel inv... politicsNews \n",
"3 WASHINGTON (Reuters) - Trump campaign adviser ... politicsNews \n",
"4 SEATTLE/WASHINGTON (Reuters) - President Donal... politicsNews \n",
"\n",
" date \n",
"0 December 31, 2017 \n",
"1 December 29, 2017 \n",
"2 December 31, 2017 \n",
"3 December 30, 2017 \n",
"4 December 29, 2017 "
],
"text/html": [
"\n",
" <div id=\"df-a4a31862-7f5f-4e5b-b2e0-ca6969b774c0\">\n",
" <div 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>title</th>\n",
" <th>text</th>\n",
" <th>subject</th>\n",
" <th>date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>As U.S. budget fight looms, Republicans flip t...</td>\n",
" <td>WASHINGTON (Reuters) - The head of a conservat...</td>\n",
" <td>politicsNews</td>\n",
" <td>December 31, 2017</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>U.S. military to accept transgender recruits o...</td>\n",
" <td>WASHINGTON (Reuters) - Transgender people will...</td>\n",
" <td>politicsNews</td>\n",
" <td>December 29, 2017</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>Senior U.S. Republican senator: 'Let Mr. Muell...</td>\n",
" <td>WASHINGTON (Reuters) - The special counsel inv...</td>\n",
" <td>politicsNews</td>\n",
" <td>December 31, 2017</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>FBI Russia probe helped by Australian diplomat...</td>\n",
" <td>WASHINGTON (Reuters) - Trump campaign adviser ...</td>\n",
" <td>politicsNews</td>\n",
" <td>December 30, 2017</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Trump wants Postal Service to charge 'much mor...</td>\n",
" <td>SEATTLE/WASHINGTON (Reuters) - President Donal...</td>\n",
" <td>politicsNews</td>\n",
" <td>December 29, 2017</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-a4a31862-7f5f-4e5b-b2e0-ca6969b774c0')\"\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 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\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",
" [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-a4a31862-7f5f-4e5b-b2e0-ca6969b774c0 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-a4a31862-7f5f-4e5b-b2e0-ca6969b774c0');\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",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 52
}
]
},
{
"cell_type": "code",
"source": [
"#Subject Vs frequency bar graph\n",
"true_news['subject'].value_counts().plot(kind='barh')\n",
"rcParams['figure.figsize'] = 7,10"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 594
},
"id": "0eLZrf9F1qi2",
"outputId": "b68de132-4fc1-4a2e-8317-a81d1cbf0b7c"
},
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"<Figure size 720x720 with 1 Axes>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAosAAAJBCAYAAAAumf/FAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm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YhEAgJJYBACgJBYBACiJRQAASmIRAICSWAQAoCQWAQAoiUUAAEpiEQCAklgEAKAkFgEAKIlFAABKYhEAgJJYBACgJBYBACiJRQAASmIRAICSWAQAoCQWAQAoiUUAAEpiEQCAklgEAKAkFgEAKIlFAABKYhEAgJJYBACgJBYBACiJRQAASmIRAICSWAQAoCQWAQAoiUUAAEpiEQCAklgEAKAkFgEAKIlFAABKYhEAgJJYBACgJBYBACiJRQAASmIRAIDSSzYW58+fn5tuuuk5j1133XVZuHDhizwRAMDLz0syFvv7+1s9AgAASUYO1QPdcsstWbduXRYsWJD//M//zHve857ceuutOeqoo3LxxRfniCOOyLhx4/LFL34x/f396ezszKWXXpqDDz44q1evzuWXX56JEyfmZz/7Wc4777ztHnvTpk256KKL8sADD+Q1r3lN9t9//7z61a9O8tRVxoceeiibNm3Khg0b8rrXvS7XXHNNXvGKV6Svry9f+tKXsmbNmvT19WX8+PG5+OKLkyTTpk3LypUr097enpNPPjlTpkwZnP1zn/tcbrnllnzjG9/IV7/61XR0dGRgYCBXX311Xv/61w/VygAAXvKG7Mri1KlTc9dddyVJ7rrrrhxzzDFZtWrV4M8TJkzIBRdckC984QtZvnx5ZsyYkXnz5g3e/+c//3lOP/30LFu2LCeccMJ2j71kyZKMHTs23/ve93LNNddkzZo12x3v7u7OokWL8t3vfjfbtm3L8uXLkyRf+cpXsueee+Yf//Ef8+1vfzv77rtvbrzxxowdOzaHHnpo7r333jz22GMZM2ZM1q5dOzhrV1dXkuTKK6/M1772tSxbtizf/OY3c8ABBwzVugAAdglDdmXx4IMPTm9vbx599NHcddddOf/883PDDTdk5syZ2bp1a3p6ejJhwoQcdthhSZJ3v/vdueSSS7J58+bB+x9zzDHP+dirV6/OZz7zmSRJZ2dn3vWud213/C1veUv22muvJMlRRx2VX/7yl0mSO++8M5s3b873v//9JElfX18mTJiQ5Km4XblyZQ444IBMmzYtq1evzqOPPpqVK1fmYx/7WJKkq6sr8+fPzwknnJDjjz8+r33ta4dqXQDAE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gJJYBACgJBYBACiJRQAASmIRAICSWAQAoCQWAQAoiUUAAEpiEQCAklgEAKAkFgEAKIlFAABKYhEAgJJYBACgJBYBACiJRQAASmIRAICSWAQAoCQWAQAoiUUAAEpiEQCAklgEAKAkFgEAKIlFAABKYhEAgJJYBACgJBYBACiJRQAASmIRAICSWAQAoCQWAQAoiUUAAEpiEQCAklgEAKAkFgEAKIlFAABKYhEAgJJYBACgJBYBACgNSyyuXr06f/7nf54k+c1vfpMzzjhj8Nh1112Xvr6+wZ+vueaafOc739mp57nuuusyfvz43HPPPdvdtnDhwp2cHACA/2nYryzut99++frXvz748+LFi7N169bBn88999ycfPLJO/34Bx54YBYtWvQnzQgAwHN7wVgcP358rr322syePTsnnnhivv/97w8e+9d//dfMmTMnM2fOzFlnnZWHH374Wff/1a9+lSlTpiRJLrnkkiTJ+973vsyePTt/+MMfMn/+/Nx0001Jkr6+vixcuDAzZszIrFmz8ld/9VdJkrvvvjunnnpqZs+enVNOOSV33HHH4ONPnz49GzduzL/927895/w33nhjTjvttJx66qn5y7/8y/z2t79Nkrz1rW9NT09PkuSjH/1o5s6dmyTp6enJ2972tiTJD3/4w8ycOTOzZ8/OjBkzsnr16hdaFwDAbmXkjvyhESNGZNmyZXnwwQfz/ve/P8cee2yS5IILLshNN92Uww47LLfeemvmzZuXW2+9tXycBQsW5Oabb84tt9ySsWPHPuv4jTfemA0bNuS2225LR0dHHn/88STJ0qVLc/bZZ2fGjBlpmiabNm0avE9bW1s+9alP5Utf+lLe8pa3bPd4y5Yty4YNG/IP//APGTFiRG6++eZ8/vOfz6JFizJlypSsWrUq06dPz69+9au0tbVl69atueuuuwbj9tprr82ll16aY445Jv39/fnjH/+4I+sCABgSa9eubfUIOxaL73nPe5Ikhx56aI488sj89Kc/TVtbWyZMmJDDDjssSfLud787l1xySTZv3rzTw6xYsSLz589PR0dHkqSzszNJMmXKlFx//fX55S9/meOOOy5HH330dvc7/vjj8+Uvfznf/e53t7v9zjvvTHd3d0499dQkSX9/f175ylcmSaZOnZqVK1dmv/32y6RJk9I0Te65556sXLkyXV1dSZKurq78zd/8TaZPn563ve1tOfzww3f6dwMA+L+aPHnysD9Hb29vuru7y+M7FIut9qEPfSjTpk3LypUrc9lll+W4447L+eefv92f+fSnP52LLrooJ5100uBtTdPkYx/7WE477bRnPWZXV1eWLFmS/fffP11dXWmaJqtWrcqqVatyzjnnJEkuvPDCrFu3LqtWrcq5556bv/iLv8jpp58+vL8sAMBLyA59weWb3/xmkuQXv/hFfvazn2XSpEmZNGlS7r///qxfvz5Jcvvtt+fII48cvHJXGTt2bHn18YQTTsjXvva1wW9LP/029EMPPZTXve51ed/73pczzzwz995777Pue+yxx+aQQw7J8uXLB2+bNm1abr755vz+979P8tRnIu+///4kT30xpr29PbfffnumTp2aqVOn5rbbbsvIkSNzwAEHJEkefPDBjB8/PmeddVZmzZr1nM8LALA726Eri/39/ZkzZ07++Mc/5tJLL82rXvWqJMmVV16ZefPmZdu2bens7MxVV131go/14Q9/OGeeeWbGjBmz3bekk2Tu3LlZtGhR5syZk1GjRuXggw/Otddem69//etZvXp1Ro0alY6OjnzmM595zsc+//zzB99yTpI5c+Zk48aN+eAHP5jkqSuN73//+zNhwoQkT70VvXbt2uy7775JkjFjxgx+HjNJFi1alIcffjjt7e3Za6+9csUVV+zIugAAdhttTdM0z/cHxo8fn7vvvvs5v5DCc3v6vf+rlz2SjVv6Wz0OALALWr5o9ovyPE93y8SJEzN69OhnHfcvuAAAUHrBt6HXrVv3YswBAMBLkCuLAACUxCIAACWxCABASSwCAFASiwAAlMQiAAAlsQgAQEksAgBQEosAAJTEIgAAJbEIAEBJLAIAUBKLAACUxCIAACWxCABASSwCAFASiwAAlMQiAAAlsQgAQEksAgBQEosAAJTEIgAAJbEIAEBJLAIAUBKLAACUxCIAACWxCABASSwCAFASiwAAlMQiAAAlsQgAQEksAgBQEosAAJTEIgAAJbEIAEBJLAIAUBKLAACUxCIAACWxCABASSwCAFASiwAAlMQiAAAlsQgAQEksAgB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6ZpdvoYz9bd3d2cffbZzQknnNCsW7fO3l8kl112WXPFFVc0AwMDTdM0zW9/+9umaZ7/3LKzx3jKwMBAc+yxxzbr1q1rmqZp7rvvvmbSpElNf3+/vQ+xNWvWNL/+9a8HzytPG449ew2GjlgcQr/73e+ayZMnN9u2bWuapmm2bdvWTJ48uenp6WnxZLuH733ve81ZZ53V3HPPPc0pp5wyeHtPT08zadKkpmmanT7G9np7e5vTTz+92bBhw+BJ3d6H3+bNm5vJkyc3mzdv3u725zu37OwxnjEwMNC86U1van784x83TdM0//Ef/9FMnz7d3ofR/4zF4diz12BojWz1lc3dySOPPJL99tsv7e3tSZL29vbsu+++eeSRR9LZ2dni6XZtAwMD+fu///tMmzYtjzzySA444IDBY52dnRkYGMjGjRt3+tjee+/9Yv46L3nXXHNNZs2alYMOOmjwNnsffhs2bMjee++dxYsXZ/Xq1Rk7dmzOPffcjBkzpjy3NE2zU8eck57R1taWq6++Oh//+Mezxx57ZMuWLbnxxhuf95xu70NnOPbsNRhaPrPILuGyyy7LHnvskQ9+8IOtHmW395Of/CTd3d35wAc+0OpRXnb6+/uzYcOGHHnkkbntttsyb968fOITn8h///d/t3q03dq2bdvy5S9/OX/7t3+bFStW5Prrr895551n7/D/ubI4hMaNG5ff/OY36e/vT3t7e/r7+/PYY49l3LhxrR5tl7Zw4cI8/PDDueGGGzJixIiMGzcuv/71rwePP/744xkxYkT23nvvnT7GM9asWZP169fnHe94R5Lk0Ucfzdlnn50zzjjD3ofZuHHjMnLkyMyYMSNJcvTRR2efffbJmDFjynNL0zQ7dYxn3HfffXnssccyefLkJMnkyZPzile8IqNHj7b3F8Hz/b9zZ/fsNRhariwOoVe96lU54ogjcscddyRJ7rjjjhxxxBEuef8JvvjFL6a7uztLlixJR0dHkmTixIl58skn8+Mf/zhJcsstt+Skk076k47xjLlz5+bf//3fc+edd+bOO+/M/vvvn7/7u7/LRz7yEXsfZp2dnZkyZUp+9KMfJXnq25w9PT055JBDynPL8513nJN2zP77759HH300Dz74YJJk/fr16enpycEHH2zvL4Kd3aXX4MXT1jRN0+ohdifr16/P/Pnz84c//CF77bVXFi5cmEMPPbTVY+2S/uu//iszZszIIYcckjFjxiRJDjrooCxZsiR33313FixYkN7e3hx44IG56qqr8upXvzpJdvoYz23atGm54YYbcvjhh9v7i2DDhg258MILs3HjxowcOTLnnXde3v72tz/vuWVnj/GMb3/721m6dGna2tqSJJ/85Cfzzne+096H2OWXX54f/OAH+d3vfpd99tkne++9d/7pn/5pWPbsNRg6YhEAgJK3oQEAKIlFAABKYhEAgJJYBACgJBYBACiJRQAASmIRAICSWAQAoPT/AFGw15VeE1eUAAAAAElFTkSuQmCC\n"
},
"metadata": {}
}
]
},
{
"cell_type": "code",
"source": [
"#Subject Vs frequency bar graph\n",
"fake_news['subject'].value_counts().plot(kind='barh')\n",
"rcParams['figure.figsize'] = 10,7"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 594
},
"id": "POwJJJTV14r0",
"outputId": "c8818dd5-cf98-4fa1-d37c-9c7b40dcdb6a"
},
"execution_count": null,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"<Figure size 504x720 with 1 Axes>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAgQAAAJBCAYAAAA5l61JAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAAsTAAALEwEAmpwYAAAnhUlEQVR4nO3de5zWdZ3//+dwGgokxTzgWTNBRCEnTpqZlCLCAKIIbYqK5K5YiOXNFN2vGtpmSnmGpHYrlTADnEDdDjcPaRzKYTNYFQ1QoZU0EJEhmGG4fn/4YzZWBMQZL5m53//J+Xyu6/q8Pm+7vB7z+VxiSaFQKAQAaNKaFXsAAKD4BAEAIAgAAEEAAEQQAABJWhR7ABrGpk2bUlVVlZYtW6akpKTY4wDwIVAoFFJTU5M2bdqkWbMtrwkIgkaqqqoqL7zwQrHHAOBD6Igjjshuu+22xTZB0Ei1bNkyydt/01u1alXkaXZtCxcuTJcuXYo9xi7POtYfa1k/muI6VldX54UXXqj7jPhHgqCR2nyboFWrViktLS3yNLs+a1g/rGP9sZb1o6mu49ZuJftSIQAgCAAAQQAARBAAABEEAEAEAQAQQQAARBAAABEEAEAEAQAQQQAARBAAABEEAEAEAQAQQQAARBAAABEEAEAEAQAQQQAARBDQgKpraos9AgA7qEWxB6Bhjbrh11ldVZwP5pkTBhXluAC8d64QAACCAAAQBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAGQXDoI+ffrkM5/5TGpra+u2TZ8+PR07dsy9996bn/70p/nRj3601edOnz49Y8aM2e6+bT3ug3T77benurq62GMA0IjtskGQJHvvvXeeeuqpup9nzJiRo446KknyxS9+Meedd16RJqtfd9xxR2pqaoo9BgCNWItiD/B+nH766Zk+fXpOPPHELFu2LOvWrcsRRxyR5O3fqtetW5dvfOMbqa6uzvXXX5+5c+dmjz32yJFHHln3Gtva93/NmDEjU6ZMSW1tbdq2bZtrr702hx122FYfe/fdd+dXv/pVamtrs88++2T8+PHZa6+9MmfOnNxyyy3ZsGFDamtr8y//8i/p379/krc/+GfNmpXS0tKUlJTkJz/5Sb73ve8lSYYPH55mzZrlnnvuSbt27eprCQEgyS4eBD169MiUKVPy5ptvZsaMGRk8eHD++7//+x2Pu//++7N8+fI89NBD2bhxY770pS/lgAMO2O6+f/T000/nkUceyX333ZdWrVrliSeeyLhx4zJ16tR3PLaioiLLli3Lz372szRr1ixTpkzJt7/97UyYMCGdO3fOlClT0rx58/ztb3/LkCFD8pnPfCaFQiE/+tGP8tRTT6V169ZZu3ZtWrdunWuuuSZTpkzJ1KlT06ZNm/pfRADILh4EJSUl6devXx566KE89NBDmTp16laDYN68eRk8eHBatmyZli1bZuDAgZk/f/529/2jRx99NM8//3yGDh2aJCkUClmzZs1W53r00UezcOHCnH766UlSd0UhSVatWpVx48bl5ZdfTvPmzfPmm29m6dKlOfroo3PQQQfl8ssvz2c+85l87nOfq3vOrqyysrLYI9SLxnIexWYd64+1rB/W8X/t0kGQvH3bYOjQoenevXv22GOPBjtOoVDIGWeckUsuueQd+y6++OIsX748SXLfffelUCjkoosuyplnnvmOx1577bXp06dP7rjjjpSUlKRv377ZsGFDmjdvnp/97GeZP39+5s6dmyFDhuQHP/hBOnXq1GDn9EEoKysr9gjvW2VlZaM4j2KzjvXHWtaPpriOGzZsyMKFC7e6b5f+UmGSHHjggbn00kszevTod31Mr169UlFRkY0bN2b9+vWZNWvWDu37R3369ElFRUVWrFiR5O3f+jcv6p133pmKiopUVFSkbdu26dOnT92tjOTt7yk8//zzSZK33nor+++/f0pKSvK73/0uL7/8cpJk7dq1WbVqVXr06JExY8bkiCOOyIsvvpgkadOmTdauXfs+VwoA3t0uf4UgSYYNG7bN/WeddVYWLVqU0047LXvssUeOPvrorFy5crv7/lH37t0zduzYXHTRRamtrU1NTU1OPfXUdOnS5R2PHTx4cFavXp2zzz47ydtXF774xS+mU6dO+frXv57rrrsut99+e44++uh07NgxydtB8NWvfjXr169PoVBI586dc8oppyRJRo4cmREjRqR169a+VAhAgygpFAqFYg9B/dt8WeiWilezuqp2+09oADMnDCrKcetbU7ys2BCsY/2xlvWjKa7j5s+GLl26pLS0dIt9u/wtAwDg/RMEAIAgAAAEAQAQQQAARBAAABEEAEAEAQAQQQAARBAAABEEAEAEAQAQQQAARBAAABEEAEAEAQAQQQAARBAAAElaFHsAGtYPrjo5paWlRTl2dU1tWrVsXpRjA/DeuEJAgxEDALsOQQAACAIAQBAAABEEAEAEAQAQQQAARBAAABEEAEAEAQAQQQAARBAAABEEAEAEAQAQQQAARBAAABEEAEAEAQAQQQAARBAAABEEAEAEAQAQQQAARBAAABEEAEAEAQAQQQAARBAAABEEAEAEAQAQQQAARBAAABEEAEAEAQAQQQAARBAAABEEAEAEAQAQQQAARBAAABEEAEAEAQAQQQAARBAAABEENKDqmtpijwDADmpR7AFoWKNu+HVWVxXng3nmhEFFOS4A750rBACAIAAABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABAmmAQdOzYMVVVVVts69mzZ5YvX54kmTt3boYOHZpBgwalX79+GTFiRDZt2vSurzdv3rx07Ngxd9999xbbhgwZ0jAnAAANoEWxB/gw2bhxY8aMGZOf/OQn6dSpU5Lk2WefTUlJyTaft9dee+XHP/5xhg8fnnbt2n0QowJAvWpyVwi2paqqKuvWrcvHP/7xum2dO3febhDsvffeOfXUUzN58uSt7n/iiScyfPjwDBkyJMOGDcsf//jHJMnXvva1PPLII0mSyZMnp6ysLLW1tUmS0047LUuXLs2SJUsybNiwDBw4MAMGDMgPf/jDejhTANiSKwT/4GMf+1jOOuusnHLKKenRo0eOPfbYlJeXp0OHDtt97kUXXZTy8vKcc845W2x/5ZVXctddd+WHP/xh2rZtmxdffDFf/vKX8/jjj6d3796ZM2dO+vXrl7lz5+aTn/xkFixYkP322y/r1q3LoYcemuuvvz59+vTJP//zPydJ3nzzzQY594ZSWVlZ7BHqRWM5j2KzjvXHWtYP6/i/BMH/b/NVgP/3//5fzj///MydOze//e1v8/3vfz/Tpk3LIYccss3nf/zjH89ZZ52Vu+66K/369avb/uSTT+aVV17Jl770pbptGzduzN/+9rf06tUrd999d6qrq7NixYpccMEFmT17dvbbb7/07NkzSdK9e/fcdNNN+fvf/56ePXumV69e9X/yDaisrKzYI7xvlZWVjeI8is061h9rWT+a4jpu2LAhCxcu3Oq+JhcE7du3z+rVq9OmTZskb384r127Nu3bt697zIEHHpgDDzwwQ4cOzahRo/LYY4/l/PPP3+5rjxo1Kv369ctRRx21xfYTTjgh3/nOd7b6nE2bNuWhhx5Kt27d0rt371x++eXZf//907t37yRJ3759061bt/zud7/L5MmTM23atNx88807e/oAsFVN7jsExx13XO6///66n++///507do1H/nIR1JVVZWnnnoqhUIhSbJmzZosX748BxxwwA699m677Zbzzz8/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FmzJu3atcvhhx+eioqK3Hvvve/6gv9o8ODBOeuss/K1r30ts2bNyv3335/k7Q/FM844I5dccslWn9emTZt3bNv84b/5+wQbN26s27b5f5s1a5ZWrVrVPadZs2bZuHHjDh1z82tsPkZtbe12z+//uuSSSzJ8+PBceOGFddu2ddxjjz02zz77bB5//PH07t07PXr0yLRp07J8+fK6LyWed9556dOnT2bPnp3x48fn+OOPz6WXXvqeZwOAbdnmdwgOOeSQfP7zn8/VV1+9xaXqdevW1f117969M23atBQKhaxduzYPP/xwjjvuuCTJfvvtl8MPPzzXX399Dj/88Oy///5Jkj59+qSioiIrVqxI8vYXB3ckMN6PnT1m27Ztd/gy/YEHHpi+ffvmxz/+8Q4dt1WrVuncuXMmT56c4447Ll27ds38+fOzaNGiuisBS5cuzUEHHZThw4dnxIgRWbBgwXs6bwDYEdu9ZfBv//Zvueuuu3LmmWemRYsWadeuXfbee++634JHjx6d8ePHp7y8PEkycODAfPazn617/umnn57LL7883/nOd+q2de/ePWPHjs1FF12U2tra1NTU5NRTT02XLl3q+/ze9zF79+6df//3f8/AgQPTo0ePXH311dt8/OjRozNjxowdPm7v3r2zYMGCHH300WnevHkOOuigHHDAAXVXOu65557MmzcvLVu2TKtWrbZ7fADYGSWFQqFQ7CGof5vvE91S8WpWV7332x+NxcwJg973azTF+4wNwTrWH2tZP5riOm7+bOjSpcsWt8oTf1IhABBBAABEEAAAEQQAQAQBABBBAABEEAAAEQQAQAQBABBBAABEEAAAEQQAQAQBABBBAABEEAAAEQQAQAQBAJCkRbEHoGH94KqTU1paWuwxiqa6pjatWjYv9hgAH3quENCoiQGAHSMIAABBAAAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggC2q6ysrNgjNAr1uY7VNbX19lrA21oUewAa1qgbfp3VVf7hSeMyc8KgYo8AjY4rBACAIAAABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAABpgkHQsWPHVFVVbfdxv/nNb9KvX78MHjw4S5Ysyf333/8BTAcAxdHkgmBHTZ06NWPGjMmDDz6Y119/XRAA0Ki1KPYAxbRkyZJ861vfyhtvvJGampqce+65OeOMM/Ktb30rlZWVWbp0aaZMmZJVq1Zl+fLlGTRoUA4++ODcdttt73itPn36ZNCgQZk9e3Zef/31jBw5MmefffY2jzN16tQsWrQo11xzTf70pz9l6NCheeCBB3LMMcfk2muvzZFHHpmBAwfmG9/4Rv785z+nRYsWOfTQQ3Prrbd+0EsFQCPXZINg48aNueyyy3LTTTflE5/4RNauXZszzjgj3bp1y7hx4/Lcc89l5MiROemkkzJv3rzceOONmT59+jZfc/369bn//vuzfPnylJeX5/TTT09paem7Hqd379750Y9+lCSZM2dOPvWpT2Xu3Lk55phjMmfOnIwcOTJPPfVUqqqq8vDDDydJ3nzzzYZeGgCaoCYbBC+99FIWL16cr33ta3XbampqsmTJknziE5/Yqdc87bTTkiQHHHBA2rVrlxUrVqRQKLzrcU4++eRs2LAhK1asyJw5c3LppZdm0qRJKS8vT01NTQ466KCUlJRk8eLFue6669KjR4987nOfe1/nDY1FZWVlsUcoqqZ+/vXFOv6vJhsEhUIhe+yxRyoqKt7zc5988sncfPPNSZLy8vKMGjUqSVJaWlr3mObNm6e2tjYlJSXbPE6vXr3y2GOPZeXKlenZs2fGjx+fxx9/PD179kySHHjggZk1a1bmzp2b3/72t/ne976XmTNnbnEsaIrKysqKPULRVFZWNunzry9NcR03bNiQhQsXbnVfk/1S4aGHHprWrVvnwQcfrNu2ePHirF279h2Pbdu27RbbTzjhhFRUVKSioqIuBnb2OL169crkyZPzqU99Kkly7LHHZvLkyendu3eSZMWKFWnevHm+8IUv5Morr8yqVauyevXqnTxrANi6JhsELVq0yKRJk/Lwww+nvLw8/fv3z3XXXZfq6up3PLZjx4459NBDM2DAgIwZM6Zej9OrV6/85S9/qQuAzT/36tUrSbJo0aIMGzYsAwcOzNChQ3PhhRdmn332eZ9nDwBbKikUCoViD0H923xZ6JaKV7O6qrbY40C9mjlhULFHKKqmeKm7ITTFddz82dClS5d33HpuslcIAID/JQgAAEEAAAgCACCCAACIIAAAIggAgAgCACCCAACIIAAAIggAgAgCACCCAACIIAAAIggAgAgCACCCAABI0qLYA9CwfnDVySktLS32GFCvqmtq06pl82KPAY2KKwSwHZWVlcUeoVGoz3UUA1D/BAEAIAgAAEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBLBdZWVlxR6hUbCO9efDspbVNbXFHoF61KLYA9CwRt3w66yu8qYF6t/MCYOKPQL1yBUCAEAQAACCAACIIAAAIggAgAgCACCCAACIIAAAIggAgAgCACCCAACIIAAAIggAgAgCACCCAACIIAAAIggAgAiCejdv3rwMGTIkSfLXv/4155xzTt2+22+/PdXV1XU/33rrrXn44Yc/8BkB4P8SBA1on332yT333FP38x133JGampq6ny+55JKcdtppxRgNALYgCLahY8eOue222zJo0KD07ds3v/zlL+v2/fa3v83gwYNTXl6ec889Ny+//PI7nr98+fL07NkzSXLdddclSYYPH55BgwZlzZo1ueKKK3LvvfcmSaqrq3PjjTdmwIABGThwYC6++OIkyfz583P66adn0KBB6d+/f2bNmtXQpw1AE9Si2AN82DVr1iwVFRVZsmRJvvjFL+bTn/50kuTyyy/Pvffem8MPPzwPPPBALrvssjzwwAPv+jrXXHNNpkyZkqlTp6ZNmzbv2H/33Xdn2bJlmT59elq1apVVq1YlSSZPnpwLLrggAwYMSKFQyFtvvdUwJwqwEyorK4s9wvuyq89fnwTBdgwdOjRJcthhh6Vz58754x//mJKSknTq1CmHH354kuSMM87Iddddl7Vr1+70cR577LFcccUVadWqVZKkffv2SZKePXtm4sSJeeWVV3L88cena9eu7/OMAOpPWVlZsUfYaZWVlbv0/Dtjw4YNWbhw4Vb3uWXwIXfeeedl4sSJad++fcaPH5/vfe97xR4JgEZIEGzHtGnTkiQvvfRSnn322XTr1i3dunXL888/n8WLFydJZsyYkc6dO6dt27bbfK02bdq861WEk046KT/+8Y/r/i2EzbcMli5dmoMOOijDhw/PiBEjsmDBgvo6NQCo45bBdtTW1mbw4MH5+9//nm9+85vZc889kyTf+c53ctlll2Xjxo1p3759brrppu2+1siRIzNixIi0bt16i3/7IEkuvPDCTJgwIYMHD07Lli1z8MEH57bbbss999yTefPmpWXLlmnVqlWuvvrqBjlPAJq2kkKhUCj2EB9WHTt2zPz587f6JcAPu833iW6peDWrq2qLPQ7QCM2cMKjYI7wvTfk7BF26dElpaekW+9wyAADcMtiWRYsWFXsEAPhAuEIAAAgCAEAQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAAARBABABAEAEEEAAEQQAABJWhR7ABrWD646OaWlpcUeA2iEqmtq06pl82KPQT1xhQC2o7KystgjNArWsf58WNZSDDQuggAAEAQAgCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIAIAIAgAgggAAiCAAACIIYLvKysqKPUKjYB3rj7WsH7vSOlbX1Db4MVo0+BEoqlE3/Dqrqxr+/0gANJyZEwY1+DFcIQAABAEAIAgAgAgCACCCAACIIAAAIggAgAgCACCCAACIIAAAIggAgAgCACCCAACIIAAAIggAgAgCACCCAACIIAAAIgjqRZ8+fTJgwIBs2rRpi20vvPBCEacCgB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AgAgggAAiCAAAJK0KPYANIxCoZAkqa6uLvIkjcOGDRuKPUKjYB3rj7WsH01tHTd/Jmz+jPhHJYWtbWWX99Zbb+WFF14o9hgAfAgdccQR2W233bbYJggaqU2bNqWqqiotW7ZMSUlJsccB4EOgUCikpqYmbdq0SbNmW35rQBAAAL5UCAAIAgAgggAAiCAAACIIAIAIAgAgggAAiCBolJYuXZphw4alb9++GTZsWF566aVij/Sh8cYbb+TLX/5y+vbtm/Ly8nzlK1/JqlWrkiR//OMfM3DgwPTt2zcjR47MypUr6563s/uagjvuuCMdO3as+5MxreN7s2HDhlxzzTU55ZRTUl5enn/9139Nsu338c7ua+wee+yxDB48OIMGDcrAgQPzq1/9Kom13GEFGp1zzjmn8OCDDxYKhULhwQcfLJxzzjlFnujD44033ijMnTu37udvf/vbhSuvvLJQW1tb+MIXvlD4wx/+UCgUCoU777yzcMUVVxQKhcJO72sKFi5cWLjgggsKJ510UmHRokXWcSeMHz++cMMNNxQ2bdpUKBQKhddff71QKGz7fbyz+xqzTZs2FT796U8XFi1aVCgUCoXnnnuu0K1bt0Jtba213EGCoJH529/+VigrKyts3LixUCgUChs3biyUlZUVVq5cWeTJPpz+8z//s3DuuecWnnnmmUL//v3rtq9cubLQrVu3QqFQ2Ol9jd2GDRsKZ511VmHZsmV1QWAd35u1a9cWysrKCmvXrt1i+7bexzu7r7HbtGlToUePHoWnn366UCgUCr///e8Lp5xyirV8D/zXDhuZV199Nfvss0+aN2+eJGnevHn23nvvvPrqq2nfvn2Rp/tw2bRpU37605+mT58+efXVV7PffvvV7Wvfvn02bdqU1atX7/S+3Xff/YM8nQ/crbfemoEDB+aAAw6o22Yd35tly5Zl9913zx133JF58+alTZs2ueSSS9K6det3fR8XCoWd2tfY3/8lJSW55ZZbMnr06Hz0ox9NVVVV7r777m3+M9Fabsl3CGiyxo8fn49+9KM5++yziz3KLue//uu/snDhwvzTP/1TsUfZpdXW1mbZsmXp3Llzpk+fnssuuyxf/epXs27dumKPtsvZuHFjvv/97+euu+7KY489lokTJ2bs2LHW8j1whaCR6dChQ/7617+mtrY2zZs3T21tbV577bV06NCh2KN9qNx44415+eWXM2nSpDRr1iwdOnTI//zP/9TtX7VqVZo1a5bdd999p/c1Zn/4wx+yePHifP7zn0+SrFixIhdccEHOOecc6/gedOjQIS1atMiAAQOSJF27ds0ee+yR1q1bv+v7uFAo7NS+xu65557La6+9lrKysiRJWVlZPvKRj6S0tNRa7iBXCBqZPffcM0ceeWRmzZqVJJk1a1aOPPLIRnuJa2d897vfzcKFC3PnnXemVatWSZIuXbpk/fr1efrpp5MkU6dOzamnnvq+9jVmF154YZ566qk8+uijefTRR7Pvvvvmhz/8YUaNGmUd34P27dunZ8+e+d3vfpfk7W+1r1y5Mocccsi7vo+39R5vyu//fffdNytWrMiSJUuSJIsXL87KlStz8MEHW8sd5D9/3AgtXrw4V1xxRdasWZN27drlxhtvzGGHHVbssT4UXnzxxQwYMCCHHHJIWrdunSQ54IADcuedd2b+/Pm55pprsmHDhuy///656aab8vGPfzxJdnpfU9GnT59MmjQpRxxxhHV8j5YtW5Zx48Zl9erVadGiRcaOHZsTTzxxm+/jnd3X2P3iF7/I5MmTU1JSkiQZM2ZMvvCFL1jLHSQIAAC3DAAAQQAARBAAABEEAEAEAQAQQQAARBAAABEEAECS/w+U1D3TLQV3rwAAAABJRU5ErkJggg==\n"
},
"metadata": {}
}
]
},
{
"cell_type": "code",
"source": [
"# Assigning label to the datasets\n",
"fake_news[\"label\"]=\"fake\"\n",
"true_news[\"label\"]=\"true\"\n",
"\n",
"# Merging the real and true news datasets to create the final one\n",
"final_news_dataset= pd.concat([fake_news,true_news])\n",
"\n",
"#Shuffling\n",
"final_news_dataset = final_news_dataset.sample(frac=1).reset_index(drop=True)\n",
"\n",
"# Exploring the final dataset\n",
"final_news_dataset.head(10)\n",
"\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 363
},
"id": "noYYMxvF2Ag8",
"outputId": "ce5142c8-631f-4420-e201-63d769ec11d6"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" title \\\n",
"0 U.S. responds in court fight over illegal Indo... \n",
"1 Numbskull Republican Ignores History, Says Re... \n",
"2 US-UK DIRTY WAR: ‘Latin American-style’ Death ... \n",
"3 SUPREME COURT JUSTICE Goes All Creepy Predicti... \n",
"4 Hillary Clinton: ‘Israel First’ (and no peace ... \n",
"5 Boiler Room EP #119 – Zombie Disneyland & The ... \n",
"6 EU Parliament calls on Myanmar to free Reuters... \n",
"7 Donald Trump Releases Statement On Cruz Sex S... \n",
"8 McConnell Just ADMITTED The NRA Must Approve ... \n",
"9 Putin says question of who hacked Democratic p... \n",
"\n",
" text subject \\\n",
"0 BOSTON (Reuters) - U.S. immigration officials ... politicsNews \n",
"1 Republican Rep. Ted Poe (R-Texas) spoke with F... News \n",
"2 Patrick Henningsen 21st Century WireThis week... Middle-east \n",
"3 What the heck is wrong with these loony libera... politics \n",
"4 Robert Fantina CounterpunchAlthough the United... US_News \n",
"5 Tune in to the Alternate Current Radio Network... US_News \n",
"6 BRUSSELS (Reuters) - The president of the Euro... worldnews \n",
"7 With the sex scandal allegations piling up aga... News \n",
"8 We could already make the assumption that Sena... News \n",
"9 MOSCOW (Reuters) - Russian President Vladimir ... politicsNews \n",
"\n",
" date label \n",
"0 December 21, 2017 true \n",
"1 January 20, 2016 fake \n",
"2 July 14, 2016 fake \n",
"3 Jul 10, 2016 fake \n",
"4 January 18, 2016 fake \n",
"5 July 29, 2017 fake \n",
"6 December 14, 2017 true \n",
"7 March 25, 2016 fake \n",
"8 July 6, 2016 fake \n",
"9 December 23, 2016 true "
],
"text/html": [
"\n",
" <div id=\"df-ebc1c057-44ea-4d5f-a5a8-aaecd2c4d9a0\">\n",
" <div 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>title</th>\n",
" <th>text</th>\n",
" <th>subject</th>\n",
" <th>date</th>\n",
" <th>label</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>U.S. responds in court fight over illegal Indo...</td>\n",
" <td>BOSTON (Reuters) - U.S. immigration officials ...</td>\n",
" <td>politicsNews</td>\n",
" <td>December 21, 2017</td>\n",
" <td>true</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Numbskull Republican Ignores History, Says Re...</td>\n",
" <td>Republican Rep. Ted Poe (R-Texas) spoke with F...</td>\n",
" <td>News</td>\n",
" <td>January 20, 2016</td>\n",
" <td>fake</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>US-UK DIRTY WAR: ‘Latin American-style’ Death ...</td>\n",
" <td>Patrick Henningsen 21st Century WireThis week...</td>\n",
" <td>Middle-east</td>\n",
" <td>July 14, 2016</td>\n",
" <td>fake</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>SUPREME COURT JUSTICE Goes All Creepy Predicti...</td>\n",
" <td>What the heck is wrong with these loony libera...</td>\n",
" <td>politics</td>\n",
" <td>Jul 10, 2016</td>\n",
" <td>fake</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Hillary Clinton: ‘Israel First’ (and no peace ...</td>\n",
" <td>Robert Fantina CounterpunchAlthough the United...</td>\n",
" <td>US_News</td>\n",
" <td>January 18, 2016</td>\n",
" <td>fake</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>Boiler Room EP #119 – Zombie Disneyland & The ...</td>\n",
" <td>Tune in to the Alternate Current Radio Network...</td>\n",
" <td>US_News</td>\n",
" <td>July 29, 2017</td>\n",
" <td>fake</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>EU Parliament calls on Myanmar to free Reuters...</td>\n",
" <td>BRUSSELS (Reuters) - The president of the Euro...</td>\n",
" <td>worldnews</td>\n",
" <td>December 14, 2017</td>\n",
" <td>true</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>Donald Trump Releases Statement On Cruz Sex S...</td>\n",
" <td>With the sex scandal allegations piling up aga...</td>\n",
" <td>News</td>\n",
" <td>March 25, 2016</td>\n",
" <td>fake</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>McConnell Just ADMITTED The NRA Must Approve ...</td>\n",
" <td>We could already make the assumption that Sena...</td>\n",
" <td>News</td>\n",
" <td>July 6, 2016</td>\n",
" <td>fake</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>Putin says question of who hacked Democratic p...</td>\n",
" <td>MOSCOW (Reuters) - Russian President Vladimir ...</td>\n",
" <td>politicsNews</td>\n",
" <td>December 23, 2016</td>\n",
" <td>true</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-ebc1c057-44ea-4d5f-a5a8-aaecd2c4d9a0')\"\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 0 24 24\"\n",
" width=\"24px\">\n",
" <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
" <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n",
" </svg>\n",
" </button>\n",
" \n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" flex-wrap:wrap;\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",
" [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-ebc1c057-44ea-4d5f-a5a8-aaecd2c4d9a0 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-ebc1c057-44ea-4d5f-a5a8-aaecd2c4d9a0');\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",
" </div>\n",
" "
]
},
"metadata": {},
"execution_count": 55
}
]
},
{
"cell_type": "code",
"source": [
"final_news_dataset.isnull().sum()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "p6QU5NZQ4Mbz",
"outputId": "579159ab-f47d-4cb9-fa66-d728a4a42107"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"title 0\n",
"text 0\n",
"subject 0\n",
"date 0\n",
"label 0\n",
"dtype: int64"
]
},
"metadata": {},
"execution_count": 56
}
]
},
{
"cell_type": "code",
"source": [
"# Reducing additional features\n",
"final_news_dataset.drop([\"subject\",\"date\"], axis=1)\n",
"\n",
"# Exploring labelwise value counts\n",
"final_news_dataset.label.value_counts()\n",
"\n",
"#viewing the processed data\n",
"sns.set_theme(style=\"whitegrid\")\n",
"sns.countplot(x=final_news_dataset[\"label\"])"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "zXrtchOF4R6T",
"outputId": "d0e6aac8-922a-4715-d7ec-5680cc1e3de5"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"fake 23481\n",
"true 21417\n",
"Name: label, dtype: int64"
]
},
"metadata": {},
"execution_count": 57
}
]
},
{
"cell_type": "code",
"source": [],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 629
},
"id": "6HCRcYsl5Bgf",
"outputId": "62e0a242-d791-43e3-8a04-3c66e88c3b58"
},
"execution_count": null,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<AxesSubplot:xlabel='label', ylabel='count'>"
]
},
"metadata": {},
"execution_count": 58
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<Figure size 720x720 with 1 Axes>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAnkAAAJSCAYAAAC/YtNUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAAsTAAALEwEAmpwYAAAc2UlEQVR4nO3df6xX9X3H8de9wL1W1F7RYi+0i9ZOw0YM6b1rs7WsG8aAjbW1PwZBY1qnmyZ2P1xFO1foKLoBtslsnXbR1CxBSbPGMpiV1pl1btOmshh3Zzeco27KnU7QgaiX671nfxhuvK3WW+B7v/i+j8df3vM5N+d9TDh55pz7/Z6OpmmaAABQSme7BwAA4PATeQAABYk8AICCRB4AQEEiDwCgoOntHuBIMzo6mn379mXGjBnp6Oho9zgAAK+raZoMDw9n5syZ6ewcf+9O5P2Yffv2Zfv27e0eAwBgwk477bQce+yx47aJvB8zY8aMJK/8z+rq6mrzNAAAr2///v3Zvn37WL+8msj7MQce0XZ1daW7u7vN0wAAvLHX+hMzH7wAAChI5AEAFCTyAAAKEnkAAAWJPACAgkQeAEBBIg8AoCCRBwBQkMgDAChI5AEAFCTyAAAKEnkAAAWJPACAgkQeAEBBIg8AoCCRBwBQkMgDAChI5AEAFCTyAAAKEnkAAAWJPACAgkQeAEBBIg8AoCCRB1DU6MvD7R4BpqQj5d/e9HYPAEBrdE6fkW3rLm73GDDl9K24pd0jJHEnDwCgJJEHAFCQyAMAKEjkAQAUJPIAAAoSeQAABYk8AICCRB4AQEEiDwCgIJEHAFCQyAMAKEjkAQAUJPIAAAoSeQAABYk8AICCRB4AQEEiDwCgIJEHAFCQyAMAKEjkAQAUJPIAAAoSeQAABYk8AICCRB4AQEEiDwCgIJEHAFCQyAMAKEjkAQAUJPIA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jF7N69O7Nmzfqpv9s0TZJk//79LZ/z1Y47esakHg9IhoaG2j1C6x11bLsngClnMq8tB3rlQL+8WsnIGxwczEknnZRp06YlSaZNm5bZs2dncHDwDSNveHg4SbJ9+/aWz/lql3z41Ek9HpAMDAy0e4TWe/8F7Z4Appx2XFuGh4dz1FFHjdtWMvIOxcyZM3PaaadlxowZ6ejoaPc4AACvq2maDA8PZ+bMmT+xVjLyent789RTT2VkZCTTpk3LyMhInn766fT29r7h73Z2dubYYz3eAADeHH78Dt4BJT94ccIJJ2TevHnZsmVLkmTLli2ZN2/eGz6qBQCooqN5rb/UK+Cxxx7L1VdfnT179uS4447L2rVr8653vavdYwEATIqykQcAMJWVfFwLADDViTwAgIJEHgBAQSIPAKAgkQev4Stf+cqkv9oOqO+ee+7J2WefnY9+9KP5z//8z9fc5/vf/34+9rGPTfJkVCTy4DV89atfHXvF3au9/PLLbZgGqGLjxo35nd/5nXzrW9/ytV60XMk3XsCh+OM//uMkybJly9LZ2Zm5c+fm+OOPz44dO7Jv377ceOON+fjHP57vf//7SZInnnhi3M/f+973ctNNN2X//v2ZMWNGPve5z2XBggXtOh3gCHHddddl27Zt2bFjR26//fbMnj07O3bsyPDwcH7u534u1113Xd761reO+509e/bk8ssvz6JFi/KpT30qd955Z26//faMjIzkmGOOyRe+8AWxyOtrgJ9w2mmnNc8//3zTNE1z1VVXNeedd16zb9++pmma5r//+7+b9773vWP7vvrnxx9/vPmN3/iNZu/evU3TNM327dubD37wg5M7PHDEuuCCC5p77723aZqm2bVr19j2L3/5y8369eubpmmaBx54oDnvvPOaJ554ojnvvPOab3/7203TNM0PfvCD5pJLLmmGhoaapmmav/u7v2uWLl06yWfAm4k7eTABS5YsydFHH/2G+9133335r//6r5x//vlj215++eU888wzOfHEE1s5IvAms2nTpmzevDnDw8N54YUXcvLJJ4+t/e///m8uvPDCrF27Nv39/UmSe++9N//2b/+WT37yk0leeTH9nj172jE6bxIiDybg1YE3ffr0NK96UczQ0NC4fRcuXJh169ZN2mzAm8+DDz6YO+64Ixs3bsysWbOyefPmfOMb3xhbf+tb35q3v/3t+fu///uxyGuaJh//+Mfzu7/7u+0amzcZH7yA1zBz5sw8//zzr7l24oknZnh4OI8//niSZMuWLWNr73//+3Pffffl0UcfHdv28MMPt3ZY4E1nz549OeaYY9LT05P9+/fnm9/85rj1rq6u/Pmf/3n+4z/+I2vWrEnTNFm0aFE2bdqU//mf/0mSjIyMZGBgoB3j8ybhTh68hosuuigXXnhhjjrqqMydO3fc2vTp03PNNdfk05/+dGbNmpVf+7VfG1s7+eSTs379+lxzzTV56aWXMjw8nPe85z0544wzJvkMgCPZwoUL89d//ddZvHhxjj/++PT39+df/uVfxu3T1dWVG264IVdeeWU+//nPZ/Xq1fm93/u9XHbZZRkZGcnw8HCWLFmS+fPnt+ksONJ1NK9+7gQAQAke1wIAFCTyAAAKEnkAAAWJPACAgkQeAEBBIg/gZ7Ro0aL80z/90xvud/rpp499n+LP6lB+FyAReQAAJYk8AICCRB7AQXr44YezdOnS9Pf35wMf+EBWr16d/fv3j9vne9/7Xs4888y8733vy9q1azM6Ojq29ld/9Vc5++yz80u/9Ev5zd/8zTz55JOTfQpAYSIP4CB1dnbmc5/7XB544IFs3Lgx999/f26//fZx+3z3u9/NN7/5zdx555259957x95Res899+RrX/tavvrVr+b+++9PX19f/uAP/qAdpwEUJfIADtL8+fOzYMGCTJ8+Pe94xzuydOnS/OAHPxi3zyWXXJKenp7MmTMnF154YbZs2ZIk2bhxY37rt34rp556aqZPn55LL700P/zhD93NAw6b6e0eAODNaseOHfnTP/3TDAwM5MUXX8zIyEh+8Rd/cdw+vb29Y/89d+7cPP3000mSnTt35rrrrsvatWvH1pumyVNPPZW5c+dOzgkApYk8gIP0hS98Ib/wC7+QL33pSznmmGNy2223ZevWreP2GRwczM///M8neSXsZs+eneSV+Lv00ktz7rnnTvrcwNTgcS3AQdq3b19mzpyZmTNn5rHHHssdd9zxE/vceuut+b//+78MDg7mL//yL/OhD30oSbJs2bL8xV/8RR599NEkyd69e/Ptb397UucHanMnD+AgXXXVVfn85z+fW2+9NfPmzcuHPvShPPDAA+P2OfPMM/Oxj30szz//fM4777x84hOfSJKcddZZ2bdvX6644oo8+eSTOfbYY/Mrv/IrOfvss9txKkBBHU3TNO0eAgCAw8vjWgCAgkQeAEBBIg8AoCCRBwBQkMgDAChI5AEAFCTyAAAKEnkAAAWJPACAgv4fdbB9EaexJy4AAAAASUVORK5CYII=\n"
},
"metadata": {}
}
]
},
{
"cell_type": "code",
"source": [
"# Minimizing the features\n",
"final_news_dataset[\"text\"]=final_news_dataset[\"title\"]+final_news_dataset[\"text\"]\n",
"dataset=final_news_dataset[[\"text\",\"label\"]]\n",
"\n",
"# Maping the labels into 0s and 1s\n",
"dataset['label'] = final_news_dataset['label'].map({'true':1, 'fake':0})"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "KhsDEe-I5OiT",
"outputId": "fefc48c1-6839-433f-c79a-881344b898f8"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"<ipython-input-59-72ed2ab62922>:6: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" dataset['label'] = final_news_dataset['label'].map({'true':1, 'fake':0})\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# storing the features \n",
"max_len=100\n",
"text=dataset[\"text\"]\n",
"label=dataset[\"label\"]"
],
"metadata": {
"id": "icH5EXWj6l-9"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"\n",
"# Load the tokenizer and model\n",
"tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')\n",
"model = BertForSequenceClassification.from_pretrained('bert-base-uncased', num_labels=2)\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "WqdRXa1XEvPr",
"outputId": "14ac8ce1-4fbb-4fd2-a7f2-0fb9fa5cba8f"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"Some weights of the model checkpoint at bert-base-uncased were not used when initializing BertForSequenceClassification: ['cls.predictions.bias', 'cls.predictions.transform.dense.weight', 'cls.predictions.transform.dense.bias', 'cls.predictions.transform.LayerNorm.weight', 'cls.seq_relationship.bias', 'cls.seq_relationship.weight', 'cls.predictions.transform.LayerNorm.bias', 'cls.predictions.decoder.weight']\n",
"- This IS expected if you are initializing BertForSequenceClassification from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).\n",
"- This IS NOT expected if you are initializing BertForSequenceClassification from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).\n",
"Some weights of BertForSequenceClassification were not initialized from the model checkpoint at bert-base-uncased and are newly initialized: ['classifier.bias', 'classifier.weight']\n",
"You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"text_train, text_test, label_train, label_test = train_test_split(text, label, stratify = label, test_size = 0.2, random_state = 50)"
],
"metadata": {
"id": "B580Edzq7OKu"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import transformers\n",
"\n",
"def tokenize_text(input_text):\n",
" # Initialize a BERT tokenizer with the pretrained model\n",
" tokenizer = transformers.BertTokenizer.from_pretrained('bert-base-uncased')\n",
" \n",
" # Tokenize the input text\n",
" tokenized_text = tokenizer.batch_encode_plus(\n",
" input_text,\n",
" max_length=100,\n",
" add_special_tokens=True,\n",
" padding='max_length',\n",
" truncation=True,\n",
" return_attention_mask=True,\n",
" return_token_type_ids=False,\n",
" verbose=True\n",
" )\n",
" \n",
" # Return the tokenized text\n",
" return tokenized_text"
],
"metadata": {
"id": "_VmBjJZs9BXu"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"data_train_token = tokenize_text(text_train)\n",
"data_test_token = tokenize_text(text_test)"
],
"metadata": {
"id": "YbrRMAyG9EYN"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import tensorflow as tf\n",
"from tensorflow.keras.layers import Input, Dense, Dropout\n",
"from tensorflow.keras.models import Model\n",
"import transformers\n",
"\n",
"def create_model(maxlen):\n",
" # Load the BERT model and tokenizer\n",
" bert_model = transformers.TFBertModel.from_pretrained('bert-base-uncased')\n",
" bert_tokenizer = transformers.BertTokenizer.from_pretrained('bert-base-uncased')\n",
" \n",
" # Define input layers for BERT inputs\n",
" input_ids = Input(shape=(maxlen,), dtype=tf.int32)\n",
" input_mask = Input(shape=(maxlen,), dtype=tf.int32)\n",
" \n",
" # Use the BERT model to encode the input text\n",
" bert_layer = bert_model([input_ids, input_mask])[1]\n",
" \n",
" # Apply dropout regularization\n",
" x = Dropout(0.5)(bert_layer)\n",
" \n",
" # Add a fully connected layer with activation function tanh\n",
" x = Dense(64, activation='tanh')(x)\n",
" \n",
" # Apply dropout regularization again\n",
" x = Dropout(0.2)(x)\n",
" \n",
" # Add a final output layer with sigmoid activation function\n",
" x = Dense(1, activation='sigmoid')(x)\n",
" \n",
" # Define the model with inputs and outputs\n",
" model = Model(inputs=[input_ids, input_mask], outputs=x)\n",
" \n",
" # Return the model\n",
" return model"
],
"metadata": {
"id": "R_ypyyBA-_oh"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Checking out the model\n",
"\n",
"model=create_model(100)\n",
"model.summary()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "1R3mS0IK_G9l",
"outputId": "0e1eb00c-bfd5-4680-f033-c791f3fa2f42"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"Some layers from the model checkpoint at bert-base-uncased were not used when initializing TFBertModel: ['mlm___cls', 'nsp___cls']\n",
"- This IS expected if you are initializing TFBertModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).\n",
"- This IS NOT expected if you are initializing TFBertModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).\n",
"All the layers of TFBertModel were initialized from the model checkpoint at bert-base-uncased.\n",
"If your task is similar to the task the model of the checkpoint was trained on, you can already use TFBertModel for predictions without further training.\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Model: \"model_1\"\n",
"__________________________________________________________________________________________________\n",
" Layer (type) Output Shape Param # Connected to \n",
"==================================================================================================\n",
" input_3 (InputLayer) [(None, 100)] 0 [] \n",
" \n",
" input_4 (InputLayer) [(None, 100)] 0 [] \n",
" \n",
" tf_bert_model_1 (TFBertModel) TFBaseModelOutputWi 109482240 ['input_3[0][0]', \n",
" thPoolingAndCrossAt 'input_4[0][0]'] \n",
" tentions(last_hidde \n",
" n_state=(None, 100, \n",
" 768), \n",
" pooler_output=(Non \n",
" e, 768), \n",
" past_key_values=No \n",
" ne, hidden_states=N \n",
" one, attentions=Non \n",
" e, cross_attentions \n",
" =None) \n",
" \n",
" dropout_76 (Dropout) (None, 768) 0 ['tf_bert_model_1[0][1]'] \n",
" \n",
" dense_2 (Dense) (None, 64) 49216 ['dropout_76[0][0]'] \n",
" \n",
" dropout_77 (Dropout) (None, 64) 0 ['dense_2[0][0]'] \n",
" \n",
" dense_3 (Dense) (None, 1) 65 ['dropout_77[0][0]'] \n",
" \n",
"==================================================================================================\n",
"Total params: 109,531,521\n",
"Trainable params: 109,531,521\n",
"Non-trainable params: 0\n",
"__________________________________________________________________________________________________\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"import tensorflow as tf\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# Set up the optimizer with specific parameters\n",
"optimizer = tf.keras.optimizers.legacy.Adam(\n",
" learning_rate=1e-05,\n",
" epsilon=1e-08,\n",
" decay=0.01,\n",
" clipnorm=1.0\n",
")\n",
"\n",
"\n",
"# Compile the model with binary cross-entropy loss and accuracy metric\n",
"model.compile(\n",
" optimizer=optimizer,\n",
" loss='binary_crossentropy',\n",
" metrics=['accuracy']\n",
")\n",
"\n",
"# Set up an early stopping callback with specific parameters\n",
"callback = tf.keras.callbacks.EarlyStopping(\n",
" monitor='val_loss',\n",
" mode='max',\n",
" verbose=1,\n",
" patience=50,\n",
" baseline=0.4,\n",
" min_delta=0.0001,\n",
" restore_best_weights=False\n",
")\n"
],
"metadata": {
"id": "GPVqHrW2BBBe"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"history = model.fit(x = {'input_1':data_train_token['input_ids'],'input_2':data_train_token['attention_mask']}, y = label_train, epochs=10, validation_split = 0.2, batch_size = 30, callbacks=[callback])"
],
"metadata": {
"id": "m8etkxDDUfnc"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# make predictions on the test data\n",
"test_pred = model.predict(text_test)\n",
"\n",
"# calculate AUC score on the test data\n",
"auc_score = roc_auc_score(label_test, test_pred)\n",
"\n",
"# plot ROC curve\n",
"fpr, tpr, _ = roc_curve(label_test, test_pred)\n",
"plt.plot(fpr, tpr)\n",
"plt.title('ROC Curve (AUC = {:.2f})'.format(auc_score))\n",
"plt.xlabel('False Positive Rate')\n",
"plt.ylabel('True Positive Rate')\n",
"plt.show()"
],
"metadata": {
"id": "aLSwrYrYZN_D"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import numpy as np\n",
"from sklearn.metrics import confusion_matrix\n",
"from mlxtend.plotting import plot_confusion_matrix\n",
"import matplotlib.pyplot as plt\n",
"\n",
"\n",
"conf_matrix = confusion_matrix(Y_test,y_pred)\n",
"fig, ax = plot_confusion_matrix(conf_mat=conf_matrix, figsize=(6, 6), cmap=plt.cm.Greens)\n",
"plt.xlabel('Predictions', fontsize=18)\n",
"plt.ylabel('Actuals', fontsize=18)\n",
"plt.title('Confusion Matrix', fontsize=18)\n",
"plt.show()\n"
],
"metadata": {
"id": "LIE2zuvMPDfN"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"\n",
"# # Evaluate the model and generate an AUC curve\n",
"# # model.eval()\n",
"# y_true = []\n",
"# y_pred = []\n",
"# with torch.no_grad():\n",
"# for batch in test_dataloader:\n",
"# input_ids, attention_mask, labels = batch\n",
"# outputs = model(input_ids, attention_mask=attention_mask)\n",
"# logits = outputs.logits\n",
"# probs = torch.softmax(logits, dim=1)[:, 1]\n",
"# y_true.extend(labels.numpy())\n",
"# y_pred.extend(probs.numpy())\n",
"# auc = roc_auc_score(y_true, y_pred)\n",
"# print(f'AUC: {auc}')\n"
],
"metadata": {
"id": "nOoRwd7tFFO_"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"testcase = \"New York City is set to reopen its public schools for in-person learning in the fall with no remote option for students, Mayor Bill de Blasio announced on Monday, making it the largest school district in the country to offer no virtual learning. The announcement came as the city has achieved its goal of vaccinating at least one million residents against Covid-19 and as public health officials have said that it is safe for schools to fully reopen.\""
],
"metadata": {
"id": "T8o_10CHa9qW"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"test_token = tokenize_text(testcase)"
],
"metadata": {
"id": "xmzHCwfZbqV7"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"test_text_pred = np.where(model.predict({ 'input_1' : test_token['input_ids'] , 'input_2' : test_token['attention_mask']}) >=0.5,1,0)"
],
"metadata": {
"id": "4ysgjuEYb1eS"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"if(test_text_pred[0]==0): print(\"Fake news\")\n",
"else: print(\"True News\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "cM8-uH_Kb8Ok",
"outputId": "94931573-ddb5-4516-8a52-b60bfc405186"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Fake news\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"**Write up**: \n",
"* Link to the model on Hugging Face Hub: \n",
"* Include some examples of misclassified news articles. Please explain what you might do to improve your model's performance on these news articles in the future (you do not need to impelement these suggestions)\n",
"\n",
"[Please put your write up here]"
],
"metadata": {
"id": "kpInVUMLyJ24"
}
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"id": "ZTSnl1RBoCCy"
}
},
{
"cell_type": "markdown",
"metadata": {
"id": "jTfHpo6BOmE8"
},
"source": [
"# 3. Deep RL / Robotics"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "saB64bbTXWgZ"
},
"source": [
"**RL for Classical Control:** Using any of the [classical control](https://github.com/openai/gym/blob/master/docs/environments.md#classic-control) environments from OpenAI's `gym`, implement a deep NN that learns an optimal policy which maximizes the reward of the environment.\n",
"\n",
"* Describe the NN you implemented and the behavior you observe from the agent as the model converges (or diverges).\n",
"* Plot the reward as a function of steps (or Epochs).\n",
"Compare your results to a random agent.\n",
"* Discuss whether you think your model has learned the optimal policy and potential methods for improving it and/or where it might fail.\n",
"* (Optional) [Upload the the model to the Hugging Face Hub](https://huggingface.co/docs/hub/adding-a-model), and add a link to your model below.\n",
"\n",
"\n",
"You may use any frameworks you like, but you must implement your NN on your own (no pre-defined/trained models like [`stable_baselines`](https://stable-baselines.readthedocs.io/en/master/)).\n",
"\n",
"You may use any simulator other than `gym` _however_:\n",
"* The environment has to be similar to the classical control environments (or more complex like [`robosuite`](https://github.com/ARISE-Initiative/robosuite)).\n",
"* You cannot choose a game/Atari/text based environment. The purpose of this challenge is to demonstrate an understanding of basic kinematic/dynamic systems."
]
},
{
"cell_type": "code",
"source": [
"### WRITE YOUR CODE TO TRAIN THE MODEL HERE"
],
"metadata": {
"id": "CUhkTcoeynVv"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"**Write up**: \n",
"* (Optional) link to the model on Hugging Face Hub: \n",
"* Discuss whether you think your model has learned the optimal policy and potential methods for improving it and/or where it might fail.\n",
"\n",
"[Please put your write up here]"
],
"metadata": {
"id": "bWllPZhJyotg"
}
},
{
"cell_type": "markdown",
"metadata": {
"id": "rbrRbrISa5J_"
},
"source": [
"# 4. Theory / Linear Algebra "
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "KFkLRCzTXTzL"
},
"source": [
"**Implement Contrastive PCA** Read [this paper](https://www.nature.com/articles/s41467-018-04608-8) and implement contrastive PCA in Python.\n",
"\n",
"* First, please discuss what kind of dataset this would make sense to use this method on\n",
"* Implement the method in Python (do not use previous implementations of the method if they already exist)\n",
"* Then create a synthetic dataset and apply the method to the synthetic data. Compare with standard PCA.\n"
]
},
{
"cell_type": "markdown",
"source": [
"**Write up**: Discuss what kind of dataset it would make sense to use Contrastive PCA\n",
"\n",
"[Please put your write up here]"
],
"metadata": {
"id": "TpyqWl-ly0wy"
}
},
{
"cell_type": "code",
"source": [
"### WRITE YOUR CODE HERE"
],
"metadata": {
"id": "1CQzUSfQywRk"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# 5. Systems"
],
"metadata": {
"id": "dlqmZS5Hy6q-"
}
},
{
"cell_type": "markdown",
"source": [
"**Inference on the edge**: Measure the inference times in various computationally-constrained settings\n",
"\n",
"* Pick a few different speech detection models (we suggest looking at models on the [Hugging Face Hub](https://huggingface.co/models?pipeline_tag=automatic-speech-recognition&sort=downloads))\n",
"* Simulate different memory constraints and CPU allocations that are realistic for edge devices that might run such models, such as smart speakers or microcontrollers, and measure what is the average inference time of the models under these conditions \n",
"* How does the inference time vary with (1) choice of model (2) available system memory (3) available CPU (4) size of input?\n",
"\n",
"Are there any surprising discoveries? (Note that this coding challenge is fairly open-ended, so we will be considering the amount of effort invested in discovering something interesting here)."
],
"metadata": {
"id": "QW_eiDFw1QKm"
}
},
{
"cell_type": "code",
"source": [
"### WRITE YOUR CODE HERE"
],
"metadata": {
"id": "OYp94wLP1kWJ"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"**Write up**: What surprising discoveries do you see?\n",
"\n",
"[Please put your write up here]"
],
"metadata": {
"id": "yoHmutWx2jer"
}
}
]
} |