Skip to content

error at keras/examples/pretrained_word_embeddings.py #10718

Closed
@DaPenggg

Description

@DaPenggg

HI ,ALL
when I run keras/examples/pretrained_word_embeddings.py, it is ok. But,if i save this model like:
model.save('my_model.h5')
then I create a new py script and load model:
model = keras.models.load_model('my_model.h5')
a error raise: Invalid type for initial value: <class 'dict'>(expected python scalar,list or tuple of values or numpy )

the solution is that:
embedding_layer = Embedding(num_words,
EMBEDDING_DIM,
embeddings_initializer=Constant(embedding_matrix.tolist()),
input_length=MAX_SEQUENCE_LENGTH,
trainable=False)

modify Constant(embedding_matrix) to be Constant(embedding_matrix.tolist())
after that ,the model can be saved and reload.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions