collab_learner {fastai}R Documentation

Collab_learner

Description

Create a Learner for collaborative filtering on 'dls'.

Usage

collab_learner(
  dls,
  n_factors = 50,
  use_nn = FALSE,
  emb_szs = NULL,
  layers = NULL,
  config = NULL,
  y_range = NULL,
  loss_func = NULL,
  opt_func = Adam(),
  lr = 0.001,
  splitter = trainable_params(),
  cbs = NULL,
  metrics = NULL,
  path = NULL,
  model_dir = "models",
  wd = NULL,
  wd_bn_bias = FALSE,
  train_bn = TRUE,
  moms = list(0.95, 0.85, 0.95)
)

Arguments

dls

a data loader object

n_factors

The number of factors

use_nn

use_nn

emb_szs

embedding size

layers

list of layers

config

configuration

y_range

y_range

loss_func

It can be any loss function you like. It needs to be one of fastai's if you want to use Learn.predict or Learn.get_preds, or you will have to implement special methods (see more details after the BaseLoss documentation).

opt_func

The function used to create the optimizer

lr

learning rate

splitter

It is a function that takes self.model and returns a list of parameter groups (or just one parameter group if there are no different parameter groups).

cbs

Cbs is one or a list of Callbacks to pass to the Learner.

metrics

It is an optional list of metrics, that can be either functions or Metrics.

path

The folder where to work

model_dir

Path and model_dir are used to save and/or load models.

wd

It is the default weight decay used when training the model.

wd_bn_bias

It controls if weight decay is applied to BatchNorm layers and bias.

train_bn

It controls if BatchNorm layers are trained even when they are supposed to be frozen according to the splitter.

moms

The default momentums used in Learner.fit_one_cycle.

Value

learner object

Examples


## Not run: 

URLs_MOVIE_LENS_ML_100k()
c(user,item,title)  %<-% list('userId','movieId','title')
ratings = fread('ml-100k/u.data', col.names = c(user,item,'rating','timestamp'))
movies = fread('ml-100k/u.item', col.names = c(item, 'title', 'date', 'N', 'url',
                                               paste('g',1:19,sep = '')))
rating_movie = ratings[movies[, .SD, .SDcols=c(item,title)], on = item]
dls = CollabDataLoaders_from_df(rating_movie, seed = 42, valid_pct = 0.1, bs = 64,
item_name=title, path='ml-100k')

learn = collab_learner(dls, n_factors = 40, y_range=c(0, 5.5))

learn %>% fit_one_cycle(1, 5e-3,  wd = 1e-1)


## End(Not run)


[Package fastai version 2.2.2 Index]