Instructions to use ASHu2/openT2L-skill-alfa-cbc with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use ASHu2/openT2L-skill-alfa-cbc with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Blood-count skill for MiniCPM-V-4.7-1B (emitted from 4 example pages)
A rank-8 LoRA adapter that teaches MiniCPM-V-4.7-1B to read the complete blood count (CBC) reports printed by one lab, including the differential count, which the base model skips.
Nobody trained this adapter. The openT2L hypernetwork wrote it in a single forward pass after seeing 4 corrected example pages. That took 34 seconds on one A10G GPU, and the adapter is 3.6 MB.
The problem
Ask the base model to "extract every test row" from a CBC and it reads the first 9 rows (haemoglobin through white cell count), then stops. The differential count below them (basophils, eosinophils, stab, segmented, lymphocytes, monocytes) is left out. On 8 test pages it returned 0 of 96 differential values.
The prompt never says that the differential rows count as test rows. The 4 example pages show it, and the emitted adapter picks it up.
Results
Same prompt, same greedy decoding, same A10G, 8 pages the hypernetwork never saw (all from the same lab):
| Base model | With this adapter | |
|---|---|---|
| Field F1 | 0.496 | 0.733 |
| Recall | 0.356 | 0.701 |
| Precision | 0.817 | 0.769 |
| Differential values read (of 96) | 0 | 44 |
| Main CBC values read (of 72) | 51 | 59 |
| Pages better | 8 of 8 |
Field F1 counts matches of (field, value) pairs after Unicode and whitespace normalisation, with list order ignored.
Limitations, stated plainly:
- The adapter reads 44 of 48 differential percentage values (all six on 6 of the 8 reports) but none of the 48 absolute counts: it labels them "Absolute Count" instead of naming the cell.
- On 7 of 8 reports it adds a "Differential Count" heading as a row; on 2 of them that shifts the percentages down by one row.
- Precision is a little lower than the base model's: some rows have the right value under a slightly wrong name or unit.
- Both models misread the platelet count on one page.
- This is one lab layout (Alfa Laboratories, Egypt) and 8 test pages. Other labs' CBC layouts were not tested with this adapter.
- An earlier attempt with a nested schema (a separate
differentialsection) made results worse, 0.51 F1 vs 0.85 for the base model. The hypernetwork was trained on single-list schemas, so use the flat prompt below.
Use
import torch
from transformers import AutoModelForImageTextToText, AutoProcessor
from peft import PeftModel
MODEL = "openbmb/MiniCPM-V-4.7-1B"
PROC = dict(downsample_mode="16x", max_slice_nums=9, enable_thinking=False) # settings the adapter was made with
proc = AutoProcessor.from_pretrained(MODEL)
model = AutoModelForImageTextToText.from_pretrained(MODEL, dtype=torch.bfloat16, device_map="cuda").eval()
model = PeftModel.from_pretrained(model, "ASHu2/openT2L-skill-alfa-cbc", subfolder="adapter")
prompt = ("Extract the lab unit and every test row from this lab report.\n"
'Return only JSON with this shape: {"unit": str, "tests": [{"name": str, "result": str, "unit": str, "range": str}]}\n'
"Copy text exactly as printed. Use an empty string or empty list when a field is absent.")
msgs = [{"role": "user", "content": [{"type": "image", "path": "cbc_page.jpg"}, {"type": "text", "text": prompt}]}]
inp = proc.apply_chat_template(msgs, tokenize=True, add_generation_prompt=True, return_dict=True,
return_tensors="pt", **PROC).to(model.device)
out = model.generate(**inp, downsample_mode="16x", max_new_tokens=1024, do_sample=False)
print(proc.batch_decode(out[:, inp["input_ids"].shape[1]:], skip_special_tokens=True)[0])
skill.json holds the exact prompt and the names of the 4 example pages.
How it was made
- Hypernetwork: ASHu2/openT2L-MiniCPM-V-4.7-1B-docs (72M parameters, trained on 365 document-extraction tasks. Lab reports were not among them: the synthetic lab-report templates were one of the held-out test domains).
- Example pages: 4 Alfa Laboratories CBC reports (
train_102,train_107,train_108,train_113), each with its correct JSON. - Targets: rank 8, alpha 16, on the language model's full-attention q/v projections and linear-attention
in_proj_qkv/out_proj(48 modules). - Labels for all 12 pages were drafted from the images and checked by a person against every page.
- Code and full outputs: openBMB-spark-t2l (
agent/runtime.py,modal_app/agent_test.py, run AG-04).
Licence and data
- Non-commercial (CC BY-NC 4.0). The hypernetwork that produced this adapter is non-commercial because some of its training datasets are.
- Lab report images: Clinical Laboratory Test Reports, Mendeley Data, DOI 10.17632/bygfmk4rx9.2, CC BY 4.0. No images are included in this repository.
- Not a medical device. Check any extracted value against the original report.
- Downloads last month
- -
Model tree for ASHu2/openT2L-skill-alfa-cbc
Base model
openbmb/MiniCPM-V-4.7-1B