0

I am new to the programming in python and getting confused with the oops concept in python. I know super() is used to use the methods defined in the parent class, but I can't understand why the parent class itself using the super() keyword.

class BahdanauAttention(tf.keras.Model):
  def __init__(self, units):
    super(BahdanauAttention, self).__init__()
    self.W1 = tf.keras.layers.Dense(units)
    self.W2 = tf.keras.layers.Dense(units)
    self.V = tf.keras.layers.Dense(1)
vvvvv
  • 25,404
  • 19
  • 49
  • 81
Jacob Lawrence
  • 145
  • 1
  • 2
  • 9

2 Answers2

2

The BahdanauAttention is inheriting from tf.keras.Model, meaning the super call within its init actually calls the init method of tf.keras.Model.

One more thing: Since Python 3, you don't need to pass any arguments to the super call:

super().__init__()
AdamGold
  • 4,941
  • 4
  • 29
  • 47
  • 1
    Happy to help, and welcome to Stack Overflow. If this answer or any other one solved your issue, please mark it as accepted. – AdamGold Feb 25 '20 at 08:24
0

I suggest you read posts about super() method in Python 3, it 's tricky, especially with multiple inheritance (even if it's not the cas ehere), How does Python's super() work with multiple inheritance?

sslloo
  • 521
  • 2
  • 10