Comments (6)
@veqtor I was not able to save the model until I wrote my own get_config.py function in the BertLayer class. Adding this code to the class made it run for me:
'''
def get_config(self):
config = super(BertLayer, self).get_config().copy()
config.update({
'n_fine_tune_layers': self.n_fine_tune_layers,
# 'trainable': self.trainable,
# 'output_size': self.output_size,
'pooling': self.pooling,
'bert_path': self.bert_path,
})
return config
'''
from keras-bert.
Did you try to run the following code instead?
tf.keras.models.save_model( model, 'model', overwrite=True, include_optimizer=True )
from keras-bert.
I can't load the model:
model.save('/Documents/BERT/Sentiment_Classification_model_smallsiwetest.h5', overwrite=True, include_optimizer=True )
new_model = keras.models.load_model('Sentiment_Classification_model_smallsiwetest.h5')
Traceback (most recent call last):
File "", line 1, in
new_model = keras.models.load_model('Sentiment_Classification_model_smallsiwetest.h5')
File "/lib/miniconda/envs/conda-venv/lib/python3.6/site-packages/keras/engine/saving.py", line 453, in load_wrapper
return load_function(*args, **kwargs)
File "/lib/miniconda/envs/conda-venv/lib/python3.6/site-packages/keras/engine/saving.py", line 545, in load_model
model = _deserialize_model(h5dict, custom_objects, compile)
File "/lib/miniconda/envs/conda-venv/lib/python3.6/site-packages/keras/engine/saving.py", line 243, in _deserialize_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "/lib/miniconda/envs/conda-venv/lib/python3.6/site-packages/keras/engine/saving.py", line 588, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "/lib/miniconda/envs/conda-venv/lib/python3.6/site-packages/keras/layers/init.py", line 168, in deserialize
printable_module_name='layer')
File "/lib/miniconda/envs/conda-venv/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 147, in deserialize_keras_object
list(custom_objects.items())))
File "/lib/miniconda/envs/conda-venv/lib/python3.6/site-packages/keras/engine/network.py", line 1043, in from_config
process_layer(layer_data)
File "/lib/miniconda/envs/conda-venv/lib/python3.6/site-packages/keras/engine/network.py", line 1029, in process_layer
custom_objects=custom_objects)
File "/lib/miniconda/envs/conda-venv/lib/python3.6/site-packages/keras/layers/init.py", line 168, in deserialize
printable_module_name='layer')
File "/lib/miniconda/envs/conda-venv/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 140, in deserialize_keras_object
': ' + class_name)
ValueError: Unknown layer: BertLayer
from keras-bert.
@JiahuiSophieHU have you tried instantiating the BertLayer
class and then including it as a custom_object
argument?
new_model = keras.models.load_model('Sentiment_Classification_model_smallsiwetest.h5',
custom_objects={'BertLayer': BertLayer})
from keras-bert.
@JiahuiSophieHU have you tried instantiating the
BertLayer
class and then including it as acustom_object
argument?new_model = keras.models.load_model('Sentiment_Classification_model_smallsiwetest.h5', custom_objects={'BertLayer': BertLayer})
I am facing a similar situation, not being able to load the saved model.
@smfullman tried this, but I am getting an error saying 'Shapes (768,) and (512, 768) are incompatible'.
from keras-bert.
@devinharia I am facing the same problem. Did you get the solution?
from keras-bert.
Related Issues (20)
- Unable to run the code in Google Colaboratory HOT 1
- Unable to run initialise training
- ModuleNotFoundError: No module named 'bert' HOT 3
- No pooling embeddings HOT 3
- How to re-use the keras-bert implementation for question answering task?
- AttributeError: module 'tensorflow_hub.tf_v1' has no attribute 'estimator' HOT 1
- Text classification (keras_text): 'Node' object has no attribute 'output_masks' HOT 2
- Nested tensor dimensions HOT 1
- FailedPreconditionError
- Error when calling model = build_model(max_seq_length) HOT 1
- failed prediction error. HOT 1
- AttributeError: 'Module' object has no attribute 'variables'
- Bert Embeddings Layer for Word Sense Disambiguation task
- Project doesn't have have requirements.txt
- NotImplementedError: Layers with arguments in `__init__` must override `get_config`. HOT 1
- Use the "[CLS]" instead of pooled result?
- Is output shape incorrect? HOT 1
- NotImplementedError: Layers with arguments in `__init__` must override `get_config`. HOT 1
- 'AutoTrackable' object is not callable
- INVALID: Not observing the same accuracy reported when reproducing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from keras-bert.