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(

the error stack trace is as follow

Traceback (most recent call last):
  File "D:\1_chatbot\text_generation\", line 78, in <module>
    model = MyModel(
  File "D:\1_chatbot\text_generation\", line 9, in __init__
  File "D:\Python Cattus\Lib\site-packages\keras\src\models\", 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(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.