generator.py
def generate_text(desiredTextLength, int2charDict, vocabulary, seed, model):
    """Generates text based on the learned text
    """
    print('Starting Text-Generation Phase...')
    start = datetime.datetime.now()
    text = ""
    # Predict the next chars starting from the seed
    for i in range(desiredTextLength):
        x = numpy.reshape(seed, (1, len(seed), 1))
        x = x / float(len(vocabulary))
        prediction = model.predict(x, verbose=1)
        # Find the prediction with the highest probability
        predictedIndex = numpy.argmax(prediction)
        predictedChar = int2charDict[predictedIndex]
        text += str(predictedChar)
        # Append the new predicted char to the seed and repredict the following sequence
        seed.append(predictedIndex)
        # Move the window by one character
        seed = seed[1:len(seed)]

    end = datetime.datetime.now()
    deltaTime = end-start
    print('Generation finished: %ds' % deltaTime.total_seconds())
    return text
Generates text based on the learned text
    
Generates text based on the learned text
Generates text based on the learned text
def generate_text(desiredTextLength, int2charDict, vocabulary, seed, model):
    print('Starting Text-Generation Phase...')
    start = datetime.datetime.now()
    text = ""
    for i in range(desiredTextLength):
        x = numpy.reshape(seed, (1, len(seed), 1))
        x = x / float(len(vocabulary))
        prediction = model.predict(x, verbose=1)
        predictedIndex = numpy.argmax(prediction)
        predictedChar = int2charDict[predictedIndex]
        text += str(predictedChar)
        seed.append(predictedIndex)
        seed = seed[1:len(seed)]
    end = datetime.datetime.now()
    deltaTime = end-start
    print('Generation finished: %ds' % deltaTime.total_seconds())
    return text
def generate_text ( desiredTextLength , int2charDict , vocabulary , seed , model ) : print ( 'Starting Text-Generation Phase...' ) start = datetime . datetime . now ( ) text = "" for i in range ( desiredTextLength ) : x = numpy . reshape ( seed , ( 1 , len ( seed ) , 1 ) ) x = x / float ( len ( vocabulary ) ) prediction = model . predict ( x , verbose = 1 ) predictedIndex = numpy . argmax ( prediction ) predictedChar = int2charDict [ predictedIndex ] text += str ( predictedChar ) seed . append ( predictedIndex ) seed = seed [ 1 : len ( seed ) ] end = datetime . datetime . now ( ) deltaTime = end - start print ( 'Generation finished: %ds' % deltaTime . total_seconds ( ) ) return text
Generates text based on the learned text
Generates text based on the learned text
"""Generates text based on the learned text
    """ # Predict the next chars starting from the seed # Find the prediction with the highest probability # Append the new predicted char to the seed and repredict the following sequence # Move the window by one character
desiredTextLength
int2charDict
vocabulary
seed
model