Team Ai
Modelpublic

impresso-project/frakturline-classification-cnn

sourceHugging Faceagpl-3.0updated 5mo agoView on Hugging Face
0likes11downloads
Model Card

Fraktur/Other Text-Line Classifier

A binary CNN classifier that determines whether a scanned text-line image is set in Fraktur (blackletter / Gothic script) or Other (primarily Latin / Roman / Antiqua script).

Developed for the Impresso digital humanities project, which processes millions of historical newspaper pages in German, French, Luxembourgish, and other European languages.


Model Details

PropertyValue
ArchitectureBinaryClassificationCNN — 3-layer CNN with LayerNorm and Dropout
InputGrayscale text-line image, resized/padded to 60 × 800 px
OutputSingle logit; logit > 0 → Fraktur (equivalent to sigmoid(logit) > 0.5)
Parameters~2.1 M
Training data~32 000 manually labeled line crops from Swiss/Luxembourgish newspapers
FrameworkPyTorch

Architecture

Input (1, 60, 800)
  → Conv2d(1→32) + ReLU + MaxPool2d      → LayerNorm[32, 30, 400]
  → Conv2d(32→64) + ReLU + MaxPool2d     → LayerNorm[64, 15, 200] + Dropout(0.15)
  → Conv2d(64→128) + LayerNorm[128,15,200] + ReLU + AdaptiveMaxPool2d(1×8)
  → Flatten(1 024) → FC(128) + ReLU → FC(1)

Training

  • —Loss: BCEWithLogitsLoss
  • —Optimizer: Adam, lr = 1e-4 with ReduceLROnPlateau (factor 0.5, patience 2)
  • —Epochs: up to 20 with early stopping (patience 5)
  • —Augmentation: random rotation ±2°, Gaussian noise (σ=0.05), random right-masking (p=0.15, up to 50 % of width) to improve robustness on short lines
  • —Class balancing: WeightedRandomSampler (other ≈ 20 k, fraktur ≈ 14 k)

Provenance note: this checkpoint predates the current training pipeline's pinned training.dataset_source field, so the exact training dataset snapshot is not asserted in config.json. Future checkpoints trained from the separated Hugging Face dataset workflow record the training dataset repository and commit SHA directly in the model config.


Performance

Evaluated on the companion held-out test set (impresso-project/frakturline-testset) — 2 000 balanced images (1 000 per class), strictly excluded from training. The refreshed official evaluation recorded in config.json uses dataset commit 1b2bb656f6b0162ceac8c905ca4f773a8c918468.

MetricScore
Accuracy99.75 %
Precision (Fraktur)100.0 %
Recall (Fraktur)99.5 %
F1 (Fraktur)99.75 %
FP / FN0 FP / 5 FN

Evaluation Dataset

The test set is published as a separate frozen HF dataset:

→ impresso-project/frakturline-testset

It is not included in the training corpus. Please consult the dataset card for detailed provenance, revision, and licensing information. Do not use it for training.

python
from datasets import load_dataset
ds = load_dataset("impresso-project/frakturline-testset", split="test")
# 2 000 images: {"image": <PIL.Image>, "label": "fraktur"|"other", ...}

Usage

Install dependencies

bash
pip install torch torchvision Pillow huggingface_hub

Classify images

python
from huggingface_hub import hf_hub_download
import importlib.util

# Load pipeline.py from the hub
spec = importlib.util.spec_from_file_location(
    "pipeline",
    hf_hub_download("impresso-project/frakturline-classification-cnn", "pipeline.py"),
)
pipeline_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(pipeline_module)

pipe = pipeline_module.FrakturPipeline.from_pretrained(
    "impresso-project/frakturline-classification-cnn"
)

# Single image — local path
result = pipe("path/to/line.png")
# → {"label": "fraktur", "score": 0.9731}

# Single image — URL
result = pipe("https://example.com/line.png")

# Batch
results = pipe(["line1.png", "line2.png", "line3.png"])

Input format

  • —Any PIL-readable image format (PNG, JPEG, TIFF, …)
  • —Ideally a single text line crop extracted by an OCR layout-analysis tool
  • —The pipeline handles grayscale conversion and resizing internally

Output format

python
{"label": "fraktur",  "score": 0.9731}  # sigmoid probability of predicted class
{"label": "other",    "score": 0.9954}

Limitations

  • —Designed for single text lines. Mixed-typeface lines or non-text content may produce unreliable results.
  • —Short headers, ornaments, or lines with very few characters can be ambiguous.
  • —The training data is drawn primarily from 19th- and 20th-century European newspapers; performance on other periods or regions is not guaranteed.

Citation

If you use this model, please cite the Impresso project:

bibtex
@misc{impresso2025fraktur,
  title  = {Fraktur/Antiqua Text-Line Classifier},
  author = {Impresso Project},
  year   = {2025},
  url    = {https://huggingface.co/impresso-project/frakturline-classification-cnn}
}

License

The code in this repository is released under the GNU Affero General Public License v3.0 (AGPL-3.0).

The model was trained on data derived from multiple upstream sources. Rights in the underlying source materials remain subject to their respective original terms. For dataset-specific provenance, revision, and licensing details, please consult the linked dataset cards.

If you use this model, please cite the Impresso project and link to this repository.