我在推理模型中是否正确应用了seq2seq中的嵌入层?

2024-04-19 21:32:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我对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.数组([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.


Tags: targetinputvaluenp数组arrayseqsentence