morgan commited on
Commit
44db7e2
·
verified ·
1 Parent(s): 4d77d51

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +125 -48
README.md CHANGED
@@ -1,50 +1,127 @@
1
  ---
2
- dataset_info:
3
- features:
4
- - name: question_id
5
- dtype: int64
6
- - name: question
7
- dtype: string
8
- - name: answer
9
- dtype: string
10
- - name: document_text
11
- dtype: string
12
- - name: page
13
- dtype: int64
14
- - name: other_metadata
15
- struct:
16
- - name: doc_id
17
- dtype: int64
18
- - name: image
19
- dtype: string
20
- - name: ucsf_document_id
21
- dtype: string
22
- - name: ucsf_document_page_no
23
- dtype: string
24
- - name: num_tokens
25
- dtype: int64
26
- - name: match_type
27
- dtype: string
28
- - name: messages
29
- list:
30
- - name: content
31
- dtype: string
32
- - name: role
33
- dtype: string
34
- splits:
35
- - name: train
36
- num_bytes: 104556687
37
- num_examples: 39455
38
- - name: validation
39
- num_bytes: 15389930
40
- num_examples: 5349
41
- download_size: 26953138
42
- dataset_size: 119946617
43
- configs:
44
- - config_name: default
45
- data_files:
46
- - split: train
47
- path: data/train-*
48
- - split: validation
49
- path: data/validation-*
50
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: other
3
+ task_categories:
4
+ - question-answering
5
+ - text-generation
6
+ language:
7
+ - en
8
+ tags:
9
+ - document-qa
10
+ - ocr
11
+ - extractive-qa
12
+ - nanochat
13
+ - sft
14
+ pretty_name: DocVQA for Nanochat
15
+ size_categories:
16
+ - 10K<n<100K
17
+ source_datasets:
18
+ - pixparse/docvqa-single-page-questions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  ---
20
+
21
+ # DocVQA for Nanochat
22
+
23
+ Single-page document QA dataset processed for nanochat fine-tuning.
24
+
25
+ ## Description
26
+
27
+ This dataset is derived from [pixparse/docvqa-single-page-questions](https://huggingface.co/datasets/pixparse/docvqa-single-page-questions) and has been processed for efficient fine-tuning of small language models with limited context windows.
28
+
29
+ ## Modifications from Source
30
+
31
+ - **OCR truncation**: Answer-priority truncation ensures the answer is always present in the truncated context. Lines containing the answer are prioritized, then surrounding context is added until the token budget is reached.
32
+ - **Page numbers**: Added "Page X" header at the top of each document from `other_metadata.ucsf_document_page_no`
33
+ - **Token budget**: Documents truncated to fit within 1750 tokens (for 2048 context window models)
34
+ - **Short answers**: Filtered to answers ≤150 characters
35
+ - **Format**: Conversation format compatible with nanochat's CustomJSON task loader
36
+
37
+ ## Statistics
38
+
39
+ | Split | Samples | Total Tokens | Avg Tokens |
40
+ |-------|---------|--------------|------------|
41
+ | Train | 39,455 | 15,495,380 | 393 |
42
+ | Validation | 5,349 | 2,218,651 | 415 |
43
+ | **Total** | **44,804** | **17,714,031** | - |
44
+
45
+ ## Tokenizer
46
+
47
+ Token counts computed with **tiktoken cl100k_base** (GPT-4's tokenizer). This is a GPT-4 style BPE tokenizer similar to what nanochat uses.
48
+
49
+ ## Schema
50
+
51
+ | Field | Type | Description |
52
+ |-------|------|-------------|
53
+ | `question_id` | int | Original question ID from DocVQA |
54
+ | `question` | str | The question to answer |
55
+ | `answer` | str | The extracted answer (or "Not found in document.") |
56
+ | `document_text` | str | OCR text with page number prepended |
57
+ | `page` | int | Page number from OCR results (always 1 for single-page) |
58
+ | `other_metadata` | dict | Full metadata from source (ucsf_document_id, doc_id, etc.) |
59
+ | `num_tokens` | int | Exact token count (tiktoken cl100k_base) |
60
+ | `match_type` | str | How answer was matched: "exact", "fuzzy", or "none" |
61
+ | `messages` | list | Conversation format for training |
62
+
63
+ ## Usage
64
+
65
+ ### With HuggingFace Datasets
66
+
67
+ ```python
68
+ from datasets import load_dataset
69
+
70
+ ds = load_dataset("morgan/docvqa-nanochat")
71
+
72
+ # Access a sample
73
+ sample = ds["train"][0]
74
+ print(f"Question: {{sample['question']}}")
75
+ print(f"Answer: {{sample['answer']}}")
76
+ print(f"Tokens: {{sample['num_tokens']}}")
77
+ ```
78
+
79
+ ### For Nanochat Training
80
+
81
+ The `messages` field is formatted for nanochat's CustomJSON task:
82
+
83
+ ```python
84
+ # Download and convert to JSONL
85
+ from datasets import load_dataset
86
+ import json
87
+
88
+ ds = load_dataset("morgan/docvqa-nanochat", split="train")
89
+ with open("docvqa_train.jsonl", "w") as f:
90
+ for row in ds:
91
+ f.write(json.dumps(row["messages"]) + "\n")
92
+
93
+ # Then use with CustomJSON
94
+ from tasks.customjson import CustomJSON
95
+ train_ds = CustomJSON(filepath="docvqa_train.jsonl")
96
+ ```
97
+
98
+ ## Document Format
99
+
100
+ Each document is formatted as:
101
+
102
+ ```
103
+ Document:
104
+ Page 4
105
+ R. J. REYNOLDS TOBACCO COMPANY
106
+ RETAIL PARTNERS MARKETING PLAN CONTRACT
107
+ ...
108
+
109
+ Question: When is the contract effective date?
110
+ ```
111
+
112
+ ## License
113
+
114
+ Same as source dataset ([pixparse/docvqa-single-page-questions](https://huggingface.co/datasets/pixparse/docvqa-single-page-questions)).
115
+
116
+ ## Citation
117
+
118
+ If you use this dataset, please cite the original DocVQA paper:
119
+
120
+ ```bibtex
121
+ @inproceedings{mathew2021docvqa,
122
+ title={DocVQA: A Dataset for VQA on Document Images},
123
+ author={Mathew, Minesh and Karatzas, Dimosthenis and Jawahar, CV},
124
+ booktitle={WACV},
125
+ year={2021}
126
+ }
127
+ ```