Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Neural Ad-Ranking & CTR Prediction

End-to-end click-through-rate prediction system built around a DCN-v2 model, stable C++ feature hashing, calibrated inference, Redis-backed calibration overrides, and a production-style gRPC serving API.

The project is designed for the 45M-example Criteo display advertising dataset and includes a lightweight synthetic path so the full train -> checkpoint -> predict loop can be tested locally without shipping the dataset.

Highlights

  • DCN-v2 CTR model in PyTorch with hashed categorical embeddings and explicit two-way feature crosses.
  • Streaming Criteo TSV loader for 13 dense features and 26 categorical features.
  • Custom pybind11 C++ feature hashing extension with a deterministic Python fallback.
  • Platt-style sigmoid calibration saved in checkpoints and optionally overridden from Redis.
  • gRPC API with single and batch prediction RPCs.
  • Smoke tests that train a tiny model, reload the checkpoint, and run calibrated prediction.

Architecture

flowchart LR
    A["Criteo TSV or synthetic data"] --> B["CriteoPreprocessor"]
    B --> C["C++ / Python feature hashing"]
    C --> D["Hashed embeddings + dense features"]
    D --> E["DCN-v2 cross network"]
    D --> F["Deep MLP tower"]
    E --> G["CTR logit"]
    F --> G
    G --> H["Sigmoid calibration"]
    H --> I["gRPC Predict / BatchPredict"]
    J["Redis calibration key"] --> H
Loading

Quickstart

Use Python 3.11 or 3.12. PyTorch wheels are not expected to work on the Homebrew Python 3.14 interpreter.

python3.12 -m venv .venv
. .venv/bin/activate
python -m pip install -e ".[dev]"
make PYTHON=.venv/bin/python proto
pytest

Train a tiny smoke checkpoint:

ad-ranker train \
  --config configs/dcnv2_criteo.yaml \
  --synthetic-examples 4096 \
  --epochs 1 \
  --output artifacts/smoke_model.pt

Run a local prediction:

ad-ranker predict \
  --checkpoint artifacts/smoke_model.pt \
  --features examples/sample_request.json

Training On Criteo

Download the Criteo display advertising dataset separately and keep it under data/, which is intentionally gitignored.

Expected TSV column order:

label, I1-I13, C1-C26

Run training:

ad-ranker train \
  --config configs/dcnv2_criteo.yaml \
  --data data/criteo/train.txt \
  --validation-data data/criteo/test.txt \
  --epochs 2 \
  --output artifacts/dcnv2_criteo.pt

The resume benchmark target for this project is 0.806 test AUC on Criteo with hashed categorical embeddings and feature crosses. The checked-in tests use synthetic data only, so they validate the pipeline mechanics rather than reproducing the full benchmark.

Serving

Start Redis if you want runtime calibration overrides:

docker compose up redis

Serve a checkpoint:

ad-ranker serve \
  --checkpoint artifacts/dcnv2_criteo.pt \
  --host 0.0.0.0 \
  --port 50051 \
  --redis-url redis://localhost:6379/0

The gRPC service is defined in proto/ad_rank.proto. It exposes:

  • Predict(PredictRequest) -> PredictResponse
  • BatchPredict(BatchPredictRequest) -> BatchPredictResponse

Benchmark a running server:

python scripts/benchmark_grpc.py \
  --target localhost:50051 \
  --requests 2000 \
  --concurrency 32

Calibration

Checkpoints store a sigmoid calibrator:

{"scale": 1.0, "bias": 0.0}

At serving time, Redis can override it from key ad_ranker:calibration:

redis-cli set ad_ranker:calibration '{"scale": 0.97, "bias": -0.04}'

This lets calibration be refreshed without rebuilding the model artifact.

Repository Layout

cpp/                         pybind11 C++ feature hashing module
configs/                     DCN-v2 Criteo training config
proto/                       gRPC service definition
scripts/                     protobuf helper and latency benchmark
src/neural_ad_ranking/       package source
tests/                       hashing, model, training, prediction smoke tests

Validation

Current local validation:

6 passed

The smoke suite confirms deterministic hashing, feature-cross preprocessing, DCN-v2 forward shape, checkpoint creation, checkpoint reload, and calibrated prediction.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages