-1

I've come across an example like below,

class Model(tf.keras.Model):
    def __init__(self, vocab_size, embedding_dim, dim, batch_sz):
        super(Model, self).__init__()
        self.dim = dim
        self.embedding = Embedding(vocab_size, embedding_dim)
        self.lstm = LSTM(self.enc_units,
                         recurrent_initializer='glorot_uniform')

In this why do we use super(Encoder, self).__init__()?. I'm not very familiar with object oriented programming with python.

user_12
  • 1,778
  • 7
  • 31
  • 72

1 Answers1

2

Since you are inhereting from anorther class class Model(tf.keras.Model): in the parenthasies here the parent class or super class in some cases has to be initialised aswell. Since you have two __init__ functions to know which one you are accessing the super is used to say use the parent classes __init__ method.

Iain McL
  • 164
  • 1
  • 10
  • Thank you. That was helpful. Here parent/super class would be `Model()` right? and child class would be `tf.keras.Model`? – user_12 Nov 29 '19 at 15:39
  • 1
    https://www.digitalocean.com/community/tutorials/understanding-class-inheritance-in-python-3 I think this describes it better and im more detail than I could. – Iain McL Nov 29 '19 at 15:42