如何解决如何在模型中添加tf.keras.layers.AdditiveAttention?
我正在研究机器语言翻译问题。我正在使用的模型是:
($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])
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。