How contrastive-lm/clm works
CLM serves contrastive state–action scoring as typed decisions and candidate ranking. The primary workflow is a caller or playground sending a state and questions/candidates to the API; the server delegates scoring to the inference engine, which embeds text, applies projection heads, and returns distributions or rankings. Separate repository capabilities support adapting heads to downstream data and evaluating trajectory selection. The README documents broader pre-, mid-, and post-training, but the sampled source chiefly evidences fine-tuning and evaluation; the graph avoids guessing their full implementation.
Main entry points: engine.py Inference engine · finetune.py Head fine-tuning · server.py HTTP API · hf_embeddings.py Embedding conversion
Components 18
API serving
- Python client
src/clm/client.py - HTTP API
src/clm/server.py - Question schema
src/clm/schema.py
Scoring engine
- Inference engine
src/clm/engine.py - Embedding client
src/clm/embedder.py - Projection heads
src/clm/heads.py - Vector cache
src/clm/cache.py
Model adaptation
- Data adapters
train/adapters.py - Training embeddings
train/embed_utils.py - Head fine-tuning
train/finetune.py - Embedding conversion
preprocessing/hf_embeddings.py - Trajectory evaluation
evaluation/bon_eval.py
Playground
- Web playground
src/clm/static/app.js
Other components
- Agent or caller
- Embedding service
- Model checkpoints
- Playground user
- Hugging Face data and models
Connections 19
- Agent or caller → Python client: calls
- Python client → HTTP API: sends requests
- HTTP API → Inference engine: dispatches scoring
- HTTP API → Question schema: validates questions
- Inference engine → Embedding client: requests embeddings
- Embedding client → Embedding service: sends text
- Inference engine → Projection heads: scores with
- Inference engine → Vector cache: reads and writes
- Inference engine → Model checkpoints: loads weights
- Playground user → Web playground: uses
- Web playground → HTTP API: posts requests
- Head fine-tuning → Data adapters: loads examples
- Head fine-tuning → Training embeddings: embeds training text
- Training embeddings → Embedding service: requests embeddings
- Head fine-tuning → Embedding conversion: uses embedding data
- Embedding conversion → Hugging Face data and models: downloads or uploads
- Head fine-tuning → Model checkpoints: writes trained heads
- Trajectory evaluation → Model checkpoints: loads heads
- Trajectory evaluation → Embedding conversion: reads embedding data