Views
No views yet
| Metric | Base Model | Fine-tuned Model | Improvement |
|---|---|---|---|
| Character Error Rate (CER) | 0.8044 (80.44%) | 0.2205 (22.05%) | +72.59% |
| Word Error Rate (WER) | 1.2029 (120.29%) | 0.5714 (57.14%) | +52.49% |
1from transformers import AutoProcessor, Qwen3VLForConditionalGeneration
2from peft import PeftModel
3from PIL import Image
4
5# Load model and processor
6base_model = "Qwen/Qwen3-VL-4B-Instruct"
7adapter_model = "small-models-for-glam/Qwen3-VL-4B-catmus"
8
9model = Qwen3VLForConditionalGeneration.from_pretrained(
10 base_model,
11 torch_dtype="auto",
12 device_map="auto"
13)
14model = PeftModel.from_pretrained(model, adapter_model)
15processor = AutoProcessor.from_pretrained(base_model)
16
17# Load your image
18image = Image.open("path/to/your/manuscript_image.jpg")
19
20# Prepare the message
21messages = [
22 {
23 "role": "user",
24 "content": [
25 {"type": "image", "image": image},
26 {"type": "text", "text": "Transcribe the text shown in this image."},
27 ],
28 },
29]
30
31# Generate transcription
32inputs = processor.apply_chat_template(
33 messages,
34 tokenize=True,
35 add_generation_prompt=True,
36 return_dict=True,
37 return_tensors="pt"
38).to(model.device)
39
40generated_ids = model.generate(**inputs, max_new_tokens=256)
41generated_ids_trimmed = [
42 out_ids[len(in_ids):] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
43]
44transcription = processor.batch_decode(
45 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
46)[0]
47
48print(transcription)1@article{Qwen3-VL,
2 title={Qwen3-VL: Large Vision Language Models Pretrained on Massive Data},
3 author={Qwen Team},
4 journal={arXiv preprint},
5 year={2024}
6}1@misc{vonwerra2022trl,
2 title = {{TRL: Transformer Reinforcement Learning}},
3 author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'{'e}}dec},
4 year = 2020,
5 journal = {GitHub repository},
6 publisher = {GitHub},
7 howpublished = {\url{https://github.com/huggingface/trl}}
8}