Hello people! I’m reading the source code for collaborative filtering and I had a question.
So we have the collab_learner function that returns the CollabLearner object.
def collab_learner(data, n_factors:int=None, use_nn:bool=False, emb_szs:Dict[str,int]=None, layers:Collection[int]=None,
ps:Collection[float]=None, emb_drop:float=0., y_range:OptRange=None, use_bn:bool=True,
bn_final:bool=False, **learn_kwargs)->Learner:
"Create a Learner for collaborative filtering on `data`."
emb_szs = data.get_emb_szs(ifnone(emb_szs, {}))
u,m = data.train_ds.x.classes.values()
if use_nn: model = EmbeddingNN(emb_szs=emb_szs, layers=layers, ps=ps, emb_drop=emb_drop, y_range=y_range,
use_bn=use_bn, bn_final=bn_final, **learn_kwargs)
else: model = EmbeddingDotBias(n_factors, len(u), len(m), y_range=y_range)
return CollabLearner(data, model, **learn_kwargs)
Here’s my question. In the last but final line in the above block of code
else: model = EmbeddingDotBias(n_factors, len(u), len(m), y_range=y_ra
nge)
in which EmbeddingDotBias object is being created which is then input into the final line creating the CollabLearner object. BUT the the CollabLearner object seems to inherit from a Learner object(from old fastai)
Neither does CollabLearner have super init nor does the Learner take an input called ‘model’.
So how does this code not break? What am I missing?
Essentially how does the final line of the above code block make sense keepig the first line of the CollabLearner in persepctive?
class CollabLearner(Learner):
"`Learner` suitable for collaborative filtering."
and Learner is like this?
class Learner():
def __init__(self, data, models, opt_fn=None, tmp_name='tmp', models_name='models', metrics=None, clip=None, crit=None):