File size: 6,823 Bytes
188f4d8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | # Chronicles-OCR Benchmark
A multi-task benchmark for vision-language models on **Chinese historical script OCR**, covering all seven canonical scripts of Chinese characters: Oracle Bone (甲骨文), Bronze Script (金文), Seal Script (篆书), Clerical Script (隶书), Regular Script (楷书), Running Script (行书), Cursive Script (草书).
| Group | Scripts | Tasks |
| ------- | ------------------------------------------------------------------ | ------------------------------------------------- |
| Ancient | Oracle Bone / Bronze Script / Seal Script | Spotting · Recognition · Parsing · Classification |
| Modern | Clerical Script / Regular Script / Running Script / Cursive Script | Parsing · Classification |
The four tasks:
| Task | Short Name | Metric | Description |
| ------------------------------------------ | -------------- | --------------------- | -------------------------------------------------------------------------- |
| Cross-period Character Spotting | Spotting | F1 @ IoU > 0.75 | Detect bounding boxes and identify the modern character for each box |
| Fine-grained Archaic Character Recognition | Recognition | Exact-match Accuracy | Identify the modern character inside a red bounding box drawn on the image |
| Ancient Text Parsing | Parsing | 1 − NED (Levenshtein) | Read all characters in reading order; `[UNK]` is filtered before scoring |
| Script Classification | Classification | Accuracy | Classify the image into one of the seven canonical scripts |
All scoring is **rule-based** — no LLM judge is needed.
> Note: the Spotting task internally also reports a Detection F1 (bbox-only, IoU > 0.75 without character matching) as a diagnostic; the headline Spotting score requires both IoU and character match.
---
## 1. Setup
```bash
git clone <this-repo>
cd ChronoText/Opensource
pip install -r requirements.txt
# Optional: only if you plan to use --api_type local_vllm
pip install vllm
```
## 2. Download benchmark data
The dataset (jsonl + images) is released as a single archive. Place the files under `Opensource/data/`:
```
Opensource/data/
├── Chronicles_OCR.jsonl
└── images/
├── 甲骨文/... # Oracle Bone
├── 金文/... # Bronze Script
├── 篆书/... # Seal Script
├── 隶书/... # Clerical Script
├── 楷书/... # Regular Script
├── 行书/... # Running Script
└── 草书/... # Cursive Script
```
Each line of the jsonl looks like:
```json
{
"image_path": "images/甲骨文/abcdef0123.jpg",
"font_type": "甲骨文",
"annotation": "...",
"spotting": [{"bbox": {"x1":..,"y1":..,"x2":..,"y2":..}, "modern_char": ".."}, ...],
"width": 800,
"height": 600
}
```
`spotting` / `width` / `height` only exist for the three ancient scripts; modern scripts only carry `image_path`, `font_type`, and `annotation`.
## 3. Inference
Three backends are supported via `--api_type`:
### (a) `openai_compat` — any OpenAI-compatible HTTP service
Works with locally-served models (`vllm serve`, `sglang`, `lmdeploy`) **or** public APIs that speak the OpenAI Chat Completions protocol (OpenAI, Gemini OpenAI-compat, Claude OpenAI-compat, Together, …).
```bash
python infer.py \
--api_type openai_compat \
--model_name Qwen2.5-VL-7B-Instruct \
--base_url http://127.0.0.1:8000/v1 \
--api_key EMPTY \
--max_workers 64
```
### (b) `local_vllm` — in-process vLLM, give it a model path
No need to start a server first. The script loads the checkpoint directly with `vllm.LLM`.
```bash
python infer.py \
--api_type local_vllm \
--model_path /path/to/Qwen2.5-VL-7B-Instruct \
--tensor_parallel_size 1 \
--max_model_len 32768
```
### Output
Each run writes one jsonl file:
```
Opensource/infer_results/<model_tag>/results.jsonl
```
`<model_tag>` defaults to `--model_name` / basename of `--model_path` / `--api_name`. You can override it with `--output_tag`.
## 4. Judging
```bash
# All models under infer_results/
python judge.py
# Specific models
python judge.py --models Qwen2.5-VL-7B-Instruct gemini-3.1-pro
```
Outputs to `Opensource/judge_results/<model_tag>/results.jsonl`. The judge step is purely rule-based and **always overwrites** previous output (it is very fast).
## 5. Summary report
```bash
python summarize.py
# → Opensource/judge_results/results_analysis.xlsx
```
The workbook has two sheets, displayed in the canonical task order **Spotting · Recognition · Parsing · Classification**:
- **Per-group summary** — per-model averages aggregated by Ancient / Modern groups
- **Per-script breakdown** — per-model averages broken down by each of the seven scripts
Scores are scaled `×100` and shown to 1 decimal (e.g. `87.3` means 0.873).
---
## 6. End-to-end example
```bash
# 1. Run inference
python infer.py --api_type openai_compat \
--model_name Qwen2.5-VL-7B-Instruct \
--base_url http://127.0.0.1:8000/v1
# 2. Score
python judge.py
# 3. Aggregate to Excel
python summarize.py
```
---
## 7. Repo layout
```
Opensource/
├── README.md / README_zh.md
├── requirements.txt
├── data/ # ← download benchmark data here
├── apis/
│ ├── base.py # APIBase
│ ├── openai_compat.py # OpenAI-compatible client
│ ├── local_vllm.py # in-process vLLM
├── prompts/
│ ├── spotting.py # Cross-period Character Spotting
│ ├── referring.py # Fine-grained Archaic Character Recognition (red-box rendering)
│ ├── extract_text.py # Ancient Text Parsing
│ └── classify.py # Script Classification
├── judges/
│ ├── spotting.py
│ ├── referring.py
│ ├── extract_text.py
│ └── classify.py
├── utils/
│ ├── image_utils.py # base64 encoding for OpenAI-compat
│ ├── io.py # ResultWriter / read_processed
│ ├── signal_utils.py # Ctrl+C aware shutdown
│ └── unk.py # [UNK] / □ / ■ etc.
├── infer.py # entry: inference
├── judge.py # entry: rule-based scoring
└── summarize.py # entry: Excel report
``` |