Views
No views yet
| Parameter | Value |
|---|---|
| Base Model | liuhaotian/llava-v1.5-7b |
| Model Size | 7B parameters |
| LoRA Rank (r) | 64 |
| LoRA Alpha | 128 |
| Quantization | 4-bit (NF4) |
| Training Method | QLoRA |
| GPU Memory Required | 8GB (T4 compatible) |
| Inference Speed | 2-3 seconds per page |
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3import torch
4
5# Load base model
6base_model_id = "liuhaotian/llava-v1.5-7b"
7adapter_id = "Shion1124/vlm-lora-agentic-rag"
8
9model = AutoModelForCausalLM.from_pretrained(
10 base_model_id,
11 torch_dtype=torch.float16,
12 device_map="auto",
13 load_in_4bit=True
14)
15
16# Load LoRA adapter
17model = PeftModel.from_pretrained(model, adapter_id)
18tokenizer = AutoTokenizer.from_pretrained(base_model_id)1from PIL import Image
2import json
3
4def analyze_document(image_path: str) -> dict:
5 """Analyze document and extract structured JSON"""
6
7 image = Image.open(image_path).convert("RGB")
8 prompt = """Analyze this document and output ONLY valid JSON:
9 {
10 "title": "...",
11 "summary": "...",
12 "key_data": [...],
13 "insights": "..."
14 }"""
15
16 # Process with VLM + LoRA
17 # ... implementation ...
18
19 return structured_json1from sentence_transformers import SentenceTransformer
2import faiss
3
4# Build document index
5embedder = SentenceTransformer('all-MiniLM-L6-v2')
6index = faiss.IndexFlatL2(vector_dim)
7index.add(embeddings)
8
9# Multi-strategy search with verification
10def agentic_search(query: str, max_iterations: int = 3):
11 for iteration in range(max_iterations):
12 if iteration == 1:
13 results = keyword_search(query)
14 elif iteration == 2:
15 results = semantic_search(query)
16 else:
17 results = hybrid_search(query)
18
19 if verify_results(results):
20 break
21
22 return results| Metric | Performance |
|---|---|
| Structured Output Accuracy | 92% |
| F1 Score (Key Data Extraction) | 0.91 |
| Inference Time (per page) | 2-3 seconds |
| Throughput | 10-15 documents/minute |
| GPU Memory | 8GB (T4 effective) |
| Hallucination Rate | <3% (Agentic verification) |
1from peft import LoraConfig, get_peft_model
2
3lora_config = LoraConfig(
4 r=64, # Rank
5 lora_alpha=128, # Scaling
6 target_modules=["q_proj", "v_proj"], # Attention heads
7 lora_dropout=0.05,
8 bias="none",
9 task_type="CAUSAL_LM"
10)