{ "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": [] } ] }