Callbacks Runner - "self()" function?

(Gaurav Upadhyay) #1

Greetings,

While going over Lesson 9, callbacks section; where Jeremy introduces the Runner, the code contains several calls like:

def one_batch(self, xb, yb):
    self.xb,self.yb = xb,yb
    if self('begin_batch'): return
    self.pred = self.model(self.xb)
    if self('after_pred'): return

While the ‘self’ object is commonly used in classes, I do not understand the use of the self('begin_batch'), which looks like a method call, on a method named self()

Have never used self this way. Please advise.
Where is it coming from?

0 Likes

(Gaurav Upadhyay) #2

The answer to it is in the very next lesson (no. 10). The no-arg behaviour is implemented in the __call__ method, so the name of the callback is received into the dunder call by simply issuing self(callback_event)

Thanks

0 Likes