/ Модель

Характеристики

Контекст
40 960 токенов
Параметры
508 млн
Лицензия
Apache 2.0
Архитектура
qwen3 · dense
Базовая модель
Qwen3-0.6B
Библиотека
transformers
Опубликована
5 апр 2026

md-reheader

Генерация текстаТекст → текст8 профессий

Компактная дообученная модель Qwen3 восстанавливает уровни заголовков H1–H6 в Markdown-документах, в том числе после конвертации PDF.

124скачиваний за 30 дней2лайкавеса обновлены11 июл 2026

Бенчмарки

Как модель справилась с задачами пользователей ailist и что о ней публикуют открытые лидерборды

Тесты пользователейпока нет

Никто ещё не опубликовал тест этой модели. Соберите бенчмарк из своих задач — результат появится здесь.

  1. Добавьте модель в бенчмарк

    Вместе с другими моделями категории «Текст» — сравнение идёт внутри одной категории.

  2. Опишите свои задачи

    Напишите запросы, при необходимости приложите файлы и эталонные ответы.

  3. Запустите и опубликуйте

    Модели ответят на каждую задачу, судья оценит ответы. Опубликованный результат появится на этой странице.

Публичные оценки

Из открытых лидербордов. Сравнивайте результаты одного теста при одинаковых условиях — отсутствие оценки не значит, что модель хуже.

В подключённых источниках результатов для этой модели пока нет.

Что умеет модель

Описание составлено по карточке модели и метаданным Hugging Face

md-reheader — созданная Джоэлом Барметтлером в Souverana модель на базе Qwen3, дообученная для восстановления уровней заголовков в Markdown-документах. Она анализирует структуру текста и предсказывает для каждого заголовка уровень H1–H6; модель рассчитана на обработку Markdown, полученного, например, при конвертации PDF, и на запуск локально через CLI, Python API или сервер vLLM.

Модель имеет плотную архитектуру Qwen3ForCausalLM и содержит 507,9 млн параметров. Она принимает текст и генерирует текст с восстановленной иерархией заголовков; основной язык обучения — английский. Контекстное окно составляет 40 960 токенов, однако README указывает, что после предварительного удаления основного текста документы длиннее 8 000 токенов обрезаются: заголовки за пределами этого предела сохраняют исходный уровень.

Модель специализируется на одной задаче, поэтому подходит для автоматизации подготовки Markdown перед навигацией и разбиением документов на фрагменты для RAG. Лицензия — Apache-2.0.

Сценарии применения

  • восстановление иерархии заголовков в Markdown после извлечения текста из PDF
  • исправление плоской структуры заголовков перед разбиением документов для RAG
  • подготовка Markdown-документов для навигации по разделам и оглавления

Ограничения

Модель ориентирована преимущественно на английский контент. После предварительной обработки документы длиннее 8 000 токенов обрезаются, поэтому заголовки за пределами этого объёма сохраняют исходные уровни.

Для каких профессий подходит8

Разделы каталога профессий, в задачах которых используется эта модель

Все профессии

Также подходит для

Карточка модели

README от автора на Hugging Face, как он его опубликовал

Открыть на Hugging Face

The problem

PDF-to-markdown tools like MinerU, Docling, and Marker do great text extraction — then collapse your document structure. Every heading becomes # or ##. TOCs break. RAG chunking breaks. Navigation breaks.

md-reheader fixes it. A 0.6B-parameter Qwen3 fine-tune reads the document and predicts the correct H1–H6 level for every heading in a single forward pass.


Quick start

CLI

pip install md-reheader
rehead --input flat.md --output fixed.md

Auto-detects CUDA. Use --cpu or --gpu to override. Omit --output to stream to stdout (pipe-friendly).

rehead -i flat.md | tee fixed.md      # pipe
rehead -i flat.md --gpu -o out/fixed.md  # creates nested dirs
rehead --help                          # all flags

Python API

from md_reheader.inference.predict import load_model, reheader_document

model, tokenizer = load_model("joelbarmettler/md-reheader")

flat = open("document.md").read()
fixed = reheader_document(flat, model, tokenizer)

The package handles preprocessing (flattening + body stripping) and postprocessing (applying predicted levels back to the original document) automatically.

Direct transformers usage

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("joelbarmettler/md-reheader")
model = AutoModelForCausalLM.from_pretrained(
    "joelbarmettler/md-reheader",
    dtype=torch.bfloat16,
    device_map="auto",
)

messages = [
    {"role": "system", "content": "You are a markdown document structure expert. Given a markdown document with incorrect or flattened heading levels, output each heading with its correct markdown prefix (# for level 1, ## for level 2, etc.), one per line."},
    {"role": "user", "content": "# Introduction\n\nSome text...\n\n# Background\n\nMore text...\n\n# Methods"},
]

input_text = tokenizer.apply_chat_template(
    messages, tokenize=False, add_generation_prompt=True, enable_thinking=False,
)
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)

with torch.no_grad():
    outputs = model.generate(**inputs, max_new_tokens=4096, do_sample=False)

generated = outputs[0][inputs["input_ids"].shape[1]:]
print(tokenizer.decode(generated, skip_special_tokens=True))
# # Introduction
# ## Background
# ## Methods

Important: pass enable_thinking=False to apply_chat_template. Without it, the model enters a repetition loop because training used the non-thinking chat format.


Self-host with vLLM

md-reheader exposes the standard OpenAI-compatible chat endpoint when served with vLLM — higher throughput than raw transformers, and drop-in client compatibility.

pip install vllm
vllm serve joelbarmettler/md-reheader --dtype bfloat16 --max-model-len 8192

On <10 GB cards (e.g. RTX 2000/3060), add --enforce-eager --gpu-memory-utilization 0.70 to skip CUDA-graph allocations that otherwise OOM.

Remote inference (vLLM or any OpenAI-compatible endpoint)

Once a server is running, use md-reheader as a thin client — no local weights needed.

CLI:

rehead -i flat.md -o fixed.md --endpoint http://localhost:8000/v1
# With auth:
rehead -i flat.md -o fixed.md --endpoint https://api.example.com/v1 --api-key sk-xxx
# or set MD_REHEADER_API_KEY in the environment

Python:

from md_reheader.inference.remote import reheader_document_remote

fixed = reheader_document_remote(
    open("flat.md").read(),
    endpoint="http://localhost:8000/v1",
    model="joelbarmettler/md-reheader",
    api_key=None,  # or a bearer token
)

The remote client preprocesses locally (flatten + strip), sends a chat completion to the server with chat_template_kwargs={"enable_thinking": false} to match training, and applies predicted levels back to the original document. Identical output to local inference.

How it works

flat markdown  ──►  flatten headings to #  ──►  strip body to 128+128 tokens
                                                         │
                                                         ▼
        restored markdown  ◄──  apply predicted levels  ◄── Qwen3-0.6B (fine-tuned)
  1. Extract headings with markdown-it-py (correctly skips code blocks).
  2. Flatten every heading to # — the model ignores input levels.
  3. Strip each section's body to its first 128 + last 128 tokens — preserves structural cues, kills the context bloat.
  4. Qwen3-0.6B predicts the correct # prefix per heading.
  5. Levels get mapped back to the original document.

Evaluation

Benchmarked on 7,321 held-out documents from GitHub markdown and Wikipedia.

MetricAll-H1 baselineHeuristicmd-reheader
Exact match0.0%14.5%56.1%
Per-heading accuracy13.1%49.1%80.6%
Hierarchy preservation61.3%68.6%91.0%
Mean absolute error1.380.620.22

Per-level accuracy

H1H2H3H4H5H6
Accuracy77%85%78%68%45%50%

H1–H3 land in the 77–85% band; H5/H6 drop but still beat baselines. Most deep-level errors are off-by-one — the relative structure survives.

By document depth

Max depthExact matchPer-heading accuracyHierarchy
Depth 283%91%95%
Depth 354%82%90%
Depth 432%70%88%
Depth 5-633%65%89%

By source

SourceExact matchPer-heading accuracy
GitHub markdown49.5%74.0%
Wikipedia71.3%95.5%

Speed

Document sizeRTX 4090 (BF16)CPU (fp32)
< 1k tokens0.4s5s
1k–2k tokens0.8s10s
2k–4k tokens1.4s~20s
4k–8k tokens3.4s~60s

Documents longer than ~8k tokens (after stripping) are truncated from the tail.


Training

ItemValue
Base modelQwen/Qwen3-0.6B (text-only)
FrameworkAxolotl
Training data~197k markdown docs (GitHub + Wikipedia, depth 4+ oversampled 2–8×)
Hardware2× RTX 4090, DDP, BF16
Sequence length8,192 tokens with sample packing
Learning rate5e-5, cosine schedule
Epochs2 (epoch-1 checkpoint — epoch 2 overfits)
Effective batch24

Input format during training

  1. All headings flattened to # .
  2. Body text per section truncated to first 128 + last 128 tokens.
  3. Document truncated to 8k tokens.
  4. Assistant output: one heading per line with its correct # prefix.

Limitations

  • Deep nesting (H5/H6): accuracy drops to 45–50%. Relative structure is preserved but absolute depth gets compressed by 1–2 levels.
  • Ambiguous structure: heading levels are subjective. The model learns common conventions; it can't resolve genuine ambiguity.
  • Long documents: >8k tokens (after stripping) get truncated. Headings past the cutoff retain their input levels.
  • English-centric: trained primarily on English content.

Author

Built by Joel Barmettler at Souverana — an AI consultancy that helps teams design, fine-tune, evaluate, and ship production LLM systems. Need a small, self-hosted model that does one job well? Let's talk → souverana.ch

Citation

@software{barmettler2026mdreheader,
  author = {Barmettler, Joel},
  title  = {md-reheader: Restoring Heading Hierarchy in Markdown Documents},
  year   = {2026},
  url    = {https://github.com/joelbarmettlerUZH/md-reheader}
}

Как запустить

На своей GPU в ailist. Цена — по текущим предложениям провайдеров

GPU в ailist

Универсальный рантайм · transformers

Можно запустить

Подбираем GPU…

Класс архитектуры
Qwen3ForCausalLM
Ревизия весов
dd7a6ad

0 моделей