File size: 2,948 Bytes
b539400 |
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 |
{
"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(\"GPT-NEO\", \"EleutherAI/gpt-neo-125M\")"
],
"metadata": {
"id": "4V9hd8bQ41HD"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!wget https://huggingface.co./datasets/DarwinAnim8or/grug/resolve/main/grug-training.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 = 2)\n",
"happy_gen.train(\"grug-training.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=50, temperature=0.7, max_length=50, early_stopping=False)"
],
"metadata": {
"id": "LXi7hXFtBLpN"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"result = happy_gen.generate_text(\"\"\"Person: \"Hello grug\"\n",
"Grug: \"hello person\"\n",
"###\n",
"Person: \"how are you grug\"\n",
"Grug: \"grug doing ok. grug find many berry. good for tribe.\"\n",
"###\n",
"Person: \"what does grug think of new spear weapon?\"\n",
"Grug: \"grug no like new spear weapon. grug stick bigger. spear too small, break easy\"\n",
"###\n",
"Person: \"what does grug think of football?\"\n",
"Grug: \\\"\"\"\", args=args_top_k)\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(\"gpt-grug-125m-epoch4/\")"
],
"metadata": {
"id": "LFUPtXAo_dTz"
},
"execution_count": null,
"outputs": []
}
]
} |