MODEL, OUTPUT_DIR, TRAIN_STEPS, TITLE = parse_arguments()

#For Mark's machine
os.environ["CUDA_VISIBLE_DEVICES"] = "1,2"

if not os.path.isdir(os.path.join("models", MODEL)):
    print(f"Downloading {MODEL} model...")
    gpt2.download_gpt2(
        model_name=MODEL
    )  # model is saved into current directory under /models/124M/

config = tf.ConfigProto()
config.gpu_options.allow_growth = True

sess = gpt2.start_tf_sess()

#gpt2.load_gpt2(sess, model_name = MODEL)
# Train Topic generator
print("TRAINING TOPIC GENERATOR...")
if TRAIN_STEPS > 0:
    gpt2.finetune(sess,
                  dataset=TRAIN_TOPIC_PATH,
                  model_name=MODEL,
                  steps=TRAIN_STEPS,
                  checkpoint_dir="topic_gen_chkpts",
                  multi_gpu=True,
                  val_dataset=VALID_TOPIC_PATH,
                  val_every=10)

    #gpt2.load_gpt2(sess, model_name = MODEL)
Example #2
0
from gpt_2 import finetune, start_tf_sess
import argparse

if __name__ == "__main__":

    parser = argparse.ArgumentParser(
        description='TensorFlow Haiku GPT-2 Finetuned Language Model')
    parser.add_argument('--dataset',
                        type=str,
                        help='location of the data corpus')
    parser.add_argument('--model_name',
                        type=str,
                        default='models/117M',
                        help='Pretrained model path')
    parser.add_argument('--steps',
                        type=int,
                        default=1000,
                        help='No of epochs to train during finetuning')
    args = parser.parse_args()
    sess = start_tf_sess()
    finetune(sess,
             dataset=args.dataset,
             model_name=args.model_name,
             steps=args.steps,
             restore_from='fresh',
             run_name='run1',
             print_every=100,
             sample_every=500,
             save_every=500)
    print("Finetuning completed!!!")
Example #3
0
import asyncio
import discord
from discord.ext import commands
import os, datetime, numpy as np, json, re, sys, time
import gpt_2, tensorflow as tf
import re

sess = gpt_2.start_tf_sess()
print(gpt_2.load_gpt2(sess))

checkpoint_path = os.path.join('models', '345M')
enc = gpt_2.encoder.get_encoder(checkpoint_path)

hparams = gpt_2.model.default_hparams()
with open(os.path.join(checkpoint_path, 'hparams.json')) as f:
    hparams.override_from_dict(json.load(f))
context = tf.compat.v1.placeholder(tf.int32, [1, None])

bot = commands.Bot(command_prefix='none')

f = open("bot.txt")
bot_token = f.read()

emojis = dict()
imitates = dict()
session = dict()
messages = dict()
messagequeue = dict()

tf_sample = gpt_2.sample.sample_sequence(hparams=hparams,
                                         length=728,