<jupyter_start><jupyter_text><jupyter_code>!pip install gpt-2-simple
import gpt_2_simple as gpt2
import os
import requests

model_name = "345M"
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/


file_name = "newyorktimes.txt"
if not os.path.isfile(file_name):
	url = "https://raw.githubusercontent.com/karpathy/char-rnn/master/data/tinyshakespeare/input.txt"
	data = requests.get(url)
	
	with open(file_name, 'w') as f:
		f.write(data.text)
    

sess = gpt2.start_tf_sess()
gpt2.finetune(sess,
              file_name,
              model_name=model_name,
              steps=10)   # steps is max number of training steps

gpt2.generate(sess)
gpt2.generate(sess, prefix='Obama shook Trump\'s hand.')
!rm -rf sample_data<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12321232123212321, 'fraction_numerical': 0.0187018701870187, 'mean_word_length': 4.170454545454546, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '518125', 'license': 'CC0-1.0', 'n_tokens_mistral': 354, 'n_tokens_neox': 343, 'n_words': 66, 'path': 'GPT2_fine_tuning.ipynb', 'repo_name': 'szentsas/Re-BiasedNews', 'size': '909'}