Skip to content

Commit 91bfe73

Browse files
authored
Feature/transformer_models (#220)
- Added `SASRecModel` and `BERT4RecModel` - Added Transformers theory & practice tutorial - Added Transformers advanced training guide - Added Transformers customization guide
1 parent b49f0cd commit 91bfe73

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+12643
-166
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
run: make test
7272

7373
- name: Upload coverage
74-
if: matrix.python-version == '3.9'
74+
if: matrix.python-version == '3.9' && ! startsWith(github.base_ref, 'experimental/')
7575
uses: codecov/codecov-action@v4
7676
with:
7777
fail_ci_if_error: true

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## Unreleased
99

1010
### Added
11+
- `SASRecModel` and `BERT4RecModel` - models based on transformer architecture ([#220](https://github.com/MobileTeleSystems/RecTools/pull/220))
12+
- Transfomers extended theory & practice tutorial, advanced training guide and customization guide ([#220](https://github.com/MobileTeleSystems/RecTools/pull/220))
1113
- `use_gpu` for PureSVD ([#229](https://github.com/MobileTeleSystems/RecTools/pull/229))
1214
- `from_params` method for models and `model_from_params` function ([#252](https://github.com/MobileTeleSystems/RecTools/pull/252))
1315
- `TorchRanker` ranker which calculates scores using torch. Supports GPU. [#251](https://github.com/MobileTeleSystems/RecTools/pull/251)

README.md

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@
2121
<a href="https://github.com/orgs/MobileTeleSystems/projects/1">Developers Board</a>
2222
</p>
2323

24-
RecTools is an easy-to-use Python library which makes the process of building recommendation systems easier,
25-
faster and more structured than ever before.
26-
It includes built-in toolkits for data processing and metrics calculation,
27-
a variety of recommender models, some wrappers for already existing implementations of popular algorithms
28-
and model selection framework.
29-
The aim is to collect ready-to-use solutions and best practices in one place to make processes
30-
of creating your first MVP and deploying model to production as fast and easy as possible.
24+
RecTools is an easy-to-use Python library which makes the process of building recommender systems easier and
25+
faster than ever before.
26+
27+
## ✨ Highlights: Transformer models released! ✨
28+
29+
**BERT4Rec and SASRec are now available in RecTools:**
30+
- Fully compatible with our `fit` / `recommend` paradigm and require NO special data processing
31+
- Explicitly described in our [Transformers Theory & Practice Tutorial](examples/tutorials/transformers_tutorial.ipynb): loss options, item embedding options, category features utilization and more!
32+
- Configurable, customizable, callback-friendly, checkpoints-included, logs-out-of-the-box, custom-validation-ready, multi-gpu-compatible! See [Transformers Advanced Training User Guide](examples/tutorials/transformers_advanced_training_guide.ipynb) and [Transformers Customization Guide](examples/tutorials/transformers_customization_guide.ipynb)
33+
- Public benchmarks which compare RecTools models to other open-source implementations following BERT4Rec replicability paper show that RecTools implementations achieve highest scores on multiple datasets: [Performance on public transformers benchmarks](https://github.com/blondered/bert4rec_repro?tab=readme-ov-file#rectools-transformers-benchmark-results)
34+
35+
36+
3137

3238

3339

@@ -103,6 +109,8 @@ See [recommender baselines extended tutorial](https://github.com/MobileTeleSyste
103109

104110
| Model | Type | Description (🎏 for user/item features, 🔆 for warm inference, ❄️ for cold inference support) | Tutorials & Benchmarks |
105111
|----|----|---------|--------|
112+
| SASRec | Neural Network | `rectools.models.SASRecModel` - Transformer-based sequential model with unidirectional attention mechanism and "Shifted Sequence" training objective <br>🎏| 📕 [Transformers Theory & Practice](examples/tutorials/transformers_tutorial.ipynb)<br> 📗 [Advanced training guide](examples/tutorials/transformers_advanced_training_guide.ipynb) <br> 📘 [Customization guide](examples/tutorials/transformers_customization_guide.ipynb) <br> 🚀 [Top performance on public benchmarks](https://github.com/blondered/bert4rec_repro?tab=readme-ov-file#rectools-transformers-benchmark-results) |
113+
| BERT4Rec | Neural Network | `rectools.models.BERT4RecModel` - Transformer-based sequential model with bidirectional attention mechanism and "MLM" (masked item) training objective <br>🎏| 📕 [Transformers Theory & Practice](examples/tutorials/transformers_tutorial.ipynb)<br> 📗 [Advanced training guide](examples/tutorials/transformers_advanced_training_guide.ipynb) <br> 📘 [Customization guide](examples/tutorials/transformers_customization_guide.ipynb) <br> 🚀 [Top performance on public benchmarks](https://github.com/blondered/bert4rec_repro?tab=readme-ov-file#rectools-transformers-benchmark-results) |
106114
| [implicit](https://github.com/benfred/implicit) ALS Wrapper | Matrix Factorization | `rectools.models.ImplicitALSWrapperModel` - Alternating Least Squares Matrix Factorizattion algorithm for implicit feedback. <br>🎏| 📙 [Theory & Practice](https://rectools.readthedocs.io/en/latest/examples/tutorials/baselines_extended_tutorial.html#Implicit-ALS)<br> 🚀 [50% boost to metrics with user & item features](examples/5_benchmark_iALS_with_features.ipynb) |
107115
| [implicit](https://github.com/benfred/implicit) BPR-MF Wrapper | Matrix Factorization | `rectools.models.ImplicitBPRWrapperModel` - Bayesian Personalized Ranking Matrix Factorization algorithm. | 📙 [Theory & Practice](https://rectools.readthedocs.io/en/latest/examples/tutorials/baselines_extended_tutorial.html#Bayesian-Personalized-Ranking-Matrix-Factorization-(BPR-MF)) |
108116
| [implicit](https://github.com/benfred/implicit) ItemKNN Wrapper | Nearest Neighbours | `rectools.models.ImplicitItemKNNWrapperModel` - Algorithm that calculates item-item similarity matrix using distances between item vectors in user-item interactions matrix | 📙 [Theory & Practice](https://rectools.readthedocs.io/en/latest/examples/tutorials/baselines_extended_tutorial.html#ItemKNN) |
@@ -115,20 +123,33 @@ See [recommender baselines extended tutorial](https://github.com/MobileTeleSyste
115123
| Random | Heuristic | `rectools.models.RandomModel` - Simple random algorithm useful to benchmark Novelty, Coverage, etc.<br>❄️| - |
116124

117125
- All of the models follow the same interface. **No exceptions**
118-
- No need for manual creation of sparse matrixes or mapping ids. Preparing data for models is as simple as `dataset = Dataset.construct(interactions_df)`
126+
- No need for manual creation of sparse matrixes, torch dataloaders or mapping ids. Preparing data for models is as simple as `dataset = Dataset.construct(interactions_df)`
119127
- Fitting any model is as simple as `model.fit(dataset)`
120128
- For getting recommendations `filter_viewed` and `items_to_recommend` options are available
121129
- For item-to-item recommendations use `recommend_to_items` method
122-
- For feeding user/item features to model just specify dataframes when constructing `Dataset`. [Check our tutorial](examples/4_dataset_with_features.ipynb)
130+
- For feeding user/item features to model just specify dataframes when constructing `Dataset`. [Check our example](examples/4_dataset_with_features.ipynb)
123131
- For warm / cold inference just provide all required ids in `users` or `target_items` parameters of `recommend` or `recommend_to_items` methods and make sure you have features in the dataset for warm users/items. **Nothing else is needed, everything works out of the box.**
132+
- Our models can be initialized from configs and have useful methods like `get_config`, `get_params`, `save`, `load`. Common functions `model_from_config`, `model_from_params` and `load_model` are available. [Check our example](examples/9_model_configs_and_saving.ipynb)
124133

125134

126135
## Extended validation tools
127136

137+
### `calc_metrics` for classification, ranking, "beyond-accuracy", DQ, popularity bias and between-model metrics
138+
139+
140+
[User guide](https://github.com/MobileTeleSystems/RecTools/blob/main/examples/3_metrics.ipynb) | [Documentation](https://rectools.readthedocs.io/en/stable/features.html#metrics)
141+
142+
128143
### `DebiasConfig` for debiased metrics calculation
129144

130145
[User guide](https://github.com/MobileTeleSystems/RecTools/blob/main/examples/8_debiased_metrics.ipynb) | [Documentation](https://rectools.readthedocs.io/en/stable/api/rectools.metrics.debias.DebiasConfig.html)
131146

147+
### `cross_validate` for model metrics comparison
148+
149+
150+
[User guide](https://github.com/MobileTeleSystems/RecTools/blob/main/examples/2_cross_validation.ipynb)
151+
152+
132153
### `VisualApp` for model recommendations comparison
133154

134155
<img src="https://recsysart.ru/images/visual_app.gif" width=500>
@@ -193,6 +214,7 @@ make clean
193214
- [Maya Spirina](https://github.com/spirinamayya)
194215
- [Grigoriy Gusarov](https://github.com/Gooogr)
195216
- [Aki Ariga](https://github.com/chezou)
217+
- [Nikolay Undalov](https://github.com/nsundalov)
196218

197219
Previous contributors: [Ildar Safilo](https://github.com/irsafilo) [ex-Maintainer], [Daniil Potapov](https://github.com/sharthZ23) [ex-Maintainer], [Alexander Butenko](https://github.com/iomallach), [Igor Belkov](https://github.com/OzmundSedler), [Artem Senin](https://github.com/artemseninhse), [Mikhail Khasykov](https://github.com/mkhasykov), [Julia Karamnova](https://github.com/JuliaKup), [Maxim Lukin](https://github.com/groundmax), [Yuri Ulianov](https://github.com/yukeeul), [Egor Kratkov](https://github.com/jegorus), [Azat Sibagatulin](https://github.com/azatnv), [Vadim Vetrov](https://github.com/Waujito)
198220

docs/source/examples.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ See examples here: https://github.com/MobileTeleSystems/RecTools/tree/main/examp
1414
examples/5_benchmark_iALS_with_features
1515
examples/6_benchmark_lightfm_inference
1616
examples/7_visualization
17+
examples/8_debiased_metrics
18+
examples/9_model_configs_and_saving

docs/source/models.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ Details of RecTools Models
1212
+-----------------------------+-------------------+---------------------+---------------------+
1313
| Model | Supports features | Recommends for warm | Recommends for cold |
1414
+=============================+===================+=====================+=====================+
15+
| SASRecModel | Yes | No | No |
16+
+-----------------------------+-------------------+---------------------+---------------------+
17+
| BERT4RecModel | Yes | No | No |
18+
+-----------------------------+-------------------+---------------------+---------------------+
1519
| DSSMModel | Yes | Yes | No |
1620
+-----------------------------+-------------------+---------------------+---------------------+
1721
| EASEModel | No | No | No |
1822
+-----------------------------+-------------------+---------------------+---------------------+
1923
| ImplicitALSWrapperModel | Yes | No | No |
2024
+-----------------------------+-------------------+---------------------+---------------------+
25+
| ImplicitBPRWrapperModel | No | No | No |
26+
+-----------------------------+-------------------+---------------------+---------------------+
2127
| ImplicitItemKNNWrapperModel | No | No | No |
2228
+-----------------------------+-------------------+---------------------+---------------------+
2329
| LightFMWrapperModel | Yes | Yes | Yes |

docs/source/tutorials.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ See tutorials here: https://github.com/MobileTeleSystems/RecTools/tree/main/exam
88
:glob:
99

1010
examples/tutorials/baselines_extended_tutorial
11+
examples/tutorials/transformers_tutorial
12+
examples/tutorials/transformers_advanced_training_guide
13+
examples/tutorials/transformers_customization_guide

0 commit comments

Comments
 (0)