Instructions to use Adiutant/colsmol-printfix-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use Adiutant/colsmol-printfix-lora with sentence-transformers:
from sentence_transformers import MultiVectorEncoder model = MultiVectorEncoder("Adiutant/colsmol-printfix-lora") queries = ["Which planet is known as the Red Planet?"] documents = [ "Venus is often called Earth's twin because of its similar size and proximity.", "Mars, known for its reddish appearance, is often referred to as the Red Planet.", "Jupiter, the largest planet in our solar system, has a prominent red spot.", ] query_embeddings = model.encode_query(queries) document_embeddings = model.encode_document(documents) similarities = model.similarity(query_embeddings, document_embeddings) print(similarities) - ColPali
How to use Adiutant/colsmol-printfix-lora with ColPali:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Print-safe ColSmol adapters for page retrieval (RU documents)
Small adapters on top of the pinned base vidore/colSmol-256M
(c79b633e17e060cc109b11aa2bf92a1517d3bd6f) that make late-interaction page
retrieval work on Russian scanned forms where printed fields and handwritten
entries live on the same page. Each page is one document; queries are short
text values from a field (an INN, a MAC address, a surname, a date).
The plain vision-LoRA recipe improves handwriting a lot but breaks the printed control (printed Hit@10 0.667 β 0.604, printed MRR 0.356 β 0.236). Both adapters here fix that, in two different ways.
| Adapter | Tensors | What was trained | Selection hand MRR@10 | Selection print MRR@10 | Selection print Hit@10 |
|---|---|---|---|---|---|
| zero-shot base | β | β | 0.2106 | 0.3563 | 0.6667 |
printfix_dense (default) |
2 | Dense projection head only | 0.3675 | 0.3533 | 0.6667 |
printfix_anchor |
146 | vision LoRA + Dense head, printed-page anchor loss | 0.4462 | 0.3081 | 0.6667 |
| plain LoRA (not shipped) | 146 | vision LoRA + Dense head, no regularisation | 0.4406 | 0.2359 | 0.6042 |
Why it happens: the LoRA sits on the vision encoder only, so page embeddings
drift while text queries (including printed ones) stay fixed. printfix_dense
never touches the encoder, and printfix_anchor penalises cosine drift of
printed pages away from their zero-shot embeddings during training.
Locked-v3 result (preregistered, single run)
printfix_dense was evaluated once on a frozen 50-page / 22-query set that was
never used for training or selection, under a rule registered before the run
(overall β₯ 14/22, handwriting β₯ 5/10, printed β₯ 8/12, and per-kind
non-inferiority against a fresh same-runtime zero-shot):
| System | overall Hit@10 | handwriting (10) | printed (12) | overall MRR@10 |
|---|---|---|---|---|
| fresh zero-shot | 17/22 | 6/10 | 11/12 | 0.4706 |
| printfix_dense | 19/22 | 8/10 | 11/12 | 0.6542 |
verdict.passed = true. The printed block is not just preserved β its MRR rose
from 0.5544 to 0.6708 on that set. The full verdict, both systems and every
per-query rank are in the adapter's sidecar JSON
(adapters/printfix_dense.json β locked_v3).
Training
- data: 789 training pairs (405 handwritten + 384 printed) over 96 pages; selection 178 pairs over 24 pages, page-disjoint from training;
- loss: multi-positive InfoNCE over 1 positive + 4 sampled negatives, temperature 1.0, seed 13, AdamW, lr 1e-4, weight decay 0.01, 3 epochs. Only the adapter's own tensors are trainable; the base stays frozen;
printfix_anchoradds2.0 Γ mean(1 β cos(page_embedding, zero_shot_embedding))for printed-control training steps, with the zero-shot embeddings cached for all 96 training pages;- every run is reproducible from the sidecar JSONs: they record data SHA256s, hyper-parameters, the training report hash and the source checkpoint hash.
Usage
pip install -r requirements.txt
# index a folder of page scans (CPU or --device cuda:0)
python colsmol_adapter_cli.py index scans/*.png --index-dir index/
# search by a field value
python colsmol_adapter_cli.py search "4500033696!" --index-dir index/ --top-k 5
python colsmol_adapter_cli.py search "ΠΠΠΠ ΠΠΠΠΠΠΠ― ΠΠΠ‘ΠΠΠΠ¦ΠΠ―" --index-dir index/ --json
# the other adapter, or the stock base
python colsmol_adapter_cli.py index scans/*.png --index-dir index-anchor/ --adapter printfix_anchor
python colsmol_adapter_cli.py index scans/*.png --index-dir index-stock/ --no-adapter
The CLI stores per-page multi-vector embeddings (fp16, index.pt) plus a
manifest (index.json) that records the base revision and the adapter SHA256.
An index built with an adapter cannot be searched without it, or with a
different adapter β the CLI stops with an explicit error instead of silently
mixing representations. Re-running index on the same directory only adds
pages that are not there yet.
Typical cost on CPU (single core-bound process, ColSmol-256M): about 6β13 s per page for indexing, tens of milliseconds per query for up to a few thousand pages; store roughly 0.23 MiB per page (fp16, ~945 vectors Γ 128 dims).
Files
| File | Contents |
|---|---|
colsmol_adapter_cli.py |
self-contained index/search CLI |
adapters/printfix_dense.safetensors + .json |
default adapter (2 tensors) and its provenance/verdict |
adapters/printfix_anchor.safetensors + .json |
LoRA-anchored adapter (146 tensors) and its provenance |
requirements.txt |
torch, sentence-transformers, peft, safetensors, Pillow |
LICENSE |
MIT for the adapters (base model keeps its own license) |
Limitations
- The locked evaluation is small: 50 pages, 22 queries, one registered run. Treat the numbers as evidence, not as a guarantee.
- Domain: Russian scanned bank/administrative forms with a mix of printed and handwritten fields. Other languages, layouts and photo captures were not measured.
- Documents are whole pages, not field crops; a query is matched against the entire page, so very small fields on dense pages are the hard case.
- The adapters assume the pinned base revision. A different base checkpoint is rejected.
printfix_anchorbrings printed Hit@10 back to the zero-shot level but its printed MRR stays below zero-shot (0.308 vs 0.356); if printed quality is the priority, useprintfix_dense.
License
Adapters: MIT (see LICENSE). The base vidore/colSmol-256M keeps its own
license (SmolVLM-256M backbone Apache-2.0, ColSmol adapters MIT β permissive,
but read the model card). Training data was internal annotated scans; only
aggregated metrics and hashes are published here, no page images.
Model tree for Adiutant/colsmol-printfix-lora
Base model
HuggingFaceTB/SmolLM2-135M