Repository: keras-team/keras

Issue:
 Unrecognized 'input_length' keyword arguments passed to Embedding
I try to build embedding layer but it results in ValueError: Unrecognized keyword arguments passed to Embedding: {'input_length': 500}
```
inp_layer = tf.keras.layers.Input(shape=(INPUT_SIZE,))
mid_layers = tf.keras.layers.Embedding(input_dim = WORDS_SIZE,
                                    output_dim = 13,
                                    input_length = INPUT_SIZE,
                                    embeddings_initializer = tf.keras.initializers.Constant(random_weights))(inp_layer)
```

I use tf v2, then I search tf.keras.layers.Embedding API, here is its sample
```
tf.keras.layers.Embedding(
    input_dim,
    output_dim,
    embeddings_initializer='uniform',
    embeddings_regularizer=None,
    activity_regularizer=None,
    embeddings_constraint=None,
    mask_zero=False,
    input_length=None,
    sparse=False,
    **kwargs
)
```
why 'input_length' is still invalid


Discussion:
Hi @vinhpt01 ,
In Keras3 input_length  argument not exists. It seems you are using TF2.16 which comes with Keras3 package. From Tf2.16v onwards tf.keras refers to Keras3 packages only. Could you confirm which TF version you have installed?

If you want to use Keras2 version then you need to set the environment variable `TF_USE_LEGACY_KERAS=1`
I was going to write the same issue. I use tf 2.16.0rc0 and Keras 3.0.5 on a MacBook Pro m1. This was the only configuration able to converge when using the Adam optimiser.
I also tried the compatibility matrix options, but this is the only one working.

I see tf 2.16 is out
https://discuss.tensorflow.org/t/tensorflow-version-2-16-just-released/23140

and I will upgrade to that asap if useful, especially because I am in a dev version.

I was checking the master and tf2.15 branches 
https://github.com/keras-team/keras/blob/master/keras/layers/core/embedding.py

input_length is missing in the master branch in __init__. Still, you can find it in the docstring. See line 22 for reference.

I am also building a test model with the Embedding layer and for now it is working: update asap.

I was thinking and I would like to ask why this method is missing in the master branch and if could be useful to add it. Maybe I am missing something and don't get why it was removed. I am also reading Deep Learning with Python and the chapter about Embedding layer.

Thanks

the early bird catches the worm: I think I got the solution.
```
corpus = [ ] # I have a dummy example of restaurant reviews.

y = [ ] # label variable. negative or positive. It will be converted with LabelEncoder

tokenizer = Tokenizer(num_words= 25)
tokenizer.fit_on_texts(corpus)
vocabulary_size = len(tokenizer.word_index)+1
print(f"Vocabulary size: {vocabulary_size}")

sequences = tokenizer.texts_to_sequences(corpus)
max_len = len(max(sequences, key=len))
padded_sequences = pad_sequences(sequences, maxlen=max_len)
print(f"padded_sequences: {padded_sequences}")
print(f"max len: {max_len}")

clear_session()
#Simple NN for embedding
model = Sequential()
model.add(Embedding(
  input_dim=vocabulary_size,
  output_dim=2,
  input_shape=(max_len,)
  ))
model.summary()
```

I was expecting and I am finally receiving an output shape (None, 5, 2) with 50 parameters.

For now it seems to work and I am going to try it
> Hi @vinhpt01 , In Keras3 input_length argument not exists. It seems you are using TF2.16 which comes with Keras3 package. From Tf2.16v onwards tf.keras refers to Keras3 packages only. Could you confirm which TF version you have installed?
> 
> If you want to use Keras2 version then you need to set the environment variable `TF_USE_LEGACY_KERAS=1`

Thank for your response, yes i have used TF 2.16.1. What is alternative for 'input_length' in Keras3?
Hi @vinhpt01 ,

Please refer to this [comment](https://github.com/keras-team/keras/issues/19094#issuecomment-1909387912) which might be useful.
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.
It's a shame Keras still has this in the documentation. This should be updated.

for me:

tensorflow.version.VERSION, keras.version() = ('2.16.1', '3.0.5')

![image](https://github.com/keras-team/keras/assets/31286651/dc00d67d-0d13-4e32-9dc3-9f82bff12155)

> It's a shame Keras still has this in the documentation. This should be updated.

Hi @johnomage ,

Thanks for pointing to the doc bug. Will propose a fix for same.

Resolving patch:
diff --git a/keras/layers/core/embedding.py b/keras/layers/core/embedding.py
--- a/keras/layers/core/embedding.py
+++ b/keras/layers/core/embedding.py
@@ -20,7 +20,7 @@ class Embedding(Layer):
     Example:
 
     >>> model = keras.Sequential()
-    >>> model.add(keras.layers.Embedding(1000, 64, input_length=10))
+    >>> model.add(keras.layers.Embedding(1000, 64))
     >>> # The model will take as input an integer matrix of size (batch,
     >>> # input_length), and the largest integer (i.e. word index) in the input
     >>> # should be no larger than 999 (vocabulary size).


Test patch: