File size: 5,929 Bytes
a4c6bf2
ef0cd09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4c6bf2
ef0cd09
 
 
a4c6bf2
ef0cd09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
181
182
183
184
185
186
187
188
189
190
191
192
---
license: mit
task_categories:
  - image-to-text
language:
  - en
  - hi
  - te
  - ta
  - or
  - ur
  - ml
  - zh
  - pa
  - gu
  - bn
  - as
  - kn
tags:
  - table
  - table-structure-recognition
  - TSR
  - multilingual
  - OTSL
  - historical-documents
size_categories:
  - 1K<n<10K
configs:
  - config_name: default
    data_splits:
      - test
---

# MUSTARD

A structured repackaging of [badrivishalk/MUSTARD](https://huggingface.co/datasets/badrivishalk/MUSTARD) that surfaces the OTSL annotations and language metadata as proper dataset columns.

**MUSTARD** (Multilingual Scanned and Scene Table Structure Recognition Dataset) contains 1,429 table images across 13 languages, annotated with OTSL (Optimized Table Structure Language) sequences for table structure recognition. Introduced by the SPRINT paper (ICDAR 2024).

This is an **evaluation-only benchmark** (test split only, no train).

## Why this version

The original upload uses `imagefolder` format, which means the OTSL annotations in `merged.txt` are not exposed as columns in the dataset viewer or via `load_dataset`. Loading it returns only `{"image": ...}` with no annotation access.

This version gives you:

```python
{
  "image_id":    "indic/assamese/1",         # stable identifier
  "image":       <PIL Image>,
  "width":       2210,
  "height":      1394,
  "language":    "assamese",                 # 13 values
  "script_type": "indic",                    # "indic" or "scenetext"
  "has_lines":   True,                       # scenetext: whether grid lines visible
  "otsl":        "FFFLFFFNUUFFUUUN...",
  "n_rows":      10,
  "n_cols":      7,
}
```

## Schema

| Field | Type | Description |
|-------|------|-------------|
| `image_id` | string | Stable path-derived identifier (e.g. `indic/assamese/1`, `scenetext/chinese_lines/1`) |
| `image` | Image | Table image (PNG) |
| `width` | int32 | Image width in pixels |
| `height` | int32 | Image height in pixels |
| `language` | string | One of 13 languages (see table below) |
| `script_type` | string | `"indic"` for printed/scanned Indic-script tables; `"scenetext"` for scene-text tables |
| `has_lines` | bool | For `scenetext`: whether the table has visible grid lines. Always `True` for `indic`. |
| `otsl` | string | OTSL annotation sequence (see format below) |
| `n_rows` | int32 | Number of table rows decoded from OTSL |
| `n_cols` | int32 | Number of table columns decoded from OTSL (max row width) |

## Language distribution

| Language | Script type | Count |
|----------|-------------|-------|
| assamese | indic | 101 |
| bengali | indic | 100 |
| chinese | indic + scenetext | 207 |
| english | scenetext | 109 |
| gujarati | indic | 101 |
| hindi | indic | 101 |
| kannada | indic | 101 |
| malayalam | indic | 102 |
| oriya | indic | 101 |
| punjabi | indic | 102 |
| tamil | indic | 100 |
| telugu | indic | 102 |
| urdu | indic | 102 |
| **Total** | | **1,429** |

Scenetext subset: 111 with visible grid lines (`has_lines=True`), 103 without (`has_lines=False`).

## OTSL format

OTSL (Optimized Table Structure Language) encodes table structure as a flat token sequence. Rows are delimited by `N`; within each row, each character is one cell:

| Token | Meaning |
|-------|---------|
| `F` | Regular cell (no span) |
| `L` | Cell spanning left (continuation of the cell immediately to its left) |
| `U` | Cell spanning up (continuation of the cell directly above) |
| `E` | Cell spanning both left and up (interior merge corner) |
| `X` | Empty/non-data cell |

Example: `FFLNFFN` = a 2-row, 3-column table where row 1 has a merged cell in columns 2-3 (`F F L`) and row 2 is all regular cells (`F F`).

### Decode OTSL to an HTML table

```python
def otsl_to_html(otsl: str) -> str:
    rows = [r for r in otsl.split("N") if r]
    n_cols = max(len(r) for r in rows)

    # First pass: compute colspan/rowspan
    grid = [[None] * n_cols for _ in range(len(rows))]
    spans = {}

    for r, row in enumerate(rows):
        for c, tok in enumerate(row):
            if tok == "F":
                spans[(r, c)] = [1, 1]
                grid[r][c] = (r, c)
            elif tok == "L":
                origin = grid[r][c - 1]
                spans[origin][1] += 1
                grid[r][c] = origin
            elif tok == "U":
                origin = grid[r - 1][c]
                spans[origin][0] += 1
                grid[r][c] = origin
            elif tok == "E":
                origin = grid[r - 1][c - 1]
                grid[r][c] = origin

    # Second pass: emit HTML
    html = ["<table>"]
    for r, row in enumerate(rows):
        html.append("  <tr>")
        for c in range(len(row)):
            if grid[r][c] == (r, c):
                rs, cs = spans[(r, c)]
                attrs = ""
                if rs > 1:
                    attrs += f' rowspan="{rs}"'
                if cs > 1:
                    attrs += f' colspan="{cs}"'
                html.append(f"    <td{attrs}></td>")
        html.append("  </tr>")
    html.append("</table>")
    return "\n".join(html)
```

## Usage

```python
from datasets import load_dataset

ds = load_dataset("rootsautomation/MUSTARD", split="test")

# Filter to a single language
hindi = ds.filter(lambda x: x["language"] == "hindi")

# Filter to scenetext with lines
scene_lines = ds.filter(lambda x: x["script_type"] == "scenetext" and x["has_lines"])

# Access a sample
row = ds[0]
print(row["language"], row["n_rows"], "x", row["n_cols"])
row["image"].show()
```

## License

MIT. Source data curated by the IIT Bombay LEAP OCR Team. See [badrivishalk/MUSTARD](https://huggingface.co/datasets/badrivishalk/MUSTARD) for the original release.

## Citation

```bibtex
@inproceedings{sprint2024,
  title     = {SPRINT: Script-agnostic Structure Recognition in Tables},
  booktitle = {Document Analysis and Recognition -- ICDAR 2024},
  year      = {2024},
  note      = {arXiv:2503.11932}
}
```