简体   繁体   English

在 Keras 中导入 Attention 包会出现 ModuleNotFoundError: No module named 'attention'

[英]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:尝试这个:

  1. Install keras-self-attention: pip install keras-self-attention安装 keras-self-attention: pip install keras-self-attention

  2. 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.

相关问题 在Google Colab中针对“注意ocr”修复“ ModuleNotFoundError:没有名为&#39;fsns&#39;的模块” - Fix “ModuleNotFoundError: No module named 'fsns'” in google colab for Attention ocr 如何使用 keras-self-attention package 可视化注意力 LSTM? - How visualize attention LSTM using keras-self-attention package? 导入 keras ModuleNotFoundError 时出错:没有名为“tensorflow.examples”的模块; &#39;tensorflow&#39; 不是一个包 - error while importing keras ModuleNotFoundError: No module named 'tensorflow.examples'; 'tensorflow' is not a package ModuleNotFoundError:没有名为“keras”的模块 - ModuleNotFoundError: No module named 'keras' ModuleNotFoundError:没有名为 keras 的模块 - ModuleNotFoundError: No module named keras ModuleNotFoundError :没有名为“keras”的模块? - ModuleNotFoundError : No module named 'keras'? 在 Keras 中实现注意力机制 - Implementing Attention in Keras LSTM 层之后的自定义注意力层在 Keras 中给出 ValueError - Custom attention layer after LSTM layer gives ValueError in Keras ModuleNotFoundError: 没有名为“的模块”<package> &#39; - ModuleNotFoundError: No module named '<package>' 在项目中安装 package 给出 ModuleNotFoundError: No module named 'requests' - installed package in project gives ModuleNotFoundError: No module named 'requests'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM