nntoolbox.tabular.models.collab module

class nntoolbox.tabular.models.collab.CollabFiltering(n_users: int, n_products: int, embedding_dim: int)[source]

Bases: torch.nn.modules.module.Module

A simple collaborative model

forward(inputs: torch.Tensor) → torch.Tensor[source]
Parameters

inputs – the pair of user-product of shape (batch_size, 2)

Returns

(batch_size, 1)

get_score(users: torch.Tensor, products: torch.Tensor) → torch.Tensor[source]

Return the score of corresponding pairs of users-products

Parameters
  • users – (batch_size, )

  • products – (batch_size, )

training: bool
class nntoolbox.tabular.models.collab.NonLinearCF(n_users: int, n_products: int, user_dim: int, product_dim: int, body: Optional[torch.nn.modules.module.Module] = None)[source]

Bases: torch.nn.modules.module.Module

A non-linear collaborative model. If no body model is provided, default to a one-hidden layer net

forward(inputs: torch.Tensor) → torch.Tensor[source]

Return the score of corresponding pairs of products and users

Parameters

inputs – the pair of user-product of shape (batch_size, 2)

Returns

(batch_size, 1)

get_score(users: torch.Tensor, products: torch.Tensor) → torch.Tensor[source]

Return the score of corresponding pairs of users-products

Parameters
  • users – (batch_size, )

  • products – (batch_size, )

training: bool