YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

Automatic Hadith Isnad Parsing Models

Fine-tuned transformer models for automatic isnad parsing: extracting narrator mentions and narration relations (who narrated to whom) from hadith isnad text. Use the output to build graph representations of transmission chains for authenticity analysis, visualization, and retrieval.

Contents: What is isnad parsing? · Example: model input and output · Model architectures · Hugging Face models · Data · Results · Installation · How to use · Reference · License


What is isnad parsing?

The isnad is the chain of narrators at the start of a hadith; it records who transmitted the report across generations. Isnad parsing means:

  1. Narrator recognition — identifying narrator mentions (and optionally narration words) in the isnad text.
  2. Relation extraction — extracting direct narration links as (head, tail) pairs: the head is the receiver of the hadith, the tail is the transmitter.

When a hadith has multiple chains (branching or parallel paths), we can also predict a chain identifier per link, giving (head, tail, chain_number) triplets so that each transmission path stays distinct in the graph.

  • Chain-blind: output is duplets (head, tail) only; no chain IDs. Suitable for a single merged graph of all links (no validation on paths).
  • Chain-aware: output is triplets (head, tail, chain_number); suitable for reconstructing separate paths and building property graphs with chain IDs on edges.

Example: The following isnad encodes three distinct transmission chains that share some narrators but branch into different paths. Preserving a chain identifier per relation is necessary to avoid invalid narration paths when building the graph.

Isnad (Arabic and translation):

حدثنا مسدد ، حدثنا يحيى ، عن سفيان قال: حدثني منصور وسليمان ، عن أبي وائل ، عن أبي ميسرة ، عن عبد الله . قال: وحدثني واصل ، عن أبي وائل ، عن عبد الله - رضي الله عنه...

Musaddad narrated to us, Yahya narrated to us, from Sufyan, who said: Mansur and Sulaiman narrated to me, from Abu Wa'il, from Abu Maysarah, from Abdullah. He said: Wasil also narrated to me, from Abu Wa'il, from Abdullah – may Allah be pleased with him...

This hadith isnad has three narration chains. They share the same opening (Musaddad ← Yahya ← Sufyan) but then branch:

  • Chain 1 goes through Wasil: Sufyan ← Wasil ← Abu Wa'il ← Abdullah.
  • Chain 2 goes through Sulaiman: Sufyan ← Sulaiman ← Abu Wa'il ← Abu Maysarah ← Abdullah.
  • Chain 3 goes through Mansur: Sufyan ← Mansur ← Abu Wa'il ← Abu Maysarah ← Abdullah.

Without chain numbers, merging all (head, tail) links into one graph would mix these paths and create invalid connections. The figures below show each chain separately, then the merged graph with chain numbers on the edges.

Chain 1 (Wasil path):

Graph representation of chain 1

Chain 2 (Sulaiman path):

Graph representation of chain 2

Chain 3 (Mansur path):

Graph representation of chain 3

Merged graph (all three chains, with chain numbers on edges):

Complete hadith isnad as narration graph


Example: model input and output

The models take raw isnad text and generate a linearized sequence of relation tuples. Below: one input and its chain-blind and chain-aware outputs.

Input (Arabic isnad as in source text). English translation for demonstration:

حدثنا يوسف القاضي ، ثنا عبد الواحد بن غياث ، ثنا حماد بن سلمة ، عن أيوب وعبيد الله بن عمر ، عن نافع ، عن ابن عمر قال : قال زيد بن ثابت...

Yusuf Al-Qadi narrated to us, saying: Abdul Wahid bin Ghayath narrated to us, saying: Hammad bin Salamah narrated to us, from Ayyub and Ubaidullah bin Umar, from Nafi', from Ibn Umar, who said: Zaid bin Thabit said...

Chain-blind output (duplets only; no chain IDs). Each relation is <head> receiver <tail> transmitter; the sequence ends with #hadith.:

<head> يوسف القاضي <tail> عبد الواحد بن غياث
<head> عبد الواحد بن غياث <tail> حماد بن سلمة
<head> حماد بن سلمة <tail> عبيد الله بن عمر
<head> حماد بن سلمة <tail> أيوب
<head> عبيد الله بن عمر <tail> نافع
<head> أيوب <tail> نافع
<head> نافع <tail> ابن عمر
<head> ابن عمر <tail> زيد بن ثابت #hadith

Chain-aware output (triplets with chain identifier). Each relation adds <chain_number> k so that the two transmission paths stay distinct.:

<head> يوسف القاضي <tail> عبد الواحد بن غياث <chain_number> 1
<head> عبد الواحد بن غياث <tail> حماد بن سلمة <chain_number> 1
<head> حماد بن سلمة <tail> عبيد الله بن عمر <chain_number> 1
<head> عبيد الله بن عمر <tail> نافع <chain_number> 1
<head> نافع <tail> ابن عمر <chain_number> 1
<head> ابن عمر <tail> زيد بن ثابت <chain_number> 1
<head> يوسف القاضي <tail> عبد الواحد بن غياث <chain_number> 2
<head> عبد الواحد بن غياث <tail> حماد بن سلمة <chain_number> 2
<head> حماد بن سلمة <tail> أيوب <chain_number> 2
<head> أيوب <tail> نافع <chain_number> 2
<head> نافع <tail> ابن عمر <chain_number> 2
<head> ابن عمر <tail> زيد بن ثابت <chain_number> 2
#hadith

Model architectures

Base model Type Description
CAMeLBERT-CA Encoder (BERT) Pre-trained on Classical Arabic. Joint NER + relation classification (biaffine). Outputs chain-blind duplets only. Best for high-precision direct links.
AraT5 Encoder–decoder (T5) T5 for Arabic; text-to-text. Can be fine-tuned for chain-blind or chain-aware output. Best for chain-aware triplets and full graph reconstruction.
AraBART Encoder–decoder (BART) BART for Arabic; denoising pretraining. Can be fine-tuned for chain-blind or chain-aware output. May show more spelling variation; useful for tasks like narrator normalization.

With-prefix vs without-prefix: Some models were trained with a task prefix (e.g. [isnad]) in the input; others without. Use the variant that matches your intended input format.


Hugging Face models

All models are hosted on the Hugging Face Hub. Choose by task (chain-blind vs chain-aware) and base architecture (CAMeLBERT-CA, AraT5, AraBART).

Chain-blind (duplets only)

Model Hugging Face
CAMeLBERT-CA (chain-blind) Jehadoumer/ChainBlind-HadithIsnadParser-CAMeLBERT
AraT5 (chain-blind, with prefix) Jehadoumer/ChainBlind-HadithIsnadParser-withPrefix-AraT5
AraT5 (chain-blind, no prefix) Jehadoumer/ChainBlind-HadithIsnadParser-AraT5
AraBART (chain-blind, with prefix) Jehadoumer/ChainBlind-HadithIsnadParser-withPrefix-AraBART
AraBART (chain-blind, no prefix) Jehadoumer/ChainBlind-HadithIsnadParser-AraBART

Chain-aware (triplets with chain number)

Model Hugging Face
AraT5 (chain-aware, with prefix) Jehadoumer/ChainAware-HadithIsnadParser-withPrefix-AraT5
AraT5 (chain-aware, no prefix) Jehadoumer/ChainAware-HadithIsnadParser-AraT5
AraBART (chain-aware, with prefix) Jehadoumer/ChainAware-HadithIsnadParser-withPrefix-AraBART
AraBART (chain-aware, no prefix) Jehadoumer/ChainAware-HadithIsnadParser-AraBART

Data used for training and evaluation

Source. Training and evaluation data come from the Ifta' Sunnah Platform (King Abdullah bin Abdul Aziz Program for the Prophetic Sunnah), and curated for the experiment at Ifta-Sunnah–Hadith-and-Narrators-Dataset. The platform provides 33 foundational hadith books (Kutub al-Matn), plus 57 additional books with supportive and interpretative content; the hadith dataset used here was extracted from the 33 books, which are organized mainly by hadith content (thematic). In total, 276,347 hadiths were extracted from the platform; after preprocessing (isnad isolation, entity tagging, relation tuples, and filtering), 223,478 hadith instances were used for automatic isnad parsing.

Splits. The dataset was split 70% training, 15% validation, 15% testing. Summary:

Training Validation Testing
Hadiths 156,434 33,521 33,523
Duplets (chain-blind relations) 756,714 162,782 162,010
Triplets (chain-aware relations) 877,016 190,049 188,755

Results summary (test set)

Models are evaluated on the held-out test set (33,523 hadith isnad texts). Metrics: exact match for relations; narrator set comparison for narrator recognition. Tables below include with-prefix and no-prefix variants for the encoder–decoder models.

Narrator recognition (predicted vs gold set of narrators)

Model Precision Recall F1
CAMeLBERT-CA 0.98 0.99 0.98
AraT5 0.97 0.97 0.97
AraT5-Prefix 0.97 0.97 0.97
AraBART 0.78 0.94 0.84
AraBART-Prefix 0.78 0.94 0.84

Chain-blind relation extraction (duplets)

Model Precision Recall F1
CAMeLBERT-CA 0.96 0.93 0.95
AraT5 0.96 0.95 0.95
AraT5-Prefix 0.96 0.95 0.95
AraBART 0.66 0.64 0.65
AraBART-Prefix 0.66 0.65 0.65

Chain-aware relation extraction (triplets)

Only the encoder–decoder models produce chain-aware output.

Model Precision Recall F1
AraT5 0.94 0.93 0.93
AraT5-Prefix 0.94 0.93 0.93
AraBART 0.76 0.37 0.48
AraBART-Prefix 0.76 0.37 0.48

Installation

pip install torch transformers huggingface_hub safetensors

The CAMeLBERT-CA Hub repo provides model.safetensors; the inference script loads that when using --model-id.


How to use

CAMeLBERT-CA (chain-blind): inference script in this repo

The CAMeLBERT-CA model does not output duplets directly from raw text. It needs a pipeline that: (1) runs NER to get narrator spans, (2) builds candidate head–tail duplets, and (3) runs the biaffine classifier on each candidate. This repo provides that pipeline in camelbert_duplets_biaffine_inference.py.

Run inference (loads the model from Hugging Face by default):

# Built-in example isnad
python camelbert_duplets_biaffine_inference.py --no-cuda

# Your own isnad text (space-separated words)
python camelbert_duplets_biaffine_inference.py --input "حدثنا أبو معاوية حدثنا الأعمش عن مسلم" --no-cuda

# From a JSONL file (one JSON object per line with "isnad_sequence" or "isnad_text")
python camelbert_duplets_biaffine_inference.py --input-file examples.jsonl --no-cuda

Output: One line per input in chain-blind form: <head> A <tail> B <head> B <tail> C ... #hadith

To use a local checkpoint (same format as training output): --checkpoint path/to/best_model.pth

Test on random examples from the predictions JSON (install ijson for large files):

pip install ijson
python test_camelbert_inference_from_predictions.py --predictions-json "path/to/predictions_camelbert_duplets_biaffine.json" --num-examples 2 --no-cuda

AraT5 / AraBART (chain-blind or chain-aware)

These models generate the linearized output directly from raw isnad text:

from transformers import AutoModelForSeq2SeqLM, AutoTokenizer

model_name = "Jehadoumer/ChainBlind-HadithIsnadParser-AraT5"  # or any other model ID above
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

# Input: raw isnad text (Arabic)
isnad_text = "..."  # e.g. "حدثنا فلان، حدثنا فلان، عن فلان..."
inputs = tokenizer(isnad_text, return_tensors="pt", truncation=True, max_length=512)
outputs = model.generate(**inputs, max_new_tokens=512)

# Decode and parse <head> / <tail> (and optionally <chain_number>) from the output
decoded = tokenizer.decode(outputs[0], skip_special_tokens=False)
# Then extract (head, tail) or (head, tail, chain_number) from decoded.

Output format: chain-blind — sequence of <head> A <tail> B segments ending with #hadith. Chain-aware — each segment also includes <chain_number> k. Parse with regex or the same logic as in the evaluation scripts.


Reference

If you use these models or the dataset in your work, please cite the thesis and the original data source as appropriate.


License

This project is released under an open-source license that allows use, modification, and distribution with attribution to the creators. The base models (CAMeLBERT-CA, AraT5, AraBART) follow their respective upstream licenses; the fine-tuned weights are released under the same open-source, attribution-based terms.

Downloads last month
1
Safetensors
Model size
0.4B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support