Layer.__init__() takes 1 positional argument but 2 were given

I followed the tutorial all the way to the class part , and i got this error when i run this code

model = MyModel(
    vocab_size=vocab_size,
    embedding_dim=embedding_dim,
    rnn_units=rnn_units)

the error stack trace is as follow

Traceback (most recent call last):
  File "D:\1_chatbot\text_generation\03_cleanedup.py", line 78, in <module>
    model = MyModel(
            ^^^^^^^^
  File "D:\1_chatbot\text_generation\03_cleanedup.py", line 9, in __init__
    super().__init__(self)
  File "D:\Python Cattus\Lib\site-packages\keras\src\models\model.py", line 156, in __init__
    Layer.__init__(self, *args, **kwargs)
TypeError: Layer.__init__() takes 1 positional argument but 2 were given

Can someone shed a light on this ?

Hi @Clone_3, I have tried to run the code for building the model mentioned in the tutorial. I did not face any error. Please refer to this gist for working code example. Thank You.

I was able to reproduce the error by upgrading to TensorFlow 2.16.1:

pip install -U tensorflow

To work around the error, Gemini suggested changing

super().__init__(self)

to

super(MyModel, self).__init__()

With that change, I verified that the code runs without error, but I don’t know if it’s really instantiating the model correctly.

which python version do you have? (python --version)

The Python version in the colab where I reproduced the error is Python 3.10.12.