Skip to content
LeeDongHun38Public

About

Topic-Enhanced LightGCN (TE-LGCN): A recommendation system using Doc2Vec and LDA for dual semantic enhancement.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Topic-Enhanced LightGCN (TE-LGCN)

License: MIT Python 3.8+ PyTorch

A novel recommendation system that enhances LightGCN with semantic content features through a dual enhancement strategy combining Doc2Vec embeddings and LDA topic modeling.

For full methodology & ablations, see docs/Topic-Enhanced LightGCN (TE-LGCN).pdf.

🎯 Overview

TE-LGCN (Topic-Enhanced LightGCN) addresses the cold-start problem and improves recommendation quality by incorporating content-based semantic information into graph collaborative filtering. Unlike vanilla LightGCN which relies solely on user-item interactions, TE-LGCN leverages:

  • Semantic Initialization: Doc2Vec embeddings from item content (e.g., movie plot summaries)
  • Structural Expansion: LDA-extracted topics as bridge nodes in the user-item graph
  • Content Consistency: A novel loss function that preserves semantic meaning during training

Key Results

Model Recall@10 Improvement
Baseline LightGCN ~0.159 -
TE-LGCN (k=10) ~0.200 +26.4%

πŸ”‘ Key Features

1. Dual Enhancement Strategy

Semantic Initialization (Doc2Vec)

  • Pre-trained document embeddings initialize item representations
  • Captures semantic similarity from textual content
  • Reduces cold-start issues for new items

Structural Expansion (LDA Topics)

  • Topic nodes create semantic bridges in the graph
  • Heterogeneous graph: User-Item-Topic connections
  • Enables recommendation via shared topic preferences

2. Content Consistency Loss

Combines three objectives:

L_total = L_BPR + λ₁ Β· L_reg + Ξ»β‚‚ Β· L_content

where:
- L_BPR: Bayesian Personalized Ranking loss
- L_reg: L2 regularization on embeddings
- L_content: L2 distance between learned and fixed Doc2Vec embeddings

3. Modular Python Package

Import and use TE-LGCN components in your own code:

from te_lgcn.models import TELightGCN
from te_lgcn.training import Trainer
from te_lgcn.evaluation import evaluate_model

πŸ“¦ Installation

Requirements

  • Python 3.8+
  • PyTorch 2.0+
  • CUDA (optional, for GPU acceleration)

Install from Source

# Clone the repository
git clone https://github.com/LeeDongHun38/TE-LGCN.git
cd TE-LGCN

# Install dependencies
pip install -r requirements.txt

# Install package in editable mode (recommended for development)
pip install -e .

Dependencies

Core libraries:

  • torch>=2.0.0 - Deep learning framework
  • gensim>=4.0.0 - Doc2Vec and LDA implementation
  • pandas, numpy, scipy - Data processing
  • scikit-learn - Additional ML utilities

πŸš€ Quick Start

Option 1: Using Jupyter Notebooks (Recommended for Research)

Follow the execution sequence in notebooks/README.md:

  1. Data Preprocessing: notebooks/preprocessing/data_preparation.ipynb
  2. Feature Extraction:
    • notebooks/feature_extraction/doc2vec_embeddings.ipynb
    • notebooks/feature_extraction/lda_topics.ipynb
  3. Baseline: notebooks/baselines/lightgcn_baseline.ipynb
  4. TE-LGCN: notebooks/te_lgcn/te_lgcn_k10.ipynb

Option 2: Using Python Package

import torch
from te_lgcn.models import TELightGCN
from te_lgcn.training import Trainer
from te_lgcn.evaluation import evaluate_model

# Load your data
# ... (see notebooks for data loading examples)

# Create model
model = TELightGCN(
    n_users=670,
    n_items=3485,
    n_topics=10,              # Number of LDA topics
    dim=64,                   # Embedding dimension
    layers=3,                 # GCN layers
    A_hat=adj_matrix,         # Normalized adjacency matrix
    doc2vec_weights=doc2vec_emb  # Pre-trained Doc2Vec embeddings
).to(device)

# Setup training
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
trainer = Trainer(
    model=model,
    optimizer=optimizer,
    device='cuda',
    lambda1=1e-5,  # L2 regularization weight
    lambda2=1e-3   # Content consistency weight
)

# Train
for epoch in range(50):
    loss = trainer.train_epoch(train_loader)
    results = evaluate_model(model, val_df, user_pos_items, k=10)
    print(f"Epoch {epoch}: Loss={loss:.4f}, Recall@10={results['Recall']:.4f}")

πŸ“ Repository Structure

topic-enhanced-lightgcn/
β”œβ”€β”€ te_lgcn/                    # Python package (importable)
β”‚   β”œβ”€β”€ models/                 # LightGCN and TE-LGCN implementations
β”‚   β”œβ”€β”€ data/                   # Dataset, graph construction
β”‚   β”œβ”€β”€ features/               # Doc2Vec and LDA extractors
β”‚   β”œβ”€β”€ training/               # Trainer and loss functions
β”‚   β”œβ”€β”€ evaluation/             # Metrics (Recall, NDCG, Precision)
β”‚   └── utils/                  # Configuration and logging
β”‚
β”œβ”€β”€ notebooks/                  # Jupyter notebooks organized by research phase
β”‚   β”œβ”€β”€ preprocessing/          # Data preparation and filtering
β”‚   β”œβ”€β”€ feature_extraction/     # Doc2Vec and LDA feature generation
β”‚   β”œβ”€β”€ baselines/              # Baseline LightGCN experiments
β”‚   └── te_lgcn/                # TE-LGCN experiments (k=7,10,15,20)
β”‚
β”œβ”€β”€ configs/                    # YAML configuration files
β”‚   β”œβ”€β”€ default.yaml            # Default hyperparameters
β”‚   └── experiments/            # Experiment-specific configs
β”‚
β”œβ”€β”€ data/                       # Data directory (not included in repo)
β”‚   β”œβ”€β”€ raw/                    # Original datasets
β”‚   β”œβ”€β”€ processed/              # Filtered and split data
β”‚   └── embeddings/             # Doc2Vec embeddings
β”‚
β”œβ”€β”€ docs/                       # Documentation
β”‚   β”œβ”€β”€ pipeline.md             # Research methodology
β”‚   └── implementation_summary.md
β”‚
β”œβ”€β”€ results/                    # Experiment results (git-ignored)
β”œβ”€β”€ scripts/                    # CLI scripts (future)
β”œβ”€β”€ tests/                      # Unit tests (future)
β”‚
β”œβ”€β”€ setup.py                    # Package installation
β”œβ”€β”€ requirements.txt            # Dependencies
β”œβ”€β”€ .gitignore                  # Git exclusions
β”œβ”€β”€ LICENSE                     # MIT License
└── README.md                   # This file

πŸ“Š Data

This project uses the MovieLens dataset with additional movie plot summaries.

Dataset Statistics (k=5 filtered)

  • Users: 671
  • Items: 3,485
  • Interactions: 89,927
  • Sparsity: 96.15%

Download Data

⚠️ Preprocessing Required: This repository provides the raw dataset. You must run preprocessing notebooks to generate train/val/test splits and feature embeddings.

Step 1: Download Raw Data

Download the preprocessed MovieLens dataset from Google Drive:

πŸ“₯ Download TE-LGCN_data.csv from Google Drive

This file contains 99,795 user-item rating interactions (671 users Γ— 9,012 items).

Step 2: Place Data File

# Place the downloaded file in the project root
topic-enhanced-lightgcn/
└── TE-LGCN_data.csv  # ← Place here

Step 3: Run Preprocessing Notebooks

Required preprocessing steps (execute in order):

  1. Data Filtering & Splitting: notebooks/preprocessing/data_preparation.ipynb

    • Applies k-core filtering (k=5, k=10)
    • Creates train/val/test splits (leave-one-out)
    • Generates data/processed/k5_filtered/ and k10_filtered/
  2. Doc2Vec Embeddings: notebooks/feature_extraction/doc2vec_embeddings.ipynb

    • Trains 64-dimensional Doc2Vec embeddings
    • Generates data/embeddings/doc2vec_embeddings_64d.pkl
  3. LDA Topics: notebooks/feature_extraction/lda_topics.ipynb

    • Extracts topic distributions (k=7,10,15,20)
    • Generates data/processed/topic_vectors_*.csv

Note: Update file paths in notebooks if running locally (they use Google Colab paths by default).

See data/README.md for detailed data structure and usage.


βš™οΈ Hyperparameters

Default Configuration

Parameter Value Description
dim 64 Embedding dimension
layers 3 Number of GCN layers
batch_size 1024 Training batch size
lr 1e-3 Learning rate (Adam)
λ₁ 1e-5 L2 regularization weight
Ξ»β‚‚ 1e-3 Content consistency loss weight
k_core 5 Minimum interactions per user/item
n_topics 10 Number of LDA topics

Experiment Configurations

See configs/experiments/ for pre-defined configurations:

  • baseline.yaml - Vanilla LightGCN
  • te_lgcn_k10.yaml - Full TE-LGCN with 10 topics

πŸ§ͺ Experiments

Baseline Comparison

Model Doc2Vec Init Topic Nodes Recall@10 NDCG@10
LightGCN ❌ ❌ 0.159 -
LightGCN + Doc2Vec βœ… ❌ ~0.175 -
TE-LGCN βœ… βœ… 0.200 -

Ablation Study: Number of Topics

Topics (k) Recall@10 Note
k=7 ~0.195 Fewer topics
k=10 ~0.200 Optimal
k=15 ~0.198 More granular
k=20 ~0.196 Too many topics

πŸ“ˆ Evaluation Metrics

Supported metrics (all computed at top-K):

  • Recall@K: Proportion of relevant items retrieved
  • NDCG@K: Normalized Discounted Cumulative Gain
  • Precision@K: Precision of top-K recommendations
  • Hit Rate@K: Whether any relevant item is in top-K

Default evaluation: K=10


πŸ› οΈ Usage Examples

Training with Custom Data

from te_lgcn.data import build_heterogeneous_graph, RecommendationDataset
from torch.utils.data import DataLoader

# Build graph with topic nodes
adj_matrix = build_heterogeneous_graph(
    train_df,
    topic_df,
    n_users=n_users,
    n_items=n_items,
    n_topics=n_topics
)

# Create dataset
dataset = RecommendationDataset(train_df, n_items)
train_loader = DataLoader(dataset, batch_size=1024, shuffle=True)

# Train model (see Quick Start section)

Using Pre-trained Embeddings

from te_lgcn.features import Doc2VecExtractor
import pickle

# Option 1: Train Doc2Vec
extractor = Doc2VecExtractor(vector_size=64, epochs=20)
doc2vec_weights = extractor.fit_transform(item_documents)

# Option 2: Load pre-trained embeddings
with open('data/embeddings/doc2vec_embeddings_64d.pkl', 'rb') as f:
    data = pickle.load(f)
    doc2vec_weights = torch.FloatTensor(data['embeddings'])

Extracting Topics with LDA

from te_lgcn.features import LDAExtractor

extractor = LDAExtractor(n_topics=10)
topic_df = extractor.fit_transform(item_documents)
# Returns DataFrame: [movie_id, topic_id, probability]

πŸ”¬ Research Methodology

The complete research pipeline is documented in docs/pipeline.md:

  1. Data Preprocessing: K-core filtering, leave-one-out splitting
  2. Feature Extraction: Doc2Vec training, LDA topic modeling
  3. Graph Construction: Heterogeneous user-item-topic graph
  4. Model Training: Dual enhancement with content consistency loss
  5. Evaluation: Multiple metrics on test set

🀝 Contributing

Contributions are welcome! Areas for improvement:

  • Add unit tests (tests/)
  • Implement CLI scripts (scripts/train.py, scripts/evaluate.py)
  • Support additional datasets (Amazon, Yelp, etc.)
  • Add more baseline models (NGCF, DGCF, etc.)
  • Hyperparameter tuning with Ray Tune
  • Documentation website (Sphinx)

Please open an issue or pull request for any contributions.


πŸ“„ Citation

If you use this code in your research, please cite:

@software{te_lgcn_2026,
  title={Topic-Enhanced LightGCN: A Dual Enhancement Strategy for Recommendation},
  author={TE-LGCN Research Team},
  year={2025},
  url={https://github.com/yourusername/topic-enhanced-lightgcn}
}

πŸ“œ License

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


πŸ™ Acknowledgments

  • LightGCN: He et al., "LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation", SIGIR 2020
  • MovieLens: Harper and Konstan, "The MovieLens Datasets", ACM TIIS 2015
  • Gensim: ŘehΕ―Ε™ek and Sojka, "Software Framework for Topic Modelling with Large Corpora", 2010

πŸ“ž Contact

For questions or issues:


About

Topic-Enhanced LightGCN (TE-LGCN): A recommendation system using Doc2Vec and LDA for dual semantic enhancement.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages