问题描述
我正在研究机器语言翻译问题。我正在使用的模型是:
($username and $password are just sanitized before including them in the query)
在这里,$MyGeneralDB->query("SELECT TOP 1 Status FROM Accounts WHERE ID = '$username' AND Pwd = dbo.HashPasswordString('$password')");
和 Model = Sequential([
Embedding(english_vocab_size,256,input_length=english_max_len,mask_zero=True),LSTM(256,activation='relu'),RepeatVector(german_max_len),activation='relu',return_sequences=True),Dense(german_vocab_size,activation='softmax')
])
分别是英语词汇中英语单词的总数和每个英语句子中单词的数量。 english_vocab_size
和english_max_len
也是如此。
现在,如何在此模型中添加german_vocab_size
层?
编辑-我做了很多尝试,以找到在nlp任务上实现german_max_len
层的良好教程,但找不到任何教程。因此,我认为,如果有人可以解释如何将tf.keras.layers.AdditiveAttention
放在该模型中,那么该人将是第一个对如何使用tf.keras.layers.AdditiveAttention
进行非常清晰的解释的人,然后关于如何使用tf.keras.layers.AdditiveAttention
层的非常清晰的实现!
解决方法
这将通过上一个链接为您提供帮助
How to build a attention model with keras?
context_vector,attention_weights = Attention(32)(lstm,state_h)
或
这是使用Luong风格的注意力的方法:
attention = tf.keras.layers.Attention()([query,value])
还有Bahdanau风格的关注:
attention = tf.keras.layers.AdditiveAttention()([query,value])
改编版本:
weights = tf.keras.layers.Attention()([lstm,state_h])