(self, num_out=200, prime=None, sample=True)
return gen_seq
Generate a sequence of text from the trained model.

        @param num_out: The length of the sequence to generate, in num words.
        @param prime: The priming sequence for generation. If None, pick a random word from the
                      vocabulary as prime.
        @param sample: Whether to probabalistically sample the next word, rather than take the word
                       of max probability.
Generate a sequence of text from the trained model.
Generate a sequence of text from the trained model .
def generate(self, num_out=200, prime=None, sample=True):
        """
        Generate a sequence of text from the trained model.

        @param num_out: The length of the sequence to generate, in num words.
        @param prime: The priming sequence for generation. If None, pick a random word from the
                      vocabulary as prime.
        @param sample: Whether to probabalistically sample the next word, rather than take the word
                       of max probability.
        """
        state = self.sess.run(self.cell.zero_state(1, tf.float32))

        # if no prime supplied, get a random word. Otherwise, translate all words in prime that
        # aren't in dictionary to '*UNK*'
        if prime is None:
            prime = np.random.choice(self.vocab)
        else:
            prime = unkify(prime, self.vocab)

        # prime the model state
        for word in prime.split():
            print word
            last_word_i = self.vocab.index(word)
            input_i = np.array([[last_word_i]])

            feed_dict = {self.inputs: input_i, self.initial_state: state}
            state = self.sess.run(self.final_state, feed_dict=feed_dict)

        # generate the sequence
        gen_seq = prime
        for i in xrange(num_out):
            # generate word probabilities
            input_i = np.array([[last_word_i]]) #TODO: use dictionary?
            feed_dict = {self.inputs: input_i, self.initial_state: state}
            probs, state = self.sess.run([self.probs, self.final_state], feed_dict=feed_dict)
            probs = probs[0]

            # select index of new word
            if sample:
                gen_word_i = np.random.choice(np.arange(len(probs)), p=probs)
            else:
                gen_word_i = np.argmax(probs)

            # append new word to the generated sequence
            gen_word = self.vocab[gen_word_i]
            gen_seq += ' ' + gen_word
            last_word_i = gen_word_i

        return gen_seq
def generate ( self , num_out = 200 , prime = None , sample = True ) : state = self . sess . run ( self . cell . zero_state ( 1 , tf . float32 ) ) # if no prime supplied, get a random word. Otherwise, translate all words in prime that # aren't in dictionary to '*UNK*' if prime is None : prime = np . random . choice ( self . vocab ) else : prime = unkify ( prime , self . vocab ) # prime the model state for word in prime . split ( ) : print word last_word_i = self . vocab . index ( word ) input_i = np . array ( [ [ last_word_i ] ] ) feed_dict = { self . inputs : input_i , self . initial_state : state } state = self . sess . run ( self . final_state , feed_dict = feed_dict ) # generate the sequence gen_seq = prime for i in xrange ( num_out ) : # generate word probabilities input_i = np . array ( [ [ last_word_i ] ] ) #TODO: use dictionary? feed_dict = { self . inputs : input_i , self . initial_state : state } probs , state = self . sess . run ( [ self . probs , self . final_state ] , feed_dict = feed_dict ) probs = probs [ 0 ] # select index of new word if sample : gen_word_i = np . random . choice ( np . arange ( len ( probs ) ) , p = probs ) else : gen_word_i = np . argmax ( probs ) # append new word to the generated sequence gen_word = self . vocab [ gen_word_i ] gen_seq += ' ' + gen_word last_word_i = gen_word_i return gen_seq