Skip to main content

_hopwise_ is an advanced extension of the Recbole library, designed to enhance recommendation systems with the power of knowledge graphs. By integrating knowledge embedding models, path-based reasoning methods, and path language modeling apporaches, hopwise supports both recommendation and link prediction tasks with a focus on interpretability and self-explanation.

Project description

🚀 hopwise

RecBole extension with a focus on Knowledge Graphs (KGs) and explainability.

Static Badge GitHub forks GitHub stars


✨ Overview

hopwise is an advanced extension of the RecBole library, designed to enhance recommendation systems with the power of knowledge graphs. By integrating knowledge embedding models, path-based reasoning methods, and path language modeling approaches, hopwise supports both recommendation and link prediction tasks with a focus on explainability.


hopwise pipeline

Our framework: new functionalities, datasets utilities, abstraction layers, environment utils, metrics type, models

🆕 What's New?

🆕 Path Reasoning Models

We also added KGLRR although the final explanation is not based on a predicted path in a Knowledge Graph.

🆕 Knowledge Graph Embedding Models

📌 Translational Models

📌 Tensor/Matrix Factorization Models

📌 Convolution-Based Models

We relied for most of the Knowledge Graph Embeddings methods to: TorchKGE due to its popularity, published at a KDD workshop in 2020.

🆕 Explanation Path Quality Metrics

  • LIR (Linking Interaction Recency)
  • SEP (Shared Entity Popularity)
  • LID (Linking Interaction Diversity)
  • LITD (Linked Interaction Type Diversity)
  • SED (Shared Entity Diversity)
  • SETD (Shared Entities Type Diversity)
  • PTC (Path Type Concentration)
  • PPT (Path Pattern Type)
  • PTD/PPC (Path Type Diversity)
  • Model Fidelity

🆕 New Datasets

  • MovieLens-1M Small: used in the papers PEARLM and KGGLM
  • Last.FM-1M Small: used in the papers PEARLM and KGGLM
  • Yelp 2018: used in the paper KGAT
  • Alibaba Fashion: used in the paper KGRec

All the datasets are available as zip archives on Google Drive.

[!IMPORTANT] Check the paper for the other changes.

⚡ Installation

To install the project, you need to use uv. Follow the steps below to set up the environment and install the necessary dependencies.

🔹 Prerequisites

  • ✅ Python 3.9, 3.10, or 3.11
  • uv package manager

🔹 Steps (from PyPI or from Source)

1️⃣ Install uv and create a virtual environment.

We suggest installing uv as a standalone application instead of using pip to avoid issues and let uv create a dedicated virtual environment.
Once installed, create the virtual environment

uv venv --python PYTHON_VERSION --prompt hopwise

PYTHON_VERSION must be one of 3.9, 3.10, 3.11, while --prompt hopwise customizes the virtual environment name that appears on the shell.

2️⃣ Install via PyPI

uv pip install hopwise

Some models require extra dependencies. In particular, language models for KG path reasoning require extra dependencies to be installed. You can install them by specifying the extra pathlm in the command line as follows:

uv pip install hopwise[pathlm]

Other models can be installed with a similar process. For instance, to install NNCF:

uv pip install hopwise[nncf]

Please check the PyPI page for the complete list of extra dependencies and the documentation for more details on how to install hopwise with specific dependencies.

🎉 Done 🎉


2️⃣ Install from source: Clone the repository

git clone https://github.com/tail-unica/hopwise.git
cd hopwise

3️⃣ Install project dependencies

📌 make sure to have uv updated to the latest version

uv sync

📢 Windows: For proper DGL installation, please follow the official DGL installation guide. Windows builds may encounter DLL linking issues with standard installation methods. Pre-built packages from the official source are recommended. Otherwise, using the Windows Subsystem for Linux (WSL) might be feasible as a solution.

🎉 Done 🎉

🚀 Usage

In any chosen setup, a .yaml file must be created containing the configuration to be used. An example:

gpu_id: 0
topk: [10,20,50,...]
data_path: *your_datasets_folder*
metrics: ['NDCG', 'MRR', 'Hit', 'Precision', 'Recall',...]
valid_metric: ndcg@10
eval_batch_size: 1
epochs: 1
eval_step: 1

📍 Training

traintest

Run the project with the following command:

hopwise train \
    --model MODEL \
    --dataset DATASET \
    --config_files CONF_FILE_1.yaml CONF_FILE_2.yaml

Override config parameters directly from the CLI using =:

hopwise train --epochs=20

📍 Evaluating from Checkpoint

pgprevaltest

hopwise evaluate --dataset DATASET --model MODEL \
--config-files CONFIG_FILES --checkpoint CHECKPOINT.pth

📍 Hyperparameters Tuning

In addition to the configuration file, a params file with the extension .hyper the range of hyperparameters to be tested must also be set in this configuration

learning_rate uniform 0.0001, 0.1
embedding_size choice [64, 100, 200]

hypertuningtest

hopwise tune \
    --params-file hopwise/properties/hyper/PARAMS_FILE.hyper \
    --config-files CONFIG_FILE.yaml \
    --study-name STUDY_NAME

ℹ️ Contributing

Please let us know if you encounter a bug or have any suggestions by filing an issue.

We welcome all contributions from bug fixes to new features and extensions. 🚀

We expect all contributions discussed in the issue tracker and going through PRs. 📌

📜 Cite

If you find hopwise useful for your research or development, please cite with:

the paper is under revision

The Team

Ludovico Boratto, Gianni Fenu, Mirko Marras, Giacomo Medda, Alessandro Soccol

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hopwise-0.9.1.post1.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hopwise-0.9.1.post1-py3-none-any.whl (2.3 MB view details)

Uploaded Python 3

File details

Details for the file hopwise-0.9.1.post1.tar.gz.

File metadata

  • Download URL: hopwise-0.9.1.post1.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.13

File hashes

Hashes for hopwise-0.9.1.post1.tar.gz
Algorithm Hash digest
SHA256 7151fe980856cd74e5f8a87da5ba7dd11671a95ec67b0eef2ed99f7dcefd212b
MD5 6774b576b8a2e3ec06ada4e4fb55e4fb
BLAKE2b-256 2c4fc6173288d108b2f4104d13c956ea2752b729584fe5aa1aef859b6c31b75d

See more details on using hashes here.

File details

Details for the file hopwise-0.9.1.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for hopwise-0.9.1.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 2c2af1973eecd631bb687cf0b665f2d84323f95fb02c673c7dcb3d1bc02240f3
MD5 9197b376dd033b1c76a99c3c3deb9a4a
BLAKE2b-256 330c0a49ec7ce94954de5a897345b95a7676d92801ca3b18b25b5e788f11d4ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page