Untitled
unknown
python
2 years ago
844 B
7
Indexable
import gpt_2_simple as gpt2
import os
import requests
model_name = "124M"
if not os.path.isdir(os.path.join("models", model_name)):
print(f"Downloading {model_name} model...")
gpt2.download_gpt2(model_name=model_name) # model is saved into current directory under /models/124M/
def preprocess_text_file(file_name):
with open(file_name, 'r', encoding='ISO-8859-1') as f:
data = f.read()
tokens = data.split()
return data
def finetune_from_document(sess, document, model_name=model_name, steps=10):
data = preprocess_text_file(document)
if not data:
print("Error: Empty dataset or no tokens found.")
return
gpt2.finetune(sess, data, model_name=model_name, steps=steps)
sess = gpt2.start_tf_sess()
finetune_from_document(sess, "/home/nmahmoudi/Desktop/ib.txt")
gpt2.generate(sess)Editor is loading...
Leave a Comment