Downloads · 30 days
8
18% of all-time downloads
cakradana-app/cakradana-v1-ocr-deepseek-3b-adapter
cakradana-v1-ocr-deepseek-3b-adapter is a image-text-to-text model from cakradana-app. Use it for the image-text-to-text task on the model card, and read the license before you ship it in a product. It is set up for peft. The card lists the license as mit.
Downloads · 30 days
8
18% of all-time downloads
All-time downloads
44
Public
Repo size
19.8 MB
Likes
0
Public
Click a slice to open those files.
.json10.1 MB · 51%
From the Hugging Face model README
</div>A LoRA adapter that teaches DeepSeek-OCR to read Indonesian campaign-finance filings
Indonesian candidates and parties file campaign-finance reports — LADK, LPSDK, LPPDK — with the KPU (Komisi Pemilihan Umum). The filings are published, and they are published almost entirely as scanned images with no text layer. A donation record that exists only as pixels cannot be audited at scale.
This is a LoRA adapter for unsloth/DeepSeek-OCR
(2.36 M trainable parameters, 9.0 MiB) that transcribes those pages. It is
inert on its own — it needs the base model.
It was built for Cakradana, an AI system for transparency in Indonesian election financing, which placed 3rd in the Open Sector at the TrackAML 2.0 hackathon run by PPATK, Indonesia's Financial Transaction Reports and Analysis Center.
Greedy decoding, no_repeat_ngram_size=20, max_new_tokens=4096. Baseline and
tuned runs use the same script and the same pages. CER is character error rate
with whitespace collapsed on both sides — lower is better.
eval_scan — the honest numberImage-only pages from held-out publishing hosts, scored against the teacher transcriptions in the dataset. This is the task the adapter exists for.
| metric | base | tuned | |
|---|---|---|---|
| median CER | 0.3511 | 0.1441 | −59% |
| mean CER | 0.4135 | 0.2616 | −37% |
| mean CER, well-formed only | 0.3611 | 0.1383 | −62% |
| runaway generations | 1 | 0 | |
| truncated generations | 0 | 4 | ← regression |
n = 25. The reference is itself a model's reading of a scan, so read the
trend, not the absolute.
The truncation regression is real and is not smoothed away. Four of 25
tuned outputs came in under 60% of reference length, against none for the
baseline. The adapter learned to stop, and on the longest pages it sometimes
stops early. Check len_ratio on your own pages before trusting a
transcription of a dense table.
eval_clean — do not read this as accuracy| metric | base | tuned | |
|---|---|---|---|
| median CER | 0.3796 | 0.0009 | −100% |
| mean CER, well-formed only | 0.2559 | 0.0144 | −94% |
n = 40. A median CER of 0.0009 does not mean the model is 99.9% accurate.
The reference for this bucket is pdftotext -layout output, and the adapter
was trained on exactly that output. The figure measures how well it learned to
imitate one extractor on pages that already had a text layer — a real thing to
have learned, and not a reading accuracy. It is reported for completeness
because the baseline comparison is meaningful; the number itself is not.
Reproduce either bucket:
python scripts/eval_cer.py --buckets eval_scan # tuned
python scripts/eval_cer.py --buckets eval_scan --adapter '' # baseline
The published figures were measured against the private pre-redaction corpus. The script reads the public release, which is a redacted subset, so it selects different pages and will not reproduce them to the digit. It reproduces the comparison.
ds_collator.py is not optional. DeepSeek-OCR registers only AutoConfig
and AutoModel in its auto_map, and ships no preprocessor_config.json and
no processing_*.py — there is no HF Processor for it. Weights plus a
tokenizer will not run. ds_collator.py builds the tensors
DeepseekOCRForCausalLM.forward wants, importing the tiling, padding and
image-token arithmetic from the model's own remote module rather than
reimplementing them.
pip install "transformers==4.57.3" peft unsloth addict
pip uninstall -y torchao # see Environment pins
python scripts/transcribe.py page.jpg
Or from Python:
from scripts.transcribe import load, transcribe
from PIL import Image
model, tok, collator = load() # base + this adapter
text = transcribe(model, tok, collator, Image.open("page.jpg").convert("RGB"))
no_repeat_ngram_size defaults to 20 and should stay set. Without it the model
runs away on dense form pages: one page in an early baseline run produced 19×
the reference length and scored CER 18.9.
| base | unsloth/DeepSeek-OCR, loaded in 4-bit |
| method | LoRA, r=16, alpha=16, dropout 0, bias none |
| trainable | 2,356,224 parameters, 102 tensors |
| scope | language layers only; the vision tower is frozen |
| schedule | 1 epoch, 1,088 optimizer steps, batch 1 × grad-accum 8 |
| optimiser | adamw_8bit, lr 2e-4 linear, warmup ratio 0.03, weight decay 0.01 |
| precision | bf16, sdpa attention |
| seed | 20260819 |
| hardware | 1× A100-SXM4-40GB |
| runtime | 18,980 s (5 h 16 m) |
| final train loss | 0.1105 |
Training data. 8,702 page/text pairs, after dropping duplicate renders and subtracting 25 keys that appeared in both the train and eval buckets. Pages are augmented at load time with a calibrated scan simulation (blur, noise, requantisation, downscale), every draw checked against a legibility floor; measured clamp rate 0.0500.
Labels are pdftotext -layout output with column padding normalised away
and line breaks kept. 29% of raw label characters are whitespace padding that
reproduces the visual grid — an artefact of the extractor, not content on the
page. Training on it teaches the model to emit whitespace grids that every
downstream consumer then has to undo.
The published dataset is a redacted subset of what this run saw. Training
used the private pre-redaction corpus. The public release
(cakradana-kpu-filings-14k-pages)
withholds 3,333 of 17,873 pages that carry — or sit beside something that
carries — an identity number, phone number, address or date of birth, leaving
7,595 train pages against the 8,702 used here. The corpus is otherwise the
same, and the public release is the corresponding citable dataset.
transformers==4.57.3 is load-bearing, not a preference. DeepSeek-OCR's
remote code does
from transformers.models.deepseek_v2.modeling_deepseek_v2 import DeepseekV2MoE.
transformers 5.x renamed that class to DeepseekV2Moe and refactored it:
5.x fuses the experts into experts.gate_up_proj / experts.down_proj, six
tensors per block, while the published checkpoint stores them per-expert as
mlp.experts.{0..63}.{gate,up,down}_proj.weight — 2,112 tensors across its
11 MoE layers, plus 33 more for the shared experts. Under 5.x none of them
match, so they are randomly initialised — and the model still loads, still
runs, and is wrong.
scripts/transcribe.py checks both the import and the expert layout and exits
rather than running on random weights. A correct load reports only
model.vision_model.embeddings.position_ids as newly initialised; anything
mentioning experts means the weights did not bind.
Two more, both found the hard way:
addict — the remote modeling file imports it and most environments do
not ship it. It surfaces as an ImportError inside from_pretrained.pip uninstall -y torchao — peft calls is_torchao_available(), which
raises rather than returning False on some builds, killing
get_peft_model.flash_attention_2 is unavailable on stock Colab, which ships xformers rather
than flash_attn. Ampere is necessary but not sufficient: detect it by
importing flash_attn, never by compute capability, and fall back to sdpa.
That costs throughput, not correctness.
self_attn.{q,k,v,o}_proj adapters, but
mlp.{gate,up,down}_proj appears for layer 0 alone. The base config sets
first_k_dense_replace: 1, so layer 0 is the only dense MLP and layers 1–11
are MoE, putting their FFN weights at mlp.experts.N.{gate,up,down}_proj and
mlp.shared_experts.*. Matching the target_modules regex in
adapter_config.json against the base model's tensor
index: of 2,207 MLP modules it matches exactly 3, all on layer 0. The
gains above came from attention alone; extending the regex to reach the
experts is the obvious v2 experiment, and this run's CER is its baseline.eval_scan references are model-generated, so its absolute CER is not a
ground-truth accuracy. eval_clean references are extractor output. Neither
bucket has human-transcribed ground truth.MIT, matching the base model. That covers the weights; it does not release you
from the terms of the corpus they were trained on, which prohibit attempting to
re-identify individuals and use for harassment or profiling. See
LICENSE.
Made with ❤️ by the Cakradana Team · cakradana.faizath.com
</div>