(self, prefix=None,
                  file_data=True,
                  max_length=512,
                  do_sample=True,
                  top_k=50,
                  top_p=0.9,
                  temperature=0.3,
                  return_sequences=2)
return self.models['text_generation']
Takes in initial text and generates text with specified number of characters more using Top P sampling
    :param prefix: initial text to start with
    :param several parameters to hyperparemeterize with given defaults
    :return: complete generated text
Takes in initial text and generates text with specified number of characters more using Top P sampling
    :param prefix: initial text to start with
    :param several parameters to hyperparemeterize with given defaults
    :return: complete generated text
Takes in initial text and generates text with specified number of characters more using Top P sampling : param prefix : initial text to start with : param several parameters to hyperparemeterize with given defaults : return : complete generated text
def generate_text(self, prefix=None,
                  file_data=True,
                  max_length=512,
                  do_sample=True,
                  top_k=50,
                  top_p=0.9,
                  temperature=0.3,
                  return_sequences=2):
    '''
    Takes in initial text and generates text with specified number of characters more using Top P sampling
    :param prefix: initial text to start with
    :param several parameters to hyperparemeterize with given defaults
    :return: complete generated text
    '''

    if return_sequences < 1:
        raise Exception("return sequences number is less than 1 (need an integer of atleast 1)")

    if max_length < 1:
        raise Exception("Max text length must be equal to or greater than 1")

    with NoStdStreams():
        tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
        model = TFGPT2LMHeadModel.from_pretrained("gpt2", pad_token_id=tokenizer.eos_token_id)

    if file_data:
        f = open(self.dataset, "r")
        input_ids = tokenizer.encode(f.read(), return_tensors='tf', max_length=max_length - 1, truncation=True)
        f.close()
    else:
        input_ids = tokenizer.encode(prefix, return_tensors='tf', max_length=max_length - 1, truncation=True)

    logger("Generating text now...")
    tf.random.set_seed(0)
    output = model.generate(input_ids,
                            do_sample=do_sample,
                            max_length=max_length,
                            top_k=top_k, top_p=top_p,
                            temperature=temperature,
                            num_return_sequences=return_sequences)
    total_text = ""
    for i, sample_output in enumerate(output):
        value = "{}: {}".format(i, tokenizer.decode(sample_output, skip_special_tokens=True))
        total_text += value

    self.models['text_generation'] = {"generated_text": total_text}
    return self.models['text_generation']
def generate_text ( self , prefix = None , file_data = True , max_length = 512 , do_sample = True , top_k = 50 , top_p = 0.9 , temperature = 0.3 , return_sequences = 2 ) : if return_sequences < 1 : raise Exception ( "return sequences number is less than 1 (need an integer of atleast 1)" ) if max_length < 1 : raise Exception ( "Max text length must be equal to or greater than 1" ) with NoStdStreams ( ) : tokenizer = GPT2Tokenizer . from_pretrained ( "gpt2" ) model = TFGPT2LMHeadModel . from_pretrained ( "gpt2" , pad_token_id = tokenizer . eos_token_id ) if file_data : f = open ( self . dataset , "r" ) input_ids = tokenizer . encode ( f . read ( ) , return_tensors = 'tf' , max_length = max_length - 1 , truncation = True ) f . close ( ) else : input_ids = tokenizer . encode ( prefix , return_tensors = 'tf' , max_length = max_length - 1 , truncation = True ) logger ( "Generating text now..." ) tf . random . set_seed ( 0 ) output = model . generate ( input_ids , do_sample = do_sample , max_length = max_length , top_k = top_k , top_p = top_p , temperature = temperature , num_return_sequences = return_sequences ) total_text = "" for i , sample_output in enumerate ( output ) : value = "{}: {}" . format ( i , tokenizer . decode ( sample_output , skip_special_tokens = True ) ) total_text += value self . models [ 'text_generation' ] = { "generated_text" : total_text } return self . models [ 'text_generation' ]