TeXtract_dataset / README.md
ToniDO's picture
Upload README.md
c5ef7f5 verified
metadata
license: mit
tags:
  - img2latex
  - latex-ocr
  - handwritten mathematical expressions
  - printed mathematical expressions
size_categories:
  - 1M<n<10M
dataset_info:
  config_name: default
  features:
    - name: __key__
      dtype: string
    - name: .png
      dtype: image
    - name: .tex
      dtype: string
  splits:
    - name: train
      num_bytes: <INSERT_TOTAL_DATASET_SIZE_IN_BYTES>
      num_examples: 3200000

TeXtract_dataset (WebDataset Format)

This repository contains approximately 3.2 million pairs of mathematical expression images and their corresponding LaTeX source code, packaged in WebDataset format for large-scale training.

The dataset is based on and derived from the original hoang-quoc-trung/fusion-image-to-latex-datasets, transformed for more efficient access.


πŸ“‚ Dataset Structure

Each WebDataset shard (.tar) contains multiple samples. Each sample groups files sharing a common identifier (__key__):

  • __key__ (string): Unique sample ID (e.g., sample_000000123).
  • Image file (.png, .jpg, etc.): Binary data of the mathematical expression.
  • .tex: UTF-8 text file with the corresponding LaTeX code.
  • __url__ (string): URL or path to the source shard (automatically added).
shard-000000.tar
β”œβ”€β”€ sample_000000000.png
β”œβ”€β”€ sample_000000000.tex
β”œβ”€β”€ sample_000000001.png
β”œβ”€β”€ sample_000000001.tex
└── ...

Note: When browsing in Hugging Face Data Studio:

  • Image metadata (dimensions) may be shown instead of the actual content.
  • .tex files may appear Base64-encoded. This is only a preview; the underlying data is UTF-8.

πŸš€ How to Use

1. Using the datasets library (recommended)

from datasets import load_dataset
from PIL import Image
import io

DATASET_ID = "ToniDO/TeXtract_dataset"

try:
    ds = load_dataset(DATASET_ID, split="train", trust_remote_code=True)
except ValueError:
    ds = load_dataset(DATASET_ID, trust_remote_code=True)

for i, sample in enumerate(ds):
    print(f"Sample {i}: {sample['__key__']}")

    # Load image
    for ext in ['.png', '.jpg', '.jpeg']:
        if ext in sample:
            img_data = sample[ext]
            img = (
                img_data
                if isinstance(img_data, Image.Image)
                else Image.open(io.BytesIO(img_data if isinstance(img_data, bytes) else img_data['bytes']))
            )
            print(f"Image ({ext}), size: {img.size}")
            break

    # Decode LaTeX
    tex_bytes = sample.get('.tex')
    if isinstance(tex_bytes, (bytes, bytearray)):
        latex = tex_bytes.decode('utf-8')
        print(latex[:100])

    if i >= 2:
        break

2. Using the webdataset library

import webdataset as wds
from PIL import Image
import io

urls = "path/to/shards/math_dataset-{000000..000349}.tar"

dataset = (
    wds.WebDataset(urls)
       .decode(
           wds.handle_extension("pil", "png"),
           wds.handle_extension("pil", "jpg"),
           handler=wds.ignore_and_continue
       )
)

for i, sample in enumerate(dataset):
    print(f"Sample {i}: {sample['__key__']}")

    # Image
    img = None
    for ext in ["png", "jpg", "jpeg"]:
        if ext in sample and isinstance(sample[ext], Image.Image):
            img = sample[ext]
            break
    if img:
        print(f"Size: {img.size}")

    # LaTeX
    tex = sample.get('.tex')
    if isinstance(tex, (bytes, bytearray)):
        print(tex.decode('utf-8')[:100])

    if i >= 2:
        break

Training tips:

  • Decode LaTeX from UTF-8.
  • Preprocess images (resize, normalize, augment).
  • Tokenize LaTeX code according to your vocabulary.
  • Shuffle shards and samples for effective training.

File Types

  .bmp
  .dvi
  .jpg
  .png

πŸ“– Citation

If you use this dataset, please cite the original work:

@misc{hoang2024fusion,
  author       = {Hoang, Quoc Trung},
  title        = {Fusion Image-to-LaTeX Datasets},
  year         = {2024},
  publisher    = {Hugging Face},
  url          = {https://huggingface.co/datasets/hoang-quoc-trung/fusion-image-to-latex-datasets}
}

And to reference this WebDataset version:

@misc{ToniDO_TeXtract_webdataset_2025,
  author       = {ToniDO},
  title        = {{TeXtract_dataset (WebDataset Format)}},
  year         = {2025},
  publisher    = {Hugging Face},
  version      = {1.0.0},
  url          = {https://huggingface.co/datasets/ToniDO/TeXtract_dataset}
}

πŸ“ Authors

  • ToniDO

πŸ“œ License

This project is licensed under the MIT License. See the LICENSE file for details.