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: Error when deserializing class 'Embedding' using config #93

Open
jmalhot opened this issue Mar 11, 2024 · 3 comments
Open

TypeError: Error when deserializing class 'Embedding' using config #93

jmalhot opened this issue Mar 11, 2024 · 3 comments

Comments

@jmalhot
Copy link

jmalhot commented Mar 11, 2024

All of sudden today, I started getting following error while using ethnicolr.pred_fl_reg_ln (version 0.9.6)

Error Category: UNCLASSIFIED_ERROR; TypeError: Error when deserializing class 'Embedding' using config={'name': 'embedding', 'trainable': True, 'dtype': 'float32', 'input_dim': 1152, 'output_dim': 32, 'embeddings_initializer': {'class_name': 'RandomUniform', 'config': {'minval': -0.05, 'maxval': 0.05, 'seed': None}}, 'embeddings_regularizer': None, 'activity_regularizer': None, 'embeddings_constraint': None, 'mask_zero': False, 'input_length': 20, 'input_shape': [None, 20]}.

I was able to work with no issues last week. Has anything changed in the source code recently ?

@soodoku
Copy link
Member

soodoku commented Mar 11, 2024 via email

@jmalhot
Copy link
Author

jmalhot commented Mar 11, 2024

Thanks for your quick response. Following are the steps to reproduce the issue:-

##Create a new python vitual env
python -m venv ethnicolr_testing

##Activate virtual envrionment
source ethnicolr_testing/bin/activate

##Install ethnicolr
pip install ethnicolr==0.9.6

##Run the python script

import pandas as pd
from ethnicolr import (pred_fl_reg_ln)
 data = {
    'Name': ['Yan Lee', 
             'Mohammad Khan'
             ]
}
df = pd.DataFrame(data)
odf = pred_fl_reg_ln(df, 'Name', num_iter=100, conf_int=0.9)
print(odf)

##Following is the error returned


Traceback (most recent call last):
  File "/Users/user/Downloads/ethnicolr_testing/lib/python3.9/site-packages/keras/src/ops/operation.py", line 196, in from_config
    return cls(**config)
  File "/Users/user/Downloads/ethnicolr_testing/lib/python3.9/site-packages/keras/src/layers/core/embedding.py", line 81, in __init__
    super().__init__(**kwargs)
  File "/Users/user/Downloads/ethnicolr_testing/lib/python3.9/site-packages/keras/src/layers/layer.py", line 265, in __init__
    raise ValueError(
ValueError: Unrecognized keyword arguments passed to Embedding: {'input_length': 20}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/Downloads/test.py", line 18, in <module>
    odf = pred_fl_reg_ln(df, 'Name', num_iter=100, conf_int=0.9)
  File "/Users/user/Downloads/ethnicolr_testing/lib/python3.9/site-packages/ethnicolr/pred_fl_reg_ln.py", line 42, in pred_fl_reg_ln
    rdf = cls.transform_and_pred(df=df,
  File "/Users/user/Downloads/ethnicolr_testing/lib/python3.9/site-packages/ethnicolr/ethnicolr_class.py", line 108, in transform_and_pred
    cls.model = load_model(MODEL)
  File "/Users/user/Downloads/ethnicolr_testing/lib/python3.9/site-packages/keras/src/saving/saving_api.py", line 183, in load_model
    return legacy_h5_format.load_model_from_hdf5(filepath)
  File "/Users/user/Downloads/ethnicolr_testing/lib/python3.9/site-packages/keras/src/legacy/saving/legacy_h5_format.py", line 133, in load_model_from_hdf5
    model = saving_utils.model_from_config(
  File "/Users/user/Downloads/ethnicolr_testing/lib/python3.9/site-packages/keras/src/legacy/saving/saving_utils.py", line 85, in model_from_config
    return serialization.deserialize_keras_object(
  File "/Users/user/Downloads/ethnicolr_testing/lib/python3.9/site-packages/keras/src/legacy/saving/serialization.py", line 495, in deserialize_keras_object
    deserialized_obj = cls.from_config(
  File "/Users/user/Downloads/ethnicolr_testing/lib/python3.9/site-packages/keras/src/models/sequential.py", line 327, in from_config
    layer = saving_utils.model_from_config(
  File "/Users/user/Downloads/ethnicolr_testing/lib/python3.9/site-packages/keras/src/legacy/saving/saving_utils.py", line 85, in model_from_config
    return serialization.deserialize_keras_object(
  File "/Users/user/Downloads/ethnicolr_testing/lib/python3.9/site-packages/keras/src/legacy/saving/serialization.py", line 504, in deserialize_keras_object
    deserialized_obj = cls.from_config(cls_config)
  File "/Users/user/Downloads/ethnicolr_testing/lib/python3.9/site-packages/keras/src/ops/operation.py", line 198, in from_config
    raise TypeError(
TypeError: Error when deserializing class 'Embedding' using config={'name': 'embedding', 'trainable': True, 'dtype': 'float32', 'input_dim': 1152, 'output_dim': 32, 'embeddings_initializer': {'class_name': 'RandomUniform', 'config': {'minval': -0.05, 'maxval': 0.05, 'seed': None}}, 'embeddings_regularizer': None, 'activity_regularizer': None, 'embeddings_constraint': None, 'mask_zero': False, 'input_length': 20, 'input_shape': [None, 20]}.

Exception encountered: Unrecognized keyword arguments passed to Embedding: {'input_length': 20}
(ethnicolr_testing) bash-3.2$ 


@jmalhot
Copy link
Author

jmalhot commented Mar 18, 2024

Issue is Fixed:
pip install ethnicolr==0.9.6 by default was installing tensorflow 2.16.x which is incompatible with ethnicolr==0.9.6. Comptaible version is tensorflow version is 2.15.0

Please update the documentation

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