keras
keras copied to clipboard
Input_length keyword parameter in the Embedding Layer of Keras 3
In this Keras 2 doc page, there is a keyword parameter named 'input_length', which is not the case for the Keras 3 doc page in the below image.
However, the example shown below that function definition of Keras 3 also shows an argument 'input_length', maybe this is a problem.
The link for the Keras 2 documentation page: https://keras.io/2.15/api/layers/core_layers/embedding/ and Keras 3 documentation page: https://keras.io/api/layers/core_layers/embedding/
Also, since the new Keras 3 Embedding class has no 'input_length' parameter, I am having a problem trying to use a Keras 2-trained model with Keras 3. Can anyone help? Thank you so much.
Hi @longsc2603 ,
In Keras2 implementation either you can provide sequence length to input_length parameter or you can pass input_shape as kwargs. If both provided input_shape will be considered by the API.
In Keras3 implementation the parameter input_length is removed as it is redundant as you can use input_shape as kwarg. Even if you won't provide input_shape the API can infer it from the input being passed to model.
Please refer the attached gist for demo.
Hope it helps. Thanks!
I seem to have passed that problem, since you are already here, could you help me solve another problem related to keras 3 and tf 2?
I got a part of the code below that is not working properly, the error is shown below
I searched online and come to think that this maybe due to tensorflow graph as defined below
The part of the code that is showing error:
I don't know how exactly to overcome this, many suggestions were for Keras 2 and I am using Keras 3, can you help? Thank you
Hi @longsc2603 ,
If you are using TF1.x graph then I afraid we are not supporting it anymore. You need to migrate to TF2.x style coding which is compatible with Keras3. Thanks!
@SuryanarayanaY, can you please elaborate on how I could do that effectively, I'm not very familiar with the Tensorflow coding style. If you could give a complete tutorial link, that is also okay. Thanks
Hi @longsc2603 ,
There are lot of guides for migrating from TF1.x to TF2.x. Please refer the guides here at migrate to Tf2.x.
I recommend to stick to keras2 only by setting the environment variable TF_USE_LEGACY_KERAS=1 as the migration is for TF2.x(i.e Keras2) and not sure compatibility with Keras3.
This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.
This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.
Hi @longsc2603 ,
In Keras2 implementation either you can provide sequence length to
input_lengthparameter or you can passinput_shapeas kwargs. If both provided input_shape will be considered by the API.In Keras3 implementation the parameter
input_lengthis removed as it is redundant as you can useinput_shapeas kwarg. Even if you won't provideinput_shapethe API can infer it from the input being passed to model.Please refer the attached gist for demo.
Hope it helps. Thanks!
I think this works..