Skip to main content

Pretense

Pretraining sentence transformers with retrieval-oriented objectives.

Pretense supports:

  • RetroMAE
  • DupMAE
  • Condenser
  • coCondenser
  • Contriever
  • supervised pairwise contrastive training
  • Multiple Negatives Ranking Loss (MNRL)
  • cached MNRL (CMNRL)
  • supervised and unsupervised SimCSE

Training uses Hugging Face Transformers and Accelerate, accepts Hugging Face Datasets or ordinary PyTorch datasets, and produces encoders that load in Transformers and Sentence Transformers 5.x or 6.x.

Installation

uv add pretense

Python 3.10 or newer is required. CUDA-enabled PyTorch should be selected using the appropriate uv/PyTorch index for the target system.

Pretense supports PyTorch 2.2 and newer without choosing or replacing a particular CUDA build. Restoring a complete Trainer checkpoint, including optimizer and scheduler state, requires PyTorch 2.6 or newer because Transformers blocks torch.load checkpoint restoration on earlier releases. Weights-only Pretense checkpoints use safetensors and remain loadable on every supported version.

For development from a source checkout, use uv sync --extra dev instead. The core install accepts ordinary Python or PyTorch datasets without installing Hugging Face Datasets. To pass a datasets.Dataset directly or run the bundled examples, install the optional dependency with uv add "pretense[examples]".

Train with the Python SDK

PretenseTrainer follows the Hugging Face Trainer interface:

from transformers import AutoTokenizer

from pretense import (
    MAECollator,
    MethodConfig,
    PretenseTrainer,
    PretenseTrainingArguments,
    load_pretraining_model,
)

model_name = "google-bert/bert-base-uncased"
method = MethodConfig(name="retromae")
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = load_pretraining_model(method, model_name)
dataset = [
    {"text": "Dense retrieval maps queries and passages into a shared embedding space."},
    {"text": "Masked autoencoders learn representations by reconstructing corrupted text."},
    {"text": "Sentence transformers produce reusable fixed-size text embeddings."},
    {"text": "In-batch negatives make contrastive learning efficient."},
]

trainer = PretenseTrainer(
    model=model,
    args=PretenseTrainingArguments(
        output_dir="outputs/retromae",
        per_device_train_batch_size=16,
        learning_rate=5e-5,
        num_train_epochs=1,
    ),
    train_dataset=dataset,
    data_collator=MAECollator(tokenizer=tokenizer, text_column="text"),
    processing_class=tokenizer,
)
trainer.train()
trainer.save_model("outputs/retromae/final")

The trainer accepts the same callbacks, optimizers, schedulers, evaluation datasets, and metrics as transformers.Trainer. Ordinary transformers.TrainingArguments are also supported. When the dataset uses the standard columns shown below, the trainer can select the collator automatically; pass a collator explicitly for custom column names or explicit MNRL negatives.

For complete Python workflows, including programmatic models and Sentence Transformers fine-tuning, see the examples.

Training produces regular console and training_log.jsonl metrics and resumable checkpoint-* directories. See training and checkpointing for evaluation, retention, callbacks, experiment trackers, recovery after interruption, and exporting.

Export a trained model explicitly when it is ready for downstream use:

from pretense import export_sentence_transformer
from transformers import AutoModel
from sentence_transformers import SentenceTransformer

export_dir = export_sentence_transformer(
    trainer.model,
    tokenizer,
    "outputs/retromae/sentence-transformers",
)
sentence_model = SentenceTransformer(str(export_dir))
encoder = AutoModel.from_pretrained(export_dir / "0_Transformer")

The Sentence Transformers directory is the canonical export. It includes the complete Hugging Face backbone under 0_Transformer/, so separate copies of the model weights are unnecessary. For a Hub export, load that backbone with AutoModel.from_pretrained(repo_id, subfolder="0_Transformer").

Supported methods

Method Objectives Required input
RetroMAE encoder MLM + CLS-conditioned reconstruction text
DupMAE RetroMAE + ordinary-token bag-of-words prediction text
Condenser skip-connected head MLM + late MLM text
coCondenser Condenser + paired-span, cross-device contrastive loss documents or paired spans
Contriever augmented-view MoCo contrastive learning text
Contrastive supervised pairwise margin loss two text columns + binary label
MNRL paired retrieval ranking with in-batch and optional explicit negatives query + positive, optionally negative columns
CMNRL memory-efficient GradCache MNRL query + positive, optionally negative columns
SimCSE dropout-view or supervised NLI contrastive learning text, or premise + entailment + optional contradiction

See the method notes for input formats, configuration, pooling behavior, distributed-training caveats, and architecture support. Separate guides cover custom models and FlashAttention.

Development

uv run ruff check .
uv run mypy src/pretense
uv run pytest
uv build --no-sources

Pretense targets objective and architecture parity, not guaranteed reproduction of paper benchmark scores. See the method notes and release documentation.

Attribution

The implementation draws on the following papers and reference projects:

Cite the corresponding paper when publishing results. Pretense is licensed under Apache-2.0.

Metadata

Release files for pretense 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pretense 0.1.1
File Size Uploaded Provenance
pretense-0.1.1.tar.gz 291.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pretense 0.1.1
File Interpreter ABI Platform
pretense-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 324.9 kB

Release files / pretense-0.1.1.tar.gz

Download URL pretense-0.1.1.tar.gz
Size 291.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b734c252f4193ca9e685979a66698e53d58d72f7d2820ccd1e33f9731510e0d9
BLAKE2b-256 checksum
How to use checksums
69d494574b630c894a5cd21c4760cd8524a6ce4d9593ddf406a2f610ce05b717
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pretense-0.1.1-py3-none-any.whl

Download URL pretense-0.1.1-py3-none-any.whl
Size 33.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e15e799cf12dab3f94e0a625f3ed21d9b27726f98245f33d97a5b47eecbd295
BLAKE2b-256 checksum
How to use checksums
d53e34b8a716f6cb5cf38d5fc14a5ac27e2419f2204ff8986d6f6f5e28c1871d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pretense 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page