'Generate.
Generate a sequence. Temperature is controlling the novelty of
the created sequence, a temperature near 0 will looks like samples
used for training, while the higher the temperature, the more novelty.
For optimal results, it is suggested to set sequence seed as some
random sequence samples from training dataset.
Arguments:
seq_length: `int`. The generated sequence length.
temperature: `float`. Novelty rate.
seq_seed: `sequence`. A sequence used as a seed to generate a
new sequence. Suggested to be a sequence from data used for
training.
display: `bool`. If True, print sequence as it is generated.
Returns:
The generated sequence.'

def generate(self, seq_length, temperature=0.5, seq_seed=None, display=False):

    generated = seq_seed[:]
    sequence = seq_seed[:]
    whole_sequence = seq_seed[:]
    if display:
        sys.stdout.write(str(generated))
    for i in range(seq_length):
        x = np.zeros((1, self.seq_maxlen, len(self.dic)))
        for (t, char) in enumerate(sequence):
            x[(0, t, self.dic[char])] = 1.0
        preds = self._predict(x)[0].tolist()
        next_index = _sample(preds, temperature)
        next_char = self.rev_dic[next_index]
        try:
            unicode_or_str = [str, unicode]
        except:
            unicode_or_str = [str]
        if (type(sequence) in unicode_or_str):
            generated += next_char
            sequence = (sequence[1:] + next_char)
            whole_sequence += next_char
        else:
            generated.append(next_char)
            sequence = sequence[1:]
            sequence.append(next_char)
            whole_sequence.append(next_char)
        if display:
            sys.stdout.write(str(next_char))
            sys.stdout.flush()
    if display:
        print()
    return whole_sequence
