Ejemplo n.º 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)
Ejemplo n.º 3
0
    # TODO: Implement Function
    train_decoder = tf.contrib.seq2seq.simple_decoder_fn_train(encoder_state)
    train_pred, _, _ = tf.contrib.seq2seq.dynamic_rnn_decoder(
        dec_cell,
        train_decoder,
        dec_embed_input,
        sequence_length,
        scope=decoding_scope)
    train_logits = output_fn(train_pred)
    return train_logits


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

# ### 解码 - 推论
#
# 使用 [`tf.contrib.seq2seq.simple_decoder_fn_inference()`](https://www.tensorflow.org/versions/r1.0/api_docs/python/tf/contrib/seq2seq/simple_decoder_fn_inference) 和 [`tf.contrib.seq2seq.dynamic_rnn_decoder()`](https://www.tensorflow.org/versions/r1.0/api_docs/python/tf/contrib/seq2seq/dynamic_rnn_decoder) 创建推论分对数(inference logits)。

# In[11]:


def decoding_layer_infer(encoder_state, dec_cell, dec_embeddings,
                         start_of_sequence_id, end_of_sequence_id,
                         maximum_length, vocab_size, decoding_scope, output_fn,
                         keep_prob):
    """
    Create a decoding layer for inference
    :param encoder_state: Encoder state