File size: 2,715 Bytes
fdd7cd1 |
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 |
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU",
"gpuClass": "standard"
},
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "u7RAqjzj4ylm"
},
"outputs": [],
"source": [
"!pip install happytransformer"
]
},
{
"cell_type": "code",
"source": [
"from happytransformer import HappyGeneration\n",
"\n",
"happy_gen = HappyGeneration(\"GPT2\", \"gpt2-medium\")"
],
"metadata": {
"id": "4V9hd8bQ41HD"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!wget https://huggingface.co/datasets/DarwinAnim8or/greentext/resolve/main/greentexts.txt"
],
"metadata": {
"id": "hz3fzo5W9ppf"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from happytransformer import GENTrainArgs \n",
"\n",
"args = GENTrainArgs(learning_rate =1e-5, num_train_epochs = 15)\n",
"happy_gen.train(\"greentexts.txt\", args=args)"
],
"metadata": {
"id": "Yl4wNVvK5Bex"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"from happytransformer import GENSettings\n",
"args_top_k = GENSettings(no_repeat_ngram_size=3, do_sample=True, top_k=80, temperature=0.8, max_length=150, early_stopping=False)"
],
"metadata": {
"id": "LXi7hXFtBLpN"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"result = happy_gen.generate_text(\"\"\"Write a greentext from 4chan.org. The story should be like a bullet-point list using > as the start of each line. Most greentexts are humorous or absurd in nature. Most greentexts have a twist near the end.\n",
">be me\n",
">\"\"\", args=args_top_k)\n",
"\n",
"#print(result)\n",
"print(result.text)"
],
"metadata": {
"id": "ih4KihPy_U_h"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"#To save the model, run this cell.\n",
"happy_gen.save(\"gpt2-greentext-epoch-15/\")"
],
"metadata": {
"id": "LFUPtXAo_dTz"
},
"execution_count": null,
"outputs": []
}
]
} |