How minhducnguyen9705/book-recommendation works
Project Type and Purpose
• This is a Python-based book recommendation system (“book_rec”) that implements multiple recommendation algorithms (Popularity, Naive Bayes, TF-IDF, Matrix Factorization, NeuMF).
• It provides training pipelines, model storage (weights), inference scripts, and exposes an API (via API.py/app.py) for real‐time recommendations.
High-Level Architecture Overview
• The system can be broken down into these main components:
A) Data Layer
B) Model Training Pipelines
C) Model Storage / Registry
D) Inference Service (API Layer)
E) CI/CD & Dev Environment
F) Client / Consumer
Component Details & Interactions
A) Data Layer
• CSV files under Data/ (final_books.csv, interaction.csv, user_data.csv)
• Used by all training pipelines and by preprocessing modules
B) Model Training Pipelines
• Six algorithm-specific modules:
1. Popularity (Popularity/main.py, Popularity/model.py)
2. NaiveBayes (NaiveBayes/train.py, NaiveBayes/infer.py)
3. TF-IDF (TF-IDF/train.py, TF-IDF/infer.py)
4. Matrix Factorization (Matrix_factorization/train.py, inference.py)
5. NeuMF (NeuMF/train.py, inference.py)
• Each pipeline reads raw data, runs preprocessing (in utils.py or preprocessing_data.py), trains the model, evaluates (via test.py), and writes weights or artifacts.
C) Model Storage / Registry
• weights/ folder stores trained model files (e.g., *.h5 for NeuMF, vocab.joblib for NaiveBayes).
• This acts as a simple model registry that the inference layer pulls from.
D) Inference Service (API Layer)
• API.py and app.py implement a Flask/FastAPI service exposing endpoints like /recommend or /predict.
• On request, loads the appropriate model from weights/ and runs inference logic in each module’s inference.py.
• example.py demonstrates client calls to the API.
E) CI/CD & Dev Environment
• .github/workflows/train.yml builds and runs training tests on PRs.
• .github/workflows/demo.yml might deploy or run a demo.
• .devcontainer/devcontainer.json sets up a reproducible dev container.
F) Client / Consumer
• Could be any front end or script that calls the API (example.py is one).
Architectural Patterns & Design Principles
• Modular “per-algorithm” pattern: each recommendation approach is fully encapsulated in its own directory.
• Clear separation of concerns: data ingestion → preprocessing → training → testing → inference.
• Simple registry pattern for model artifacts (weights directory).
• CI pipelines enforce automated testing on training code and demo deployments.