Image-Text-to-Text
PEFT
Safetensors
English
lora
hypernetwork
text-to-lora
document-understanding
information-extraction
lab-report
minicpm-v
Run this model with HF Jobs
Run ASHu2/openT2L-skill-alfa-cbc on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/ASHu2/openT2L-skill-alfa-cbc. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/ASHu2/openT2L-skill-alfa-cbc on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/ASHu2/openT2L-skill-alfa-cbc. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/ASHu2/openT2L-skill-alfa-cbc. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
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
|
Download README.md from ASHu2/openT2L-skill-alfa-cbc: direct link, hf CLI and curl.
- Browser
- Download file 5.42 kB
-
https://huggingface.co/ASHu2/openT2L-skill-alfa-cbc/resolve/main/README.md
- Command line
-
hf download hf://ASHu2/openT2L-skill-alfa-cbc/README.md
-
curl -L -o README.md https://huggingface.co/ASHu2/openT2L-skill-alfa-cbc/resolve/main/README.md
5.42 kB
| license: cc-by-nc-4.0 | |
| base_model: openbmb/MiniCPM-V-4.7-1B | |
| library_name: peft | |
| pipeline_tag: image-text-to-text | |
| tags: | |
| - lora | |
| - peft | |
| - hypernetwork | |
| - text-to-lora | |
| - document-understanding | |
| - information-extraction | |
| - lab-report | |
| - minicpm-v | |
| language: | |
| - en | |
| # 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](https://huggingface.co/openbmb/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](https://huggingface.co/ASHu2/openT2L-MiniCPM-V-4.7-1B-docs) 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 `differential` section) 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 | |
| ```python | |
| 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](https://huggingface.co/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](https://github.com/ASH1998/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](https://doi.org/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. | |