Peritext MPNet Page Classifier (Front / Core / Back)

Fine-tuned MPNet classifier that labels digitized book pages as:

Label Meaning
Front Front matter
Core Body / main text
Back Back matter

The model combines page text (via a fine-tuned MPNet encoder) with 14 positional features (page deciles and within-volume percentile indicators).

Important: This model expects raw page text, not precomputed embeddings. Positional features must be supplied in the training feature order (see below).

Model details

  • Base model: sentence-transformers/all-mpnet-base-v2
  • Task: 3-class page classification
  • Architecture: MPNet [CLS] representation + MLP over 14 extra features → linear classifier
  • Extra features (required, order matters):
    1. decile_10, decile_5, decile_4, decile_2
    2. below_10, below_20, …, below_100
  • Max token length: 256 (must match training; do not use 128)

How to compute positional features

Within each volume (grouped by book id), with 1-based page numbers:

  • Deciles: pandas.qcut(page, q=Q, labels=False, duplicates="drop") + 1 for Q ∈ {10,5,4,2}
  • below_N: 1 if (page / max_page) * 100 <= N else 0, for N = 10,20,…,100

Intended use

  • Research and tooling for separating peritext from body text in digitized volumes (e.g. HathiTrust-style page text the user already has rights to access).
  • Not a substitute for human annotation on edge cases (poetry, pamphlets, unusual structures).

How to use

import torch
from transformers import AutoTokenizer, AutoModel

repo = "alucic2/peritext-mpnet-page-classifier"

tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModel.from_pretrained(repo, trust_remote_code=True)
model.eval()

text = "CONTENTS CHAPTER I INTRODUCTION ..."
extra = torch.tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=torch.float)
# extra columns: decile_10,5,4,2, below_10..below_100

enc = tokenizer(text, return_tensors="pt", truncation=True, max_length=256, padding="max_length")
with torch.no_grad():
    out = model(
        input_ids=enc["input_ids"],
        attention_mask=enc["attention_mask"],
        extra_features=extra,
    )
pred = out.logits.argmax(dim=-1).item()
print(model.config.id2label[pred])

Load with trust_remote_code=True because this is a custom head (text + positional features).

Training data

Trained on annotated pages from 944 development volumes in which every volume has Front, Core, and Back pages.
Page full text is not redistributed with the public dataset release; the public companion release may include labels, volume metadata, and positional features only.

Evaluation

External validation on 109 held-out volumes (pages with extractable text; empty pages dropped): 36,466 pages.

Class Precision Recall F1 Support
Front 0.793 0.971 0.873 1,349
Core 0.995 0.982 0.988 33,599
Back 0.841 0.910 0.874 1,518
Accuracy 0.979 36,466
Macro avg 0.876 0.954 0.912 36,466

Confusion matrix (rows = true, cols = predicted):

Front Core Back
Front 1310 36 3
Core 341 33000 258
Back 0 137 1381

In-corpus held-out evaluation during training was Front/Core/Back F1 0.90 / 0.99 / 0.89 (accuracy 0.98). Front and Back are close on both splits; remaining errors concentrate at Core–Front and Core–Back boundaries.

Limitations

  • Requires page text the user is authorized to use.
  • Performance can degrade on atypical genres (verse, very short works, unusual structures).
  • Positional features must match the definitions above; silent mismatches hurt accuracy.
  • Class imbalance: Core dominates; report per-class metrics, not accuracy alone.

Citation

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

@misc{lucic2026peritext-mpnet,
 title         = {Peritext MPNet Page Classifier (Front / Core / Back)},
 author       = {Lucic, Ana and Debnath, Tanmoy and Shanahan, John},
 year         = {2026},
 howpublished = {Hugging Face},
 url          = {https://huggingface.co/alucic2/peritext-mpnet-page-classifier}}

## License

Model weights and code in this repository: **Apache-2.0** (unless otherwise noted).  
Respect source corpus terms (e.g. HathiTrust) for any page text you run through the model.
Downloads last month
-
Safetensors
Model size
0.1B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support