Spaces:
Runtime error
Runtime error
File size: 26,447 Bytes
a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f ba07099 a895a4f |
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 |
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"machine_shape": "hm"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"gpuClass": "standard",
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"source": [
"# Fintune GPT2 using HuggingFace & PyTorch"
],
"metadata": {
"id": "2K_YzZvVxv81"
}
},
{
"cell_type": "code",
"source": [
"!pip install --quiet transformers==4.2.2"
],
"metadata": {
"id": "F4DGSHU_e915"
},
"execution_count": 1,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Based off of [Philipp Schmid's](https://www.philschmid.de/philipp-schmid) [notebook](https://colab.research.google.com/github/philschmid/fine-tune-GPT-2/blob/master/Fine_tune_a_non_English_GPT_2_Model_with_Huggingface.ipynb#scrollTo=laDp891gO25V) with data from the [Trump Twitter Archive](https://www.thetrumparchive.com/?results=1).\n",
"\n",
"- GPT2 [Model Card](https://huggingface.co/gpt2)\n",
"-[HuggingFace's Finetuning Docs](https://huggingface.co/learn/nlp-course/chapter3/3?fw=pt)"
],
"metadata": {
"id": "lw58eJhpyCww"
}
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "iwZxNbIIbzbR"
},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"import pandas as pd\n",
"import json\n",
"from transformers import (\n",
" TextDataset,\n",
" DataCollatorForLanguageModeling,\n",
" AutoTokenizer,\n",
" AutoModelWithLMHead,\n",
" get_linear_schedule_with_warmup,\n",
" Trainer,\n",
" TrainingArguments,\n",
" pipeline\n",
")\n",
"from sklearn.model_selection import train_test_split\n",
"from tqdm.auto import tqdm\n",
"import torch\n",
"from pathlib import Path"
]
},
{
"cell_type": "code",
"source": [
"model_name = \"gpt2-medium\"\n",
"\n",
"if model_name == \"gpt2\":\n",
" model_size = \"124M\"\n",
"elif model_name == \"gpt2-medium\":\n",
" model_size = \"355M\"\n",
"elif model_name == \"gpt2-large\":\n",
" model_size = \"774M\"\n",
"elif model_name == \"gpt2-xl\":\n",
" model_size = \"1.5B\""
],
"metadata": {
"id": "GxBa9kFFsHaM"
},
"execution_count": 3,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# define some params for model\n",
"batch_size = 8\n",
"epochs = 15\n",
"learning_rate = 5e-4\n",
"epsilon = 1e-8\n",
"warmup_steps = 1e2\n",
"sample_every = 100 # produce sample output every 100 steps\n",
"max_length = 140 # max length used in generate method of model"
],
"metadata": {
"id": "1hFiQUbNcANl"
},
"execution_count": 4,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Fetch / Load Data & Preprocess"
],
"metadata": {
"id": "9PY6SSKlcJNq"
}
},
{
"cell_type": "code",
"source": [
"tweets_path = Path(\"./data/tweets.json\")\n",
"train_path = Path(\"./data/train_tweets.csv\")\n",
"dev_path = Path(\"./data/dev_tweets.csv\")\n",
"\n",
"# fetch data if !exists already\n",
"if not tweets_path.exists():\n",
" !mkdir data\n",
" !wget -O ./data/tweets.json \"https://drive.google.com/uc?export=download&id=16wm-2NTKohhcA26w-kaWfhLIGwl_oX95\"\n",
"\n",
"if not (train_path.exists() and dev_path.exists()):\n",
" with open(tweets_path, 'rb') as f:\n",
" # read json file into dict and then parse into df\n",
" as_dict = json.loads(f.read())\n",
" df = pd.DataFrame(as_dict)\n",
" \n",
" # filter df by !retweet\n",
" df = df[df['isRetweet'] == \"f\"]\n",
"\n",
" # filter df to only text\n",
" def is_multimedia(tweet: str):\n",
" if tweet.startswith('https://t.co/'):\n",
" return \"t\"\n",
" else:\n",
" return \"f\"\n",
"\n",
" df['isMultimedia'] = df['text'].apply(lambda x : is_multimedia(x))\n",
" df = df[df['isMultimedia'] == \"f\"]\n",
" df = df.reset_index(drop=True)\n",
"\n",
" # filter tweets to remove 'amp;'\n",
" def remove_amp(tweet):\n",
" tweet = tweet.replace('amp;', '')\n",
" tweet = tweet.replace('amp', '')\n",
" return tweet\n",
" df['text'] = df['text'].apply(lambda x: remove_amp(x))\n",
"\n",
" # rename 'text' column to 'labels'\n",
" # df = df.rename(columns={'text': 'labels'})\n",
" \n",
" # create train, validation splits\n",
" train_data, dev_data = train_test_split(df[['text']], test_size=0.15) \n",
" \n",
" train_data.to_csv(train_path, index=False, header=None)\n",
" dev_data.to_csv(dev_path, index=False, header=None)"
],
"metadata": {
"id": "aLQVWQ_dcB2h"
},
"execution_count": 5,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# create tokenized datasets\n",
"tokenizer = AutoTokenizer.from_pretrained(\n",
" model_name, \n",
" pad_token='<|endoftext|>'\n",
")\n",
"\n",
"# custom load_dataset function because there are no labels\n",
"def load_dataset(train_path, dev_path, tokenizer):\n",
" block_size = 128\n",
" # block_size = tokenizer.model_max_length\n",
" \n",
" train_dataset = TextDataset(\n",
" tokenizer=tokenizer,\n",
" file_path=train_path,\n",
" block_size=block_size)\n",
" \n",
" dev_dataset = TextDataset(\n",
" tokenizer=tokenizer,\n",
" file_path=dev_path,\n",
" block_size=block_size) \n",
" \n",
" data_collator = DataCollatorForLanguageModeling(\n",
" tokenizer=tokenizer, mlm=False,\n",
" )\n",
" return train_dataset, dev_dataset, data_collator\n",
"\n",
"train_dataset, dev_dataset, data_collator = load_dataset(train_path, dev_path, tokenizer)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "DAd1-0nLfcej",
"outputId": "bc4e47c7-2fc9-47a4-add6-9a573568eb4c"
},
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"/usr/local/lib/python3.9/dist-packages/transformers/data/datasets/language_modeling.py:54: FutureWarning: This dataset will be removed from the library soon, preprocessing should be handled with the 🤗 Datasets library. You can have a look at this example script for pointers: https://github.com/huggingface/transformers/blob/master/examples/language-modeling/run_mlm.py\n",
" warnings.warn(\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"## Finetune Model"
],
"metadata": {
"id": "6szJYteUf9L3"
}
},
{
"cell_type": "code",
"source": [
"# AutoModelWithLMHead will pick GPT-2 weights from name\n",
"model = AutoModelWithLMHead.from_pretrained(model_name, cache_dir=Path('cache').resolve())\n",
"\n",
"# necessary because of additional bos, eos, pad tokens to embeddings\n",
"model.resize_token_embeddings(len(tokenizer))\n",
"\n",
"# create optimizer and learning rate schedule \n",
"optimizer = torch.optim.AdamW(model.parameters(), lr=learning_rate, eps=epsilon)\n",
"\n",
"training_steps = len(train_dataset) * epochs\n",
"\n",
"# adjust learning rate during training\n",
"scheduler = get_linear_schedule_with_warmup(optimizer, \n",
" num_warmup_steps = warmup_steps, \n",
" num_training_steps = training_steps)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Nv-bFNB1f68X",
"outputId": "610e42fc-4fc2-4ceb-eb38-f00423fb5594"
},
"execution_count": 7,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"/usr/local/lib/python3.9/dist-packages/transformers/models/auto/modeling_auto.py:921: FutureWarning: The class `AutoModelWithLMHead` is deprecated and will be removed in a future version. Please use `AutoModelForCausalLM` for causal language models, `AutoModelForMaskedLM` for masked language models and `AutoModelForSeq2SeqLM` for encoder-decoder models.\n",
" warnings.warn(\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"training_args = TrainingArguments(\n",
" output_dir=f\"./{model_name}-{model_size}-trump\",\n",
" overwrite_output_dir=True,\n",
" num_train_epochs=epochs,\n",
" per_device_train_batch_size=batch_size,\n",
" per_device_eval_batch_size=batch_size,\n",
" eval_steps = 400, # n update steps between two evaluations\n",
" save_steps=800, # n steps per model save \n",
" warmup_steps=500, # n warmup steps for learning rate scheduler\n",
" remove_unused_columns=False,\n",
" prediction_loss_only=True\n",
")\n",
"\n",
"trainer = Trainer(\n",
" model=model,\n",
" args=training_args,\n",
" data_collator=data_collator,\n",
" train_dataset=train_dataset,\n",
" eval_dataset=dev_dataset,\n",
")"
],
"metadata": {
"id": "5OvNyCQagD1I"
},
"execution_count": 8,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# train & save model run\n",
"trainer.train()\n",
"trainer.save_model()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000
},
"id": "Ni9OyHY5gQLw",
"outputId": "f0322248-f504-405d-d2e9-1b5646e8946c"
},
"execution_count": 9,
"outputs": [
{
"data": {
"text/html": [
"\n",
" <div>\n",
" <style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" </style>\n",
" \n",
" <progress value='10685' max='20460' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" [10685/20460 2:24:09 < 2:11:54, 1.24 it/s, Epoch 7.83/15]\n",
" </div>\n",
" <table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>Step</th>\n",
" <th>Training Loss</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>500</td>\n",
" <td>3.622700</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1000</td>\n",
" <td>3.301600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1500</td>\n",
" <td>3.145200</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2000</td>\n",
" <td>2.932000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2500</td>\n",
" <td>2.925000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3000</td>\n",
" <td>2.777100</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3500</td>\n",
" <td>2.661500</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4000</td>\n",
" <td>2.668100</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4500</td>\n",
" <td>2.482500</td>\n",
" </tr>\n",
" <tr>\n",
" <td>5000</td>\n",
" <td>2.455600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>5500</td>\n",
" <td>2.443600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>6000</td>\n",
" <td>2.266700</td>\n",
" </tr>\n",
" <tr>\n",
" <td>6500</td>\n",
" <td>2.271600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>7000</td>\n",
" <td>2.228200</td>\n",
" </tr>\n",
" <tr>\n",
" <td>7500</td>\n",
" <td>2.108600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>8000</td>\n",
" <td>2.133900</td>\n",
" </tr>\n",
" <tr>\n",
" <td>8500</td>\n",
" <td>2.017700</td>\n",
" </tr>\n",
" <tr>\n",
" <td>9000</td>\n",
" <td>1.985300</td>\n",
" </tr>\n",
" <tr>\n",
" <td>9500</td>\n",
" <td>1.999300</td>\n",
" </tr>\n",
" <tr>\n",
" <td>10000</td>\n",
" <td>1.859000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>10500</td>\n",
" <td>1.869600</td>\n",
" </tr>\n",
" </tbody>\n",
"</table><p>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.HTML object>"
],
"text/html": [
"\n",
" <div>\n",
" <style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" </style>\n",
" \n",
" <progress value='20460' max='20460' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
" [20460/20460 4:36:05, Epoch 15/15]\n",
" </div>\n",
" <table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>Step</th>\n",
" <th>Training Loss</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>500</td>\n",
" <td>3.622700</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1000</td>\n",
" <td>3.301600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1500</td>\n",
" <td>3.145200</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2000</td>\n",
" <td>2.932000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2500</td>\n",
" <td>2.925000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3000</td>\n",
" <td>2.777100</td>\n",
" </tr>\n",
" <tr>\n",
" <td>3500</td>\n",
" <td>2.661500</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4000</td>\n",
" <td>2.668100</td>\n",
" </tr>\n",
" <tr>\n",
" <td>4500</td>\n",
" <td>2.482500</td>\n",
" </tr>\n",
" <tr>\n",
" <td>5000</td>\n",
" <td>2.455600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>5500</td>\n",
" <td>2.443600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>6000</td>\n",
" <td>2.266700</td>\n",
" </tr>\n",
" <tr>\n",
" <td>6500</td>\n",
" <td>2.271600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>7000</td>\n",
" <td>2.228200</td>\n",
" </tr>\n",
" <tr>\n",
" <td>7500</td>\n",
" <td>2.108600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>8000</td>\n",
" <td>2.133900</td>\n",
" </tr>\n",
" <tr>\n",
" <td>8500</td>\n",
" <td>2.017700</td>\n",
" </tr>\n",
" <tr>\n",
" <td>9000</td>\n",
" <td>1.985300</td>\n",
" </tr>\n",
" <tr>\n",
" <td>9500</td>\n",
" <td>1.999300</td>\n",
" </tr>\n",
" <tr>\n",
" <td>10000</td>\n",
" <td>1.859000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>10500</td>\n",
" <td>1.869600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>11000</td>\n",
" <td>1.858000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>11500</td>\n",
" <td>1.759300</td>\n",
" </tr>\n",
" <tr>\n",
" <td>12000</td>\n",
" <td>1.765400</td>\n",
" </tr>\n",
" <tr>\n",
" <td>12500</td>\n",
" <td>1.732600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>13000</td>\n",
" <td>1.670400</td>\n",
" </tr>\n",
" <tr>\n",
" <td>13500</td>\n",
" <td>1.689000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>14000</td>\n",
" <td>1.619500</td>\n",
" </tr>\n",
" <tr>\n",
" <td>14500</td>\n",
" <td>1.611100</td>\n",
" </tr>\n",
" <tr>\n",
" <td>15000</td>\n",
" <td>1.619800</td>\n",
" </tr>\n",
" <tr>\n",
" <td>15500</td>\n",
" <td>1.539300</td>\n",
" </tr>\n",
" <tr>\n",
" <td>16000</td>\n",
" <td>1.550200</td>\n",
" </tr>\n",
" <tr>\n",
" <td>16500</td>\n",
" <td>1.539100</td>\n",
" </tr>\n",
" <tr>\n",
" <td>17000</td>\n",
" <td>1.491500</td>\n",
" </tr>\n",
" <tr>\n",
" <td>17500</td>\n",
" <td>1.507000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>18000</td>\n",
" <td>1.479400</td>\n",
" </tr>\n",
" <tr>\n",
" <td>18500</td>\n",
" <td>1.462600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>19000</td>\n",
" <td>1.464000</td>\n",
" </tr>\n",
" <tr>\n",
" <td>19500</td>\n",
" <td>1.442600</td>\n",
" </tr>\n",
" <tr>\n",
" <td>20000</td>\n",
" <td>1.439300</td>\n",
" </tr>\n",
" </tbody>\n",
"</table><p>"
]
},
"metadata": {}
}
]
},
{
"cell_type": "markdown",
"source": [
"## Generate tweets"
],
"metadata": {
"id": "vJLUI-tSgtaX"
}
},
{
"cell_type": "code",
"source": [
"trump = pipeline(\"text-generation\", model=f\"./{model_name}-{model_size}-trump\", tokenizer=tokenizer, config={\"max_length\":max_length})"
],
"metadata": {
"id": "-qyyt5O8TqON"
},
"execution_count": 10,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#@title\n",
"# give Trump a prompt\n",
"result = trump('The democrats have')"
],
"metadata": {
"id": "gnVtF1K_h473",
"collapsed": true,
"cellView": "form"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"trump('Why does the lying news media')"
],
"metadata": {
"id": "H02NvY6lEPTJ",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "1c9263ae-e166-4008-f0e1-d6cd26e6109c"
},
"execution_count": 12,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[{'generated_text': 'Why does the lying news media refuse to state that Cruz poll numbers, as opposed to others, are the highest of any GOP? He beat @RealBenCarson!\"\\n\"\"\"\"\"Donald Trump to run for PGA Grand regressor\"\"\"\" http'}]"
]
},
"metadata": {},
"execution_count": 12
}
]
},
{
"cell_type": "code",
"source": [
"trump(\"Today I'll be\")"
],
"metadata": {
"id": "n8BoiGLGEScg",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "81e35bc4-7005-42bf-c93b-8f70918ab802"
},
"execution_count": 13,
"outputs": [
{
"metadata": {
"tags": null
},
"name": "stderr",
"output_type": "stream",
"text": [
"Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.\n"
]
},
{
"data": {
"text/plain": [
"[{'generated_text': \"Today I'll be rallying w/ @FEMA, First Responders, Law Enforcement, and First Responders of Puerto Rico to help those most affected by the #IrmaFlood.https://t.co/gsFSghkmdM\"}]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"cell_type": "code",
"source": [
"trump(\"The democrats have\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "snXJFbPCEooG",
"outputId": "79b70812-0eab-4f41-80ce-6e30fb028ebe"
},
"execution_count": 14,
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation.\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[{'generated_text': 'The democrats have made life so difficult for your favorite President and Vice President. Many thousands of jobs have been lost. Would rather make a deal with Russia than play games. Great power for the U.S.A.\"\\n\"... and the U'}]"
]
},
"metadata": {},
"execution_count": 14
}
]
}
]
} |