Exemplo n.º 1
0
    hidden_dim = 100
    ae = AutoEncoder(max_sequence_len, vocab.NumIds(), embedding_dim,
                     hidden_dim)
    ae.build_models()
    reducelr_cb = ReduceLROnPlateau(monitor='val_loss',
                                    factor=0.5,
                                    patience=10,
                                    verbose=1,
                                    mode='auto',
                                    epsilon=0.0001,
                                    cooldown=0,
                                    min_lr=1e-20)
    checkpoint_cb = ModelCheckpoint(model_weights, period=1)
    earlystopping_cb = EarlyStopping(min_delta=0.0001, patience=10)
    callbacks_list = [reducelr_cb, checkpoint_cb, earlystopping_cb]
    x = p.get_data()[:5000]
    print(len(x))
    print('-' * 30, 'Loaded data', '-' * 30)
    ae.train(x, batch_size, num_epochs=30, callbacks_list=callbacks_list)

    # AutoEncoder.save(ae, model_params, model_file, model_weights)
    # ae = AutoEncoder.load(model_params, model_file, model_weights)
    data = p.process_sentences([
        'malignant melanoma is now the fifth most common cancer .',
        'the babies are conjoined from the chest to the navel.',
        'experts believe the rapidly rising rate in older people.'
    ])
    print(data)
    prediction = ae.predict(data)
    sentences = predict_sentences(prediction, vocab)
    for s in sentences: