RKB109 commited on
Commit
f0d8bfd
·
verified ·
1 Parent(s): 5fdb8c3

Publish artifacts for multimodal-document-retrieval-20260802

Browse files
Files changed (5) hide show
  1. README.md +61 -0
  2. evaluation.json +5 -0
  3. inference.py +80 -0
  4. model.json +197 -0
  5. project.json +52 -0
README.md ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: custom
4
+ pipeline_tag: visual-document-retrieval
5
+ datasets:
6
+ - RKB109/multimodal-document-retrieval-20260802-dataset
7
+ tags:
8
+ - synthetic-data
9
+ - transparent-baseline
10
+ - multimodal-ai
11
+ - visual-document-retrieval
12
+ - document-question-answering
13
+ - image-to-text
14
+ - feature-extraction
15
+ metrics:
16
+ - accuracy
17
+ ---
18
+
19
+ # Multimodal Document Retrieval Baseline Baseline Model
20
+
21
+ ## Model Description
22
+
23
+ This repository contains a small, transparent prototype model for
24
+ **Business documents contain meaning in text, tables, layout, and imagery that text-only retrieval can miss.**
25
+
26
+ The model combines per-label token weights with IDF-weighted evidence
27
+ retrieval. It was generated for reproducible architecture demonstrations and
28
+ does not call a hosted LLM.
29
+
30
+ ## Evaluation
31
+
32
+ - Held-out synthetic examples: 4
33
+ - Accuracy: 1
34
+ - Intended metrics: retrieval_accuracy, modality_coverage, recall_at_3
35
+
36
+ ## Intended Use
37
+
38
+ - Architecture prototyping
39
+ - CI and evaluation examples
40
+ - Local baseline comparisons
41
+ - Educational experimentation
42
+
43
+ ## Hugging Face Task Coverage
44
+
45
+ - `visual-document-retrieval`
46
+ - `document-question-answering`
47
+ - `image-to-text`
48
+ - `feature-extraction`
49
+
50
+ ## Limitations and Risks
51
+
52
+ The starter dataset contains synthetic textual modality descriptors, not sensitive scanned documents.
53
+
54
+ The dataset is synthetic and small. Do not use this model for consequential
55
+ decisions without representative data, expert review, and production-grade
56
+ evaluation.
57
+
58
+ ## Reproducibility
59
+
60
+ The linked GitHub repository includes `train.py`, the exact dataset split,
61
+ evaluation code, and the model JSON format.
evaluation.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "test_examples": 4,
3
+ "accuracy": 1,
4
+ "synthetic_evaluation": true
5
+ }
inference.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Transparent baseline pipeline for the generated AI project."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import math
7
+ import re
8
+ from pathlib import Path
9
+
10
+
11
+ def tokenize(value: str) -> list[str]:
12
+ return re.findall(r"[a-z0-9]+", value.lower())
13
+
14
+
15
+ class Pipeline:
16
+ def __init__(self, model: dict):
17
+ self.model = model
18
+
19
+ @classmethod
20
+ def from_file(cls, path: str | Path) -> "Pipeline":
21
+ return cls(json.loads(Path(path).read_text(encoding="utf-8")))
22
+
23
+ def classify(self, text: str) -> tuple[str, float]:
24
+ tokens = tokenize(text)
25
+ scores = {
26
+ label: sum(weights.get(token, 0) for token in tokens)
27
+ for label, weights in self.model["prototypes"].items()
28
+ }
29
+ ranked = sorted(scores.items(), key=lambda item: (-item[1], item[0]))
30
+ label, best = ranked[0]
31
+ total = sum(max(score, 0) for _, score in ranked) or 1
32
+ return label, best / total
33
+
34
+ def search(self, query: str, limit: int = 3) -> list[dict]:
35
+ query_tokens = set(tokenize(query))
36
+ ranked = []
37
+ for document in self.model["documents"]:
38
+ document_tokens = set(tokenize(document["text"]))
39
+ lexical = sum(
40
+ self.model["idf"].get(token, 1.0)
41
+ for token in query_tokens & document_tokens
42
+ )
43
+ ranked.append({**document, "score": round(lexical, 6)})
44
+ return sorted(ranked, key=lambda item: (-item["score"], item["id"]))[:limit]
45
+
46
+ def graph_evidence(self, text: str) -> list[dict]:
47
+ tokens = set(tokenize(text))
48
+ matches = []
49
+ for subject, relation, target in self.model.get("graph_edges", []):
50
+ edge_tokens = set(tokenize(f"{subject} {relation} {target}"))
51
+ overlap = len(tokens & edge_tokens)
52
+ if overlap:
53
+ matches.append(
54
+ {
55
+ "subject": subject,
56
+ "relation": relation,
57
+ "target": target,
58
+ "overlap": overlap,
59
+ }
60
+ )
61
+ return sorted(matches, key=lambda item: -item["overlap"])
62
+
63
+ def run(self, text: str) -> dict:
64
+ label, confidence = self.classify(text)
65
+ evidence = self.search(text)
66
+ result = {
67
+ "prediction": label,
68
+ "confidence": round(confidence, 4),
69
+ "requires_review": confidence < self.model["confidence_threshold"],
70
+ "evidence": evidence,
71
+ }
72
+ if self.model["mode"] == "graph":
73
+ result["graph_evidence"] = self.graph_evidence(text)
74
+ if self.model["mode"] == "agent":
75
+ result["proposed_tool"] = label
76
+ result["approval_required"] = label in {
77
+ "request-approval",
78
+ "request-human-help",
79
+ }
80
+ return result
model.json ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "format": "daily-project-prototype-v1",
3
+ "project": "multimodal-document-retrieval",
4
+ "title": "Multimodal Document Retrieval Baseline",
5
+ "domain": "multimodal-ai",
6
+ "mode": "retrieval",
7
+ "labels": [
8
+ "invoice",
9
+ "technical-diagram",
10
+ "policy-form"
11
+ ],
12
+ "prototypes": {
13
+ "invoice": {
14
+ "80": 3,
15
+ "184": 2,
16
+ "1480": 3,
17
+ "find": 3,
18
+ "the": 3,
19
+ "invoice": 7,
20
+ "with": 3,
21
+ "a": 5,
22
+ "shipping": 6,
23
+ "surcharge": 6,
24
+ "table": 8,
25
+ "ocr": 5,
26
+ "total": 5,
27
+ "image": 3,
28
+ "company": 3,
29
+ "seal": 3,
30
+ "in": 2,
31
+ "an": 3,
32
+ "operations": 2,
33
+ "review": 2,
34
+ "for": 1,
35
+ "evaluation": 1,
36
+ "case": 1,
37
+ "which": 2,
38
+ "contains": 2,
39
+ "tax": 4,
40
+ "adjustment": 4,
41
+ "subtotal": 2,
42
+ "final": 2
43
+ },
44
+ "technical-diagram": {
45
+ "in": 2,
46
+ "an": 4,
47
+ "operations": 2,
48
+ "review": 2,
49
+ "locate": 2,
50
+ "the": 5,
51
+ "architecture": 2,
52
+ "diagram": 7,
53
+ "showing": 2,
54
+ "a": 5,
55
+ "queue": 4,
56
+ "caption": 5,
57
+ "service": 5,
58
+ "labels": 5,
59
+ "producer": 2,
60
+ "consumer": 2,
61
+ "for": 2,
62
+ "evaluation": 2,
63
+ "case": 2,
64
+ "show": 3,
65
+ "network": 6,
66
+ "with": 3,
67
+ "gateway": 6,
68
+ "topology": 3,
69
+ "client": 3
70
+ },
71
+ "policy-form": {
72
+ "find": 2,
73
+ "the": 2,
74
+ "signed": 2,
75
+ "privacy": 4,
76
+ "exception": 4,
77
+ "request": 4,
78
+ "ocr": 4,
79
+ "layout": 2,
80
+ "signature": 4,
81
+ "block": 2,
82
+ "approved": 4,
83
+ "for": 2,
84
+ "an": 3,
85
+ "evaluation": 2,
86
+ "case": 2,
87
+ "in": 1,
88
+ "operations": 1,
89
+ "review": 1,
90
+ "which": 2,
91
+ "form": 2,
92
+ "includes": 2,
93
+ "retention": 4,
94
+ "approval": 2,
95
+ "checkbox": 2,
96
+ "present": 2
97
+ }
98
+ },
99
+ "idf": {
100
+ "80": 2.252763,
101
+ "184": 2.252763,
102
+ "1480": 2.252763,
103
+ "ocr": 1.336472,
104
+ "total": 1.847298,
105
+ "table": 1.847298,
106
+ "shipping": 2.252763,
107
+ "surcharge": 2.252763,
108
+ "image": 2.252763,
109
+ "company": 2.252763,
110
+ "seal": 2.252763,
111
+ "caption": 1.847298,
112
+ "service": 1.847298,
113
+ "diagram": 2.252763,
114
+ "labels": 1.847298,
115
+ "producer": 2.252763,
116
+ "queue": 2.252763,
117
+ "consumer": 2.252763,
118
+ "privacy": 2.252763,
119
+ "exception": 2.252763,
120
+ "layout": 2.252763,
121
+ "signature": 1.847298,
122
+ "block": 2.252763,
123
+ "approved": 1.847298,
124
+ "invoice": 2.252763,
125
+ "subtotal": 2.252763,
126
+ "tax": 2.252763,
127
+ "adjustment": 2.252763,
128
+ "final": 2.252763,
129
+ "network": 2.252763,
130
+ "topology": 2.252763,
131
+ "client": 2.252763,
132
+ "gateway": 2.252763,
133
+ "retention": 2.252763,
134
+ "request": 2.252763,
135
+ "checkbox": 2.252763,
136
+ "present": 2.252763
137
+ },
138
+ "documents": [
139
+ {
140
+ "id": "doc-01",
141
+ "label": "invoice",
142
+ "text": "OCR total 1480; table shipping surcharge 80; image company seal.",
143
+ "metadata": {
144
+ "synthetic": true,
145
+ "domain": "multimodal-ai"
146
+ }
147
+ },
148
+ {
149
+ "id": "doc-02",
150
+ "label": "technical-diagram",
151
+ "text": "Caption service diagram; labels producer queue consumer.",
152
+ "metadata": {
153
+ "synthetic": true,
154
+ "domain": "multimodal-ai"
155
+ }
156
+ },
157
+ {
158
+ "id": "doc-03",
159
+ "label": "policy-form",
160
+ "text": "OCR privacy exception; layout signature block approved.",
161
+ "metadata": {
162
+ "synthetic": true,
163
+ "domain": "multimodal-ai"
164
+ }
165
+ },
166
+ {
167
+ "id": "doc-04",
168
+ "label": "invoice",
169
+ "text": "OCR invoice 184; table subtotal tax adjustment final total.",
170
+ "metadata": {
171
+ "synthetic": true,
172
+ "domain": "multimodal-ai"
173
+ }
174
+ },
175
+ {
176
+ "id": "doc-05",
177
+ "label": "technical-diagram",
178
+ "text": "Caption network topology; labels client gateway service.",
179
+ "metadata": {
180
+ "synthetic": true,
181
+ "domain": "multimodal-ai"
182
+ }
183
+ },
184
+ {
185
+ "id": "doc-06",
186
+ "label": "policy-form",
187
+ "text": "OCR retention request; checkbox approved; signature present.",
188
+ "metadata": {
189
+ "synthetic": true,
190
+ "domain": "multimodal-ai"
191
+ }
192
+ }
193
+ ],
194
+ "graph_edges": [],
195
+ "confidence_threshold": 0.18,
196
+ "trained_on_synthetic_data": true
197
+ }
project.json ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "Multimodal Document Retrieval Baseline",
3
+ "problem": "Business documents contain meaning in text, tables, layout, and imagery that text-only retrieval can miss.",
4
+ "domain": "multimodal-ai",
5
+ "architecture": "retrieval",
6
+ "hugging_face_tasks": [
7
+ "visual-document-retrieval",
8
+ "document-question-answering",
9
+ "image-to-text",
10
+ "feature-extraction"
11
+ ],
12
+ "recommended_stack": [
13
+ "FastAPI for ingestion and multimodal search",
14
+ "Transformers with LayoutLMv3 or ColPali-style encoders",
15
+ "OCR adapter plus image captioning",
16
+ "PostgreSQL plus pgvector for fused embeddings",
17
+ "Object storage for source documents",
18
+ "OpenTelemetry plus retrieval ablation reports"
19
+ ],
20
+ "real_world_data_sources": [
21
+ {
22
+ "name": "SEC EDGAR company facts API",
23
+ "url": "https://data.sec.gov/api/xbrl/companyfacts/CIK0000320193.json",
24
+ "purpose": "Real tabular filing facts and document metadata"
25
+ },
26
+ {
27
+ "name": "arXiv API",
28
+ "url": "https://export.arxiv.org/api/query?search_query=all:document%20understanding&start=0&max_results=5",
29
+ "purpose": "Public papers and document-layout retrieval scenarios"
30
+ }
31
+ ],
32
+ "job_description_skills": [
33
+ "Multimodal embeddings and document understanding",
34
+ "OCR, layout, image, and text feature fusion",
35
+ "Vector retrieval and modality-aware ranking",
36
+ "Ablation testing and retrieval evaluation",
37
+ "Scalable document ingestion and object storage"
38
+ ],
39
+ "impact_targets": [
40
+ "Improve Recall@5 by >= 20% over text-only retrieval",
41
+ "Report modality ablations for OCR, layout, and image signals",
42
+ "Index 100,000 documents with resumable ingestion",
43
+ "Keep p95 retrieval latency below 500 ms"
44
+ ],
45
+ "baseline_evaluation": {
46
+ "test_examples": 4,
47
+ "accuracy": 1,
48
+ "synthetic_evaluation": true
49
+ },
50
+ "estimated_delivery": "8-12 weeks for one engineer",
51
+ "generated_baseline_is_production_ready": false
52
+ }