online-ml / deep-river

https://online-ml.github.io/river-torch
BSD 3-Clause "New" or "Revised" License
101 stars 10 forks source link

[QUESTION] Embedding and Ranking #88

Open zeyaddeeb opened 5 months ago

zeyaddeeb commented 5 months ago

If I have a model like this:

class Model(torch.nn.Module):
...
        self.user_embed = torch.nn.Embedding(n_users, n_factors)
...

What would be the best way to implement def learn_one... given that new users get added from a stream?

kulbachcedric commented 1 month ago

Hi @zeyaddeeb, I would stick to the regression learn_one method:

def learn_one(self, x: dict, y: RegTarget, **kwargs) -> "Regressor": if not self.module_initialized: self.kwargs["n_features"] = len(x) self.initialize_module(**self.kwargs) x_t = dict2tensor(x, self.device) y_t = float2tensor(y, device=self.device) self._learn(x_t, y_t) return self

The helper methods _learn, dict2tensor and float2tensor might help you as well.

Best Cedric