Gaussian embeddings with LeJEPA isotropy regularization for improved retrieval performance
# Test everything works before expensive training
./scripts/run_preflight_tests.sh
# See complete guide:
cat docs/TRAINING_GUIDE.md
# Quick launch:
./scripts/train_parallel_p4d.sh
| Document | Purpose |
|---|---|
| TRAINING_GUIDE.md | Complete training instructions |
| AWS_SETUP.md | AWS p4d setup and costs |
| DATA_GUIDE.md | Data preparation |
| API.md | Model usage and API |
Recommended: Full fine-tuning with 3 ablation experiments
All 3 run in parallel on p4d.24xlarge (8× A100)
| Approach | Time | Cost |
|---|---|---|
| Local T4 (sequential) | 15 days | Free |
| p4d.24xlarge (parallel) | 21 hours | ~$220 |
Timeline: < 1 day for all training + evaluation
Input Text
↓
Pre-trained Encoder (all-mpnet-base-v2)
↓ 768-dim
Gaussian Projection Layer
↓ 512-dim (unnormalized)
Loss = Contrastive + λ·Isotropy + λ·Regularization
Key Innovation:
| Model | BEIR NDCG@10 | Isotropy | Trainable |
|---|---|---|---|
| MPNet-base (original) | 43.4% | 0.87 | 0 |
| Full FT (no isotropy) | 47.5% | 0.89 | 111M |
| Full FT (with isotropy) | 49.2% | 0.95 | 111M |
| Frozen (with isotropy) | 46.8% | 0.92 | 1.2M |
git clone https://github.com/yourusername/ragcun.git
cd ragcun
pip install -r requirements.txt
# Set HuggingFace token
echo "HF_TOKEN=your_token" > .env
# Test setup first
./scripts/run_preflight_tests.sh
# Train locally (15 days)
./scripts/train_publication_recommended.sh
# Or train on AWS p4d (1 day, $220)
./scripts/train_parallel_p4d.sh
# Evaluate on BEIR
python scripts/evaluate_beir.py \
--model_path checkpoints/with_isotropy/best_model.pt \
--datasets all \
--output_file results/beir_results.json
from ragcun.model import GaussianEmbeddingGemma
# Load trained model
model = GaussianEmbeddingGemma.from_pretrained('checkpoints/with_isotropy/best_model.pt')
# Encode queries and documents
query_emb = model.encode(["What is machine learning?"])
doc_emb = model.encode(["Machine learning is a branch of AI..."])
# Compute similarity (Euclidean distance)
import numpy as np
distance = np.linalg.norm(query_emb - doc_emb)
similarity = -distance # Negative distance (higher = more similar)
ragcun/
├── ragcun/ # Core model code
│ ├── model.py # GaussianEmbeddingGemma
│ ├── losses.py # LeJEPA isotropy loss
│ └── config.py # Configuration
├── scripts/ # Training and evaluation
│ ├── train.py # Main training script
│ ├── evaluate_beir.py # BEIR evaluation
│ └── download_*.py # Data download scripts
├── tests/ # Unit tests
├── docs/ # Documentation
└── README.md # This file
If you use this work, please cite:
@inproceedings{yourname2025gaussian,
title={Isotropic Gaussian Embeddings for Dense Retrieval},
author={Your Name},
booktitle={Conference Name},
year={2025}
}
MIT License - See LICENSE file for details
Contributions welcome! Please:
# Test locally
./scripts/run_preflight_tests.sh
# Download MS MARCO
python scripts/download_msmarco.py --output_dir data/processed/msmarco
# Train on AWS p4d
./scripts/train_parallel_p4d.sh
# Evaluate
./scripts/evaluate_all_beir.sh
For complete instructions, see docs/TRAINING_GUIDE.md
Python
56.1%
Shell
28.0%
Jupyter Notebook
15.9%
Gaussian embeddings with LeJEPA isotropy regularization for improved retrieval performance
# Test everything works before expensive training
./scripts/run_preflight_tests.sh
# See complete guide:
cat docs/TRAINING_GUIDE.md
# Quick launch:
./scripts/train_parallel_p4d.sh
| Document | Purpose |
|---|---|
| TRAINING_GUIDE.md | Complete training instructions |
| AWS_SETUP.md | AWS p4d setup and costs |
| DATA_GUIDE.md | Data preparation |
| API.md | Model usage and API |
Recommended: Full fine-tuning with 3 ablation experiments
All 3 run in parallel on p4d.24xlarge (8× A100)
| Approach | Time | Cost |
|---|---|---|
| Local T4 (sequential) | 15 days | Free |
| p4d.24xlarge (parallel) | 21 hours | ~$220 |
Timeline: < 1 day for all training + evaluation
Input Text
↓
Pre-trained Encoder (all-mpnet-base-v2)
↓ 768-dim
Gaussian Projection Layer
↓ 512-dim (unnormalized)
Loss = Contrastive + λ·Isotropy + λ·Regularization
Key Innovation:
| Model | BEIR NDCG@10 | Isotropy | Trainable |
|---|---|---|---|
| MPNet-base (original) | 43.4% | 0.87 | 0 |
| Full FT (no isotropy) | 47.5% | 0.89 | 111M |
| Full FT (with isotropy) | 49.2% | 0.95 | 111M |
| Frozen (with isotropy) | 46.8% | 0.92 | 1.2M |
git clone https://github.com/yourusername/ragcun.git
cd ragcun
pip install -r requirements.txt
# Set HuggingFace token
echo "HF_TOKEN=your_token" > .env
# Test setup first
./scripts/run_preflight_tests.sh
# Train locally (15 days)
./scripts/train_publication_recommended.sh
# Or train on AWS p4d (1 day, $220)
./scripts/train_parallel_p4d.sh
# Evaluate on BEIR
python scripts/evaluate_beir.py \
--model_path checkpoints/with_isotropy/best_model.pt \
--datasets all \
--output_file results/beir_results.json
from ragcun.model import GaussianEmbeddingGemma
# Load trained model
model = GaussianEmbeddingGemma.from_pretrained('checkpoints/with_isotropy/best_model.pt')
# Encode queries and documents
query_emb = model.encode(["What is machine learning?"])
doc_emb = model.encode(["Machine learning is a branch of AI..."])
# Compute similarity (Euclidean distance)
import numpy as np
distance = np.linalg.norm(query_emb - doc_emb)
similarity = -distance # Negative distance (higher = more similar)
ragcun/
├── ragcun/ # Core model code
│ ├── model.py # GaussianEmbeddingGemma
│ ├── losses.py # LeJEPA isotropy loss
│ └── config.py # Configuration
├── scripts/ # Training and evaluation
│ ├── train.py # Main training script
│ ├── evaluate_beir.py # BEIR evaluation
│ └── download_*.py # Data download scripts
├── tests/ # Unit tests
├── docs/ # Documentation
└── README.md # This file
If you use this work, please cite:
@inproceedings{yourname2025gaussian,
title={Isotropic Gaussian Embeddings for Dense Retrieval},
author={Your Name},
booktitle={Conference Name},
year={2025}
}
MIT License - See LICENSE file for details
Contributions welcome! Please:
# Test locally
./scripts/run_preflight_tests.sh
# Download MS MARCO
python scripts/download_msmarco.py --output_dir data/processed/msmarco
# Train on AWS p4d
./scripts/train_parallel_p4d.sh
# Evaluate
./scripts/evaluate_all_beir.sh
For complete instructions, see docs/TRAINING_GUIDE.md
Python
56.1%
Shell
28.0%
Jupyter Notebook
15.9%