[英]Importing the Attention package in Keras gives ModuleNotFoundError: No module named 'attention'
As part of my imports, I am importing the AttentionLayer package as follows:作为导入的一部分,我将按如下方式导入 AttentionLayer 包:
from attention import AttentionLayer
I get the following error:我收到以下错误:
ModuleNotFoundError: No module named 'attention'
I figured this might be because I need to pip install it so I tried based on other answers I found online a few pip installs I tried were:我想这可能是因为我需要 pip install 它所以我根据我在网上找到的其他答案进行了尝试,我尝试过的一些 pip 安装是:
pip install AttentionLayer
pip install Attention
pip install keras-self-attention
All 3 of those give me:所有这三个都给了我:
Could not find a version that satisfies the requirement keras-self-attention (from versions: ) No Matching distribution found for....
Why am I not getting it to work and how can I fix it?为什么我不能让它工作,我该如何解决?
I have a suspicion that it might be related to setting the pythonpath but I do not have admin rights to edit this at work.我怀疑它可能与设置 pythonpath 相关,但我没有在工作中编辑它的管理员权限。
Thank you.谢谢你。
try using the name keras-attention
:尝试使用名称
keras-attention
:
pip install keras-attention
you can search pip for packages like this:你可以在 pip 中搜索这样的包:
pip search attention
keras-attention (1.0.0) - Attention Mechanism Implementations for NLP via Keras
.
.
.
(other stuff)
Try this:尝试这个:
Install keras-self-attention: pip install keras-self-attention
安装 keras-self-attention:
pip install keras-self-attention
Import SeqSelfAttention: from keras_self_attention import SeqSelfAttention
导入 SeqSelfAttention:
from keras_self_attention import SeqSelfAttention
It worked for me!它对我有用!
我正在 google collab 上工作,此代码在 2021 年 2 月对我有用 pip install keras-self-attention
It's because You didn't have attention module, go to this link https://github.com/thushv89/attention_keras/blob/master/layers/attention.py and use this attention module.这是因为你没有注意力模块,去这个链接https://github.com/thushv89/attention_keras/blob/master/layers/attention.py并使用这个注意力模块。 Regards.
问候。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.