添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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 ?

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)
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.