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.
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
| Model | Recall@10 | Improvement |
|---|---|---|
| Baseline LightGCN | ~0.159 | - |
| TE-LGCN (k=10) | ~0.200 | +26.4% |
- Pre-trained document embeddings initialize item representations
- Captures semantic similarity from textual content
- Reduces cold-start issues for new items
- Topic nodes create semantic bridges in the graph
- Heterogeneous graph: User-Item-Topic connections
- Enables recommendation via shared topic preferences
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
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- Python 3.8+
- PyTorch 2.0+
- CUDA (optional, for GPU acceleration)
# 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 .Core libraries:
torch>=2.0.0- Deep learning frameworkgensim>=4.0.0- Doc2Vec and LDA implementationpandas,numpy,scipy- Data processingscikit-learn- Additional ML utilities
Follow the execution sequence in notebooks/README.md:
- Data Preprocessing:
notebooks/preprocessing/data_preparation.ipynb - Feature Extraction:
notebooks/feature_extraction/doc2vec_embeddings.ipynbnotebooks/feature_extraction/lda_topics.ipynb
- Baseline:
notebooks/baselines/lightgcn_baseline.ipynb - TE-LGCN:
notebooks/te_lgcn/te_lgcn_k10.ipynb
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}")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
This project uses the MovieLens dataset with additional movie plot summaries.
- Users: 671
- Items: 3,485
- Interactions: 89,927
- Sparsity: 96.15%
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).
# Place the downloaded file in the project root
topic-enhanced-lightgcn/
βββ TE-LGCN_data.csv # β Place hereRequired preprocessing steps (execute in order):
-
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/andk10_filtered/
-
Doc2Vec Embeddings:
notebooks/feature_extraction/doc2vec_embeddings.ipynb- Trains 64-dimensional Doc2Vec embeddings
- Generates
data/embeddings/doc2vec_embeddings_64d.pkl
-
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.
| 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 |
See configs/experiments/ for pre-defined configurations:
baseline.yaml- Vanilla LightGCNte_lgcn_k10.yaml- Full TE-LGCN with 10 topics
| Model | Doc2Vec Init | Topic Nodes | Recall@10 | NDCG@10 |
|---|---|---|---|---|
| LightGCN | β | β | 0.159 | - |
| LightGCN + Doc2Vec | β | β | ~0.175 | - |
| TE-LGCN | β | β | 0.200 | - |
| 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 |
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
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)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'])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]The complete research pipeline is documented in docs/pipeline.md:
- Data Preprocessing: K-core filtering, leave-one-out splitting
- Feature Extraction: Doc2Vec training, LDA topic modeling
- Graph Construction: Heterogeneous user-item-topic graph
- Model Training: Dual enhancement with content consistency loss
- Evaluation: Multiple metrics on test set
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.
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}
}This project is licensed under the MIT License - see the LICENSE file for details.
- 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
For questions or issues:
- Issues: GitHub Issues
- Email: hueny0238@gmail.com