Hironsan / anago

Bidirectional LSTM-CRF and ELMo for Named-Entity Recognition, Part-of-Speech Tagging and so on.
https://anago.herokuapp.com/
MIT License
1.48k stars 368 forks source link

model.fit() got error "TypeError: add_weight() got multiple values for argument 'name'" #120

Open pnovenaa opened 5 years ago

pnovenaa commented 5 years ago

I'm using anago 1.0.8 on jupyter notebook got this error

`--------------------------------------------------------------------------- TypeError Traceback (most recent call last)

in ----> 1 model.fit(x_train, y_train, epochs=15) /home/xxx/.conda/envs/xxx/lib/python3.7/site-packages/anago/wrapper.py in fit(self, x_train, y_train, x_valid, y_valid, epochs, batch_size, verbose, callbacks, shuffle) 78 use_char=self.use_char, 79 use_crf=self.use_crf) ---> 80 model, loss = model.build() 81 model.compile(loss=loss, optimizer=self.optimizer) 82 /home/xxx/.conda/envs/xxx/lib/python3.7/site-packages/anago/models.py in build(self) 113 crf = CRF(self._num_labels, sparse_target=False) 114 loss = crf.loss_function --> 115 pred = crf(z) 116 else: 117 loss = 'categorical_crossentropy' /home/xxx/.conda/envs/xxx/lib/python3.7/site-packages/keras/engine/base_layer.py in __call__(self, inputs, **kwargs) 461 'You can build it manually via: ' 462 '`layer.build(batch_input_shape)`') --> 463 self.build(unpack_singleton(input_shapes)) 464 self.built = True 465 /home/xxx/.conda/envs/xxx/lib/python3.7/site-packages/anago/layers.py in build(self, input_shape) 180 initializer=self.kernel_initializer, 181 regularizer=self.kernel_regularizer, --> 182 constraint=self.kernel_constraint) 183 self.chain_kernel = self.add_weight((self.units, self.units), 184 name='chain_kernel', TypeError: add_weight() got multiple values for argument 'name' `
G-bgyl commented 5 years ago

Met the same problem.

Update-- Able to detect the issue. It is because the use of new version of Keras. The requirements for anago is keras 2.2.0.

Solution-- Try to create a new virtual environment and install the Anago requirements.txt .

And btw, Torch is not compatible with windows, so if you are on a windows system, try to forget about the last required package allennlp, which needs torch as dependency. (Delete it from the requirements.txt is what I did).