Xanthus

Latest version: v0.1.0rc2

Safety actively analyzes 685525 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

0.1.0

This is the first release of Xanthus, a Neural Recommendation Model package implemented in Python on top of TensorFlow and utilising the high-level Keras API. Xanthus came into existence as an exercise in implementing and replicating the results of [a relatively current ML paper](https://dl.acm.org/doi/10.1145/3038912.3052569) and to try out some of the new features of TensorFlow 2.0 (and changes to the Keras API over the last couple of years!).

Release notes

Here's what's in the box:

Models

Three neural recommender models implemented with the Keras Model API:

* `GeneralizedMatrixFactorization` (GMF) - This model generalizes 'classic' matrix factorization (MF) as a neural model. By using the pointwise negative sampling approach outlined in literature, this model can produce higher performance than some 'classic' MF approaches for _some_ datasets.
* `MultiLayerPerceptron` (MLP) - A model with two input embedding blocks feeding into a 'classic' Multi-Layer Perceptron (MLP) block. As demonstrated in the literature, this architecture benefits from the depth of the model over 'shallower' models such as the GMF model in some cases.
* `NeuralMatrixFactorization` (NMF) - This model combines the GMF and MLP models into a single model. Theoretically with the benefits of both!

Bonus features

* Metadata support - The implementations of the above models (+ supporting utils) in this package are implemented to make it easy to quickly introduce _metadata_ into your recommendation models. This means Xanthus natively supports 'hybrid' recommendations (interaction data + user/item metadata). This is mentioned in [He et al's](https://dl.acm.org/doi/10.1145/3038912.3052569) work, but not implemented or assessed. [Here's an example if you're interested.](examples/metadata.py)
* TensorBoard support - By using the Keras `Model` API, Xanthus natively supports TensorBoard for model training and monitoring -- plus custom callbacks too. Why not Slack yourself after each training epoch? What could _possibly_ go wrong?

Data Utilities

Getting your data encoded neatly and quickly, generating useful training and evaluation datasets and getting that data into a format that can be used by your models can be a fiddly and time consuming process. To alleviate some of these issues and to help you get stuck into tuning your models, Xanthus provides the following utilities:

* `xanthus.datasets.Dataset` - A utility class for quickly and (relatively) efficiently building recommendation-friendly datasets, with a bunch of bundled utilities for manipulating these datasets too.
* `xanthus.datasets.DatasetEncoder` - Another utility class for encoding and decoding datasets, and to aid in preserving consistency _across_ split datasets (i.e. train/test datasets).
* `xanthus.evaluate.split` - An implementation of the 'Recommender Split' [implemented as part of the Azure ML Studio](https://docs.microsoft.com/en-us/azure/machine-learning/studio-module-reference/split-data-using-recommender-split:~:text=The%20Recommender%20Split%20option%20is,user-item-rating%20triples.). This gives you the option of sampling hold-out interactions, selecting subsets of interactions, and ensuring consistency between the resulting train and test sets.
* `xanthus.evaluate.create_rankings` - An implementation of the common ranking evaluation protocol used for recommendation models where `n` 'positive' items (items a user has interacted with, but weren't present in the test set) are appended to `m` 'negative' items (items a user hasn't interacted with). The model can then be queried to generate a ranking for these items, with the hope that 'positive' items will appear higher in the query results.

Bonus Features

But wait, there's more! Xanthus implements some common recommendation model metric functions including:

* `xanthus.evaluate.metrics.ndcg` - An implementation of the [Normalized Discounted Cumulative Gain (NDCG) metric](https://en.wikipedia.org/wiki/Discounted_cumulative_gain). Yes, that is a reference to Wikipedia.
* `xanthus.evaluate.metrics.hit_ratio` - An implementation of the common 'hit ratio' metric used in many recommendation model evaluation activities (see also `xanthus.evaluate.metrics.precision_at_k`).
* `xanthus.evaluate.metrics.truncated_ndcg` - A special-case NDCG implementation that has some performance optimizations for cases when the target set consists of a single 'positive' item in a set as opposed to the more general case addressed above.

Additionally, to make using these functions easier, you can use:

* `xanthus.evaluate.metrics.score` - A utility function for executing a `map` operation over a set of recommendations, applying a provided metric function, and then returning these scores as a NumPy array. This function provides support for parallel processing too!

Finally, if you're interested in 'coverage' metrics, there's:

* `xanthus.evaluate.metrics.coverage_at_k` - Coverage metrics can be handy for understanding how diverse your model's recommendations are -- exploring product catalogues is often a major motivation for recommenders in the first place, so 'pure' accuracy and ranking metrics (as above) might not give you the full picture.

Notes

Xanthus has been implemented with the aim of helping new users get a decent neural recommender model working as quickly as possible. From this point of view, it could be a good starting place for folk trying to get started with neural recommendation models.

*That said*, while neural models sound exciting and might attract attention, you might find that 'classic' recommendation models fit you're use-case better: 'lightweight' matrix factorization approaches are often simpler, faster and easier to use, so you might do well to look at those first. If you're interested, you should check out:

* `implicit` - [Implicit Matrix Factorization](https://github.com/benfred/implicit/tree/master/implicit)
* `LightFM` - [Hybrid Matrix Factorization](https://github.com/lyst/lightfm)

Disclaimer

The neural architectures implemented in this package are (currently) based directly upon [He et al's](https://dl.acm.org/doi/10.1145/3038912.3052569) work on Neural Collaborative Filtering. This team [has their own repository](https://github.com/hexiangnan/neural_collaborative_filtering) with the code they used in their paper. It's a good paper, I encourage you to check it out!

0.1.0rc2

0.1.0rc1

0.1.0b1

Some bug fixes and GitHub action improvements for the very first release of Xanthus. Release notes to follow.

And as always with pre-releases, be wary that there may well be changes before the first stable release!

Happy recommending!

0.1.0a0

The very first release of Xanthus. Release notes to follow.

And as always with pre-releases, be wary that there may well be changes before the first stable release!

Happy recommending!

Links

Releases

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.