
<SYSTEM_TASK:>
Given the following text problem statement, write Python code to implement the functionality described below in problem statement
<END_TASK>
<USER_TASK:>
Problem:
write a code on how to use pretrained gpt2 on custom data

<ASSISTANT_TASK:>
Python Code::
import numpy as np
import gpt_2_simple as gpt2
from datetime import datetime
from google.colab import files
from tensorflow.python.framework import ops
gpt2.download_gpt2(model_name="124M")
from transformers import GPT2Tokenizer
tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
sess = gpt2.start_tf_sess()
gpt2.finetune(sess, dataset= file_name, model_name=model_size, steps=200, restore_from='fresh',run_name = run_name,print_every=10,sample_every=50,save_every=50,learning_rate=0.0007)
ops.reset_default_graph()
sess = gpt2.start_tf_sess()
gpt2.load_gpt2(sess, run_name=run_name)
gpt2.generate(sess, run_name=run_name, temperature=.7, length=100, prefix=None, top_k=40, nsamples=10)

<END_TASK>
