1

我是 NLP 和 Keras 的新手,仍在学习。

我尝试遵循本指南:https ://blog.keras.io/a-ten-minute-introduction-to-sequence-to-sequence-learning-in-keras.html并添加了嵌入层。我正在使用 fra2eng 数据集。

但是,我不确定我的推理模型和输出代码的生成是否正确。基本上,我的解码器输入是输入到我的推理模型中的索引(单个数字)数组。

我不太确定这是否正确。如果需要更多背景信息或代码,请告诉我。

input_seq 是词汇表中单词的索引数组。

array([36., 64., 57.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,
        0.,  0.,  0.], dtype=float32)

0 是我的起始标记索引,所以我的第一个目标序列是 np.array([0]) --> 不确定它是否正确

def decode_sequence(input_seq):
    # Encode the input as state vectors.
    states_value = encoder_model.predict(input_seq)
    target_seq = np.array([0])
    stop_condition = False
    decoded_sentence = ''
    while not stop_condition:
        output_tokens, h, c = decoder_model.predict([target_seq] + states_value)
        sampled_token_index = np.argmax(output_tokens[0, -1, :])
        sampled_char = target_idx2char[sampled_token_index]
        decoded_sentence += sampled_char
        if (sampled_char == '\n' or len(decoded_sentence) > 20):
            stop_condition = True
            # Update the target sequence (of length 1).
        target_seq = np.array([sampled_token_index])
            # Update states
        states_value = [h, c]
    return decoded_sentence

这是我的输出,想知道输出是否是由于上述任何错误。

Input sentence: Go.
Decoded sentence: tréjous?!

-
Input sentence: Run!
Decoded sentence: ï

-
Input sentence: Run!
Decoded sentence: ï

-
Input sentence: Wow!
Decoded sentence: u te les fois.

-
Input sentence: Fire!
Decoded sentence: ïï

-
Input sentence: Help!
Decoded sentence: ez joi de l'argent.

4

0 回答 0