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

AttributeError: module 'keras.backend' has no attribute 'identity' #2

Open
souryarazorthink opened this issue Dec 6, 2020 · 1 comment

Comments

@souryarazorthink
Copy link

souryarazorthink commented Dec 6, 2020

import os
from keras_ernie import load_from_checkpoint

ernie_path = ""
init_checkpoint = os.path.join(ernie_path, 'params')
ernie_config_path = os.path.join(ernie_path, 'ernie_config.json')
ernie_vocab_path = os.path.join(ernie_path, 'vocab.txt')
ernie_version = "Base_en_stable-2.0.0"

model = load_from_checkpoint(init_checkpoint, ernie_config_path, ernie_vocab_path, ernie_version,
            max_seq_len=128, num_labels=2, use_fp16=False, training=False, seq_len=None, name='ernie')
model.summary()

i am getting this error.

2020-12-06 23:41:52,113-INFO: Load pretraining parameters from params.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-13-8c36d4235214> in <module>
      9 
     10 model = load_from_checkpoint(init_checkpoint, ernie_config_path, ernie_vocab_path, ernie_version,
---> 11             max_seq_len=128, num_labels=2, use_fp16=False, training=False, seq_len=None, name='ernie')
     12 model.summary()

~/.local/lib/python3.7/site-packages/keras_ernie/loader.py in load_from_checkpoint(init_checkpoint, ernie_config_path, ernie_vocab_path, ernie_version, max_seq_len, num_labels, use_fp16, training, seq_len, name)
     47 
     48     model = load_trained_model_from_checkpoint(
---> 49             bert_config_path, bert_checkpoint_path, training=training, seq_len=seq_len)
     50 
     51     model.name = name

~/.local/lib/python3.7/site-packages/keras_bert/loader.py in load_trained_model_from_checkpoint(config_file, checkpoint_file, training, trainable, output_layer_num, seq_len, **kwargs)
    167         output_layer_num=output_layer_num,
    168         seq_len=seq_len,
--> 169         **kwargs)
    170     load_model_weights_from_checkpoint(model, config, checkpoint_file, training=training)
    171     return model

~/.local/lib/python3.7/site-packages/keras_bert/loader.py in build_model_from_config(config_file, training, trainable, output_layer_num, seq_len, **kwargs)
     56         trainable=trainable,
     57         output_layer_num=output_layer_num,
---> 58         **kwargs)
     59     if not training:
     60         inputs, outputs = model

~/.local/lib/python3.7/site-packages/keras_bert/bert.py in get_model(token_num, pos_num, seq_len, embed_dim, transformer_num, head_num, feed_forward_dim, dropout_rate, attention_activation, feed_forward_activation, training, trainable, output_layer_num, use_task_embed, task_num, use_adapter, adapter_units)
     89         embed_dim=embed_dim,
     90         pos_num=pos_num,
---> 91         dropout_rate=dropout_rate,
     92     )
     93     if use_task_embed:

~/.local/lib/python3.7/site-packages/keras_bert/layers/embedding.py in get_embedding(inputs, token_num, pos_num, embed_dim, dropout_rate, trainable)
     38             trainable=trainable,
     39             name='Embedding-Token',
---> 40         )(inputs[0]),
     41         keras.layers.Embedding(
     42             input_dim=2,

~/.local/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
    924     if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
    925       return self._functional_construction_call(inputs, args, kwargs,
--> 926                                                 input_list)
    927 
    928     # Maintains info about the `Layer.call` stack.

~/.local/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
   1115           try:
   1116             with ops.enable_auto_cast_variables(self._compute_dtype_object):
-> 1117               outputs = call_fn(cast_inputs, *args, **kwargs)
   1118 
   1119           except errors.OperatorNotAllowedInGraphError as e:

~/.local/lib/python3.7/site-packages/tensorflow/python/autograph/impl/api.py in wrapper(*args, **kwargs)
    256       except Exception as e:  # pylint:disable=broad-except
    257         if hasattr(e, 'ag_error_metadata'):
--> 258           raise e.ag_error_metadata.to_exception(e)
    259         else:
    260           raise

AttributeError: in user code:

    /home/devops/.local/lib/python3.7/site-packages/keras_bert/layers/embedding.py:17 call  *
        return [super(TokenEmbedding, self).call(inputs), K.identity(self.embeddings)]

    AttributeError: module 'keras.backend' has no attribute 'identity'
@Kosisochi
Copy link

Hello, did you figure out what the issue is yet?

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

2 participants