Beispiel #1
0
def run_tests():

    import problem_unittests as t

    t.test_decoding_layer(decoding_layer)
    t.test_decoding_layer_infer(decoding_layer_infer)
    t.test_decoding_layer_train(decoding_layer_train)
    t.test_encoding_layer(encoding_layer)
    t.test_model_inputs(model_inputs)
    t.test_process_encoding_input(process_decoder_input)
    t.test_sentence_to_seq(sentence_to_seq)
    t.test_seq2seq_model(seq2seq_model)
    t.test_text_to_ids(text_to_ids)
def run_all_tests():
    tests.test_text_to_ids(text_to_ids)

    check_tensorflow_gpu()
    tests.test_model_inputs(model_inputs)

    tests.test_process_encoding_input(process_decoder_input)

    from imp import reload
    reload(tests)
    tests.test_encoding_layer(encoding_layer)

    tests.test_decoding_layer_train(decoding_layer_train)
    tests.test_decoding_layer_infer(decoding_layer_infer)
    tests.test_decoding_layer(decoding_layer)
    tests.test_seq2seq_model(seq2seq_model)

    tests.test_sentence_to_seq(sentence_to_seq)
Beispiel #3
0
                                            keep_prob)

    with tf.variable_scope("decoding", reuse=True) as decoding_scope:
        start_of_sequence_id = target_vocab_to_int['<GO>']
        end_of_sequence_id = target_vocab_to_int['<EOS>']
        inference_logits = decoding_layer_infer(
            encoder_state, dec_cell, dec_embeddings, start_of_sequence_id,
            end_of_sequence_id, sequence_length - 1, vocab_size,
            decoding_scope, output_fn, keep_prob)
    return train_logits, inference_logits


"""
DON'T MODIFY ANYTHING IN THIS CELL THAT IS BELOW THIS LINE
"""
tests.test_decoding_layer(decoding_layer)

# ### 构建神经网络
#
# 应用你在上方实现的函数,以:
#
# - 向编码器的输入数据应用嵌入。
# - 使用 `encoding_layer(rnn_inputs, rnn_size, num_layers, keep_prob)` 编码输入。
# - 使用 `process_decoding_input(target_data, target_vocab_to_int, batch_size)` 函数处理目标数据。
# - 向解码器的目标数据应用嵌入。
# - 使用 `decoding_layer(dec_embed_input, dec_embeddings, encoder_state, vocab_size, sequence_length, rnn_size, num_layers, target_vocab_to_int, keep_prob)` 解码编码的输入数据。

# In[13]:


def seq2seq_model(input_data, target_data, keep_prob, batch_size,