Skip to content
/ LAKR Public

LLM-Augmented Knowledge-Graph-Based Recommendation System

Notifications You must be signed in to change notification settings

carteakey/LAKR

Repository files navigation

LAKR (LLM-Augmented Knowledge-Graph-Based Recommendation)

Getting Started

Prerequisites

Installation

Install the necessary packages:

pip install -r requirements.txt

For CUDA support:

CUDACXX=/usr/local/cuda-12/bin/nvcc CMAKE_ARGS="-DLLAMA_CUBLAS=on -DCMAKE_CUDA_ARCHITECTURES=native" FORCE_CMAKE=1 pip install pandas numpy scikit-learn scipy implicit

Start the databases:

Neo4j:

cd db/neo4j
docker compose up -d

Please note that the Neo4j database is started with the default password neo4j. The password is changed after the first run.

Postgres:

cd db/postgres
docker compose up -d

Running the Code

Update the variables inside the run.sh and config/env.sh files to point to the correct directories.

Data Preprocessing

K-core Filtering

Download the Amazon Reviews dataset

(Note that the initial download will take some time.)

./run.sh download_amazon_reviews

Filter the dataset to retain users and items with at least 15 interactions :

./run.sh k_core_filtering

Splitting the Data

Last Out Split

./run.sh last_out_split

Timestamp Split

./run.sh timestamp_split

Random Split

./run.sh random_split

Data Loading

Loading Data to DuckDB

Load K-core Ratings

./run.sh load_kcore_ratings_duckdb

Load Metadata and Reviews

This takes some time as the metadata and reviews are downloaded in huggingface format and then loaded into DuckDB.

./run.sh load_metadata_reviews_duckdb

Load Metadata as Baseline KG

./run.sh load_metadata_neo4j

Knowledge Graph Augmentation using LLM

Extract Relationships (e.g., SIMILAR_TO_BOOK, RELATED_AUTHOR)

./run.sh extract_relationships --relationship SIMILAR_TO_BOOK --max_batches 10

Evaluate Extracted Relationships

./run.sh evaluate_relationships --relationship SIMILAR_TO_BOOK

Update KG with Extracted Relationships

./run.sh update_kg --relationship SIMILAR_TO_BOOK

Model Training

BPRMF

Train the BPRMF model:

./run.sh train_bprmf

To resume training from a pre-trained model:

./run.sh train_bprmf_pretrained

KGAT

./run.sh train_kgat

To use pre-trained embeddings:

./run.sh train_kgat_pretrained

Resetting the Databases

Reset DuckDB

rm -rf db/duckdb/amazon-reviews.db

Reset Neo4j

cd db/neo4j
sudo reset.sh

Reset Postgres

cd db/postgres
sudo reset.sh

About

LLM-Augmented Knowledge-Graph-Based Recommendation System

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published