Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow warp-kos loss for LightFMWrapperModel #175

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- `display()` method in `MetricsApp` ([#169](https://github.com/MobileTeleSystems/RecTools/pull/169))

### Fixed
- Allow warp-kos loss for LightFMWrapperModel ([#175](https://github.com/MobileTeleSystems/RecTools/pull/175))

## [0.7.0] - 29.07.2024

### Added
Expand Down
3 changes: 2 additions & 1 deletion rectools/models/lightfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ def _fit(self, dataset: Dataset) -> None: # type: ignore
ui_coo = dataset.get_user_item_matrix(include_weights=True).tocoo(copy=False)
user_features = self._prepare_features(dataset.get_hot_user_features(), dataset.n_hot_users)
item_features = self._prepare_features(dataset.get_hot_item_features(), dataset.n_hot_items)
sample_weight = None if self._model.loss == "warp-kos" else ui_coo

self.model.fit(
ui_coo,
user_features=user_features,
item_features=item_features,
sample_weight=ui_coo,
sample_weight=sample_weight,
epochs=self.n_epochs,
num_threads=self.n_threads,
verbose=self.verbose > 0,
Expand Down
10 changes: 10 additions & 0 deletions tests/models/test_lightfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ def test_with_weights(self, interactions_df: pd.DataFrame) -> None:
actual,
)

def test_with_warp_kos(self, dataset: Dataset) -> None:
base_model = DeterministicLightFM(no_components=2, loss="warp-kos")
try:
LightFMWrapperModel(model=base_model, epochs=10).fit(dataset)
except NotImplementedError:
pytest.fail("Should not raise NotImplementedError")
except ValueError:
# LightFM raises ValueError with the dataset
pass

def test_get_vectors(self, dataset_with_features: Dataset) -> None:
base_model = LightFM(no_components=2, loss="logistic")
model = LightFMWrapperModel(model=base_model).fit(dataset_with_features)
Expand Down
Loading