Views
No views yet
NTT-hil-insight/VDocGenerator-Phi3-vision, was trained on QA pairs NTT-hil-insight/OpenDocVQA with the corpus NTT-hil-insight/OpenDocVQA-Corpus, for training VDocRAG with Vision Language Models (microsoft/Phi-3-vision-128k-instruct) in open-domain question answering scenarios.NTT-hil-insight/VDocGenerator-Phi3-vision is an autoregressive model designed to generate answers based on retrieved document images.1from PIL import Image
2import requests
3from io import BytesIO
4from torch.nn.functional import cosine_similarity
5import torch
6from transformers import AutoProcessor
7from vdocrag.vdocgenerator.modeling import VDocGenerator
8
9model = VDocGenerator.load('microsoft/Phi-3-vision-128k-instruct',
10 lora_name_or_path='NTT-hil-insight/VDocGenerator-Phi3-vision',
11 trust_remote_code=True,
12 attn_implementation="flash_attention_2",
13 torch_dtype=torch.bfloat16,
14 use_cache=False).to('cuda:0')
15
16# Process images with the prompt
17query = "How many international visitors came to Japan in 2017? \n Answer briefly."
18image_tokens = "\n".join([f"<|image_{i+1}|>" for i in range(len(doc_images))])
19messages = [{"role": "user", "content": f"{image_tokens}\n{query}"}]
20prompt = processor.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
21processed = processor(prompt, images=doc_images, return_tensors="pt").to('cuda:0')
22
23# Generate the answer
24generate_ids = model.generate(processed,
25 generation_args={
26 "max_new_tokens": 64,
27 "temperature": 0.0,
28 "do_sample": False,
29 "eos_token_id": processor.tokenizer.eos_token_id
30 })
31generate_ids = generate_ids[:, processed['input_ids'].shape[1]:]
32response = processor.batch_decode(generate_ids,
33 skip_special_tokens=True,
34 clean_up_tokenization_spaces=False)[0].strip()
35
36print("Model prediction: {0}".format(response))
37
38# >> Model prediction: 28.69m1@inproceedings{tanaka2025vdocrag,
2 author = {Ryota Tanaka and
3 Taichi Iki and
4 Taku Hasegawa and
5 Kyosuke Nishida and
6 Kuniko Saito and
7 Jun Suzuki},
8 title = {VDocRAG: Retrieval-Augmented Generation over Visually-Rich Documents},
9 booktitle = {CVPR},
10 year = {2025}
11}