Giter Site home page Giter Site logo

Comments (6)

connormeaton avatar connormeaton commented on August 15, 2024 1

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

AxeldeRomblay avatar AxeldeRomblay commented on August 15, 2024

Did you try to run the following code instead?

tf.keras.models.save_model( model, 'model', overwrite=True, include_optimizer=True )

from keras-bert.

JiahuiSophieHU avatar JiahuiSophieHU commented on August 15, 2024

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.

smfullman avatar smfullman commented on August 15, 2024

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

devinharia avatar devinharia commented on August 15, 2024

@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})

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.

PradyumnaGupta avatar PradyumnaGupta commented on August 15, 2024

@devinharia I am facing the same problem. Did you get the solution?

from keras-bert.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.