Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: add_weight() got multiple values for argument 'name' #5

Open
ouening opened this issue Dec 16, 2019 · 3 comments
Open

TypeError: add_weight() got multiple values for argument 'name' #5

ouening opened this issue Dec 16, 2019 · 3 comments

Comments

@ouening
Copy link

ouening commented Dec 16, 2019

Attention类实现感觉有问题,本人使用TextBiRNN模型来跑,出现以下错误:

Traceback (most recent call last):
  File "train.py", line 86, in <module>
    last_activation='softmax').get_model()
  File "/media/gaoya/disk/Applications/keras/短文本分类/model.py", line 282, in get_model
    x_word = Attention(self.maxlen_word)(x_word)
  File "/media/gaoya/disk/Applications/anaconda3/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 75, in symbolic_fn_wrapper
    return func(*args, **kwargs)
  File "/media/gaoya/disk/Applications/anaconda3/lib/python3.7/site-packages/keras/engine/base_layer.py", line 463, in __call__
    self.build(unpack_singleton(input_shapes))
  File "/media/gaoya/disk/Applications/keras/短文本分类/model.py", line 231, in build
    constraint=self.b_constraint)
TypeError: add_weight() got multiple values for argument 'name'

请问怎么解决呢

@ShawnyXiao
Copy link
Owner

这可能是 Keras 升级了 API 导致的,你可以查一下最新的 API,相应的修改一下参数即可

@zhouzuguang
Copy link

Attention类实现感觉有问题,本人使用TextBiRNN模型来跑,出现以下错误:

Traceback (most recent call last):
File "train.py", line 86, in
last_activation='softmax').get_model()
File "/media/gaoya/disk/Applications/keras/短文本分类/model.py", line 282, in get_model
x_word = Attention(self.maxlen_word)(x_word)
File "/media/gaoya/disk/Applications/anaconda3/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 75, in symbolic_fn_wrapper
return func(*args, **kwargs)
File "/media/gaoya/disk/Applications/anaconda3/lib/python3.7/site-packages/keras/engine/base_layer.py", line 463, in call
self.build(unpack_singleton(input_shapes))
File "/media/gaoya/disk/Applications/keras/短文本分类/model.py", line 231, in build
constraint=self.b_constraint)
TypeError: add_weight() got multiple values for argument 'name'
请问怎么解决呢

self.W = self.add_weight(shape=(input_shape[-1], input_shape[-1],),
initializer=self.init,
name='{}_W'.format(self.name),
regularizer=self.W_regularizer,
constraint=self.W_constraint)
if self.bias:
self.b = self.add_weight(shape=(input_shape[-1],),
initializer='zero',
name='{}_b'.format(self.name),
regularizer=self.b_regularizer,
constraint=self.b_constraint)
第一个参数加上shape =

@Trevor4Y
Copy link

请问我试着输出了attention中与x相乘的那个a的值,但发现权值是我序列长度的平均只。比如我的输入每句话有23个词,然后每个权值都是1/23。。请问有遇到过类似的情况吗,或者这样的情况的原因可能是什么呢。。刚入门。。求解答,谢谢大佬~

@github-staff github-staff deleted a comment from hfzi May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants