CoolFace
Datasetpublic

FatimahEmadEldin/Isnad-AI-Identifying-Islamic-Citation

Isnad AI: AraBERT for Ayah & Hadith Span Detection in LLM Outputs This repository contains the official fine-tuned model for the Isnad AI system, the submission to the IslamicEval 2025 Shared Task 1A. The model is designed to identify character-level spans of Quranic verses (Ayahs) and Prophetic sayings (Hadiths) within text generated by Large Language Models (LLMs). By: Fatimah Emad Eldin Cairo University ๐Ÿ“œ Model Descriptionโ€ฆ See the full description on the dataset page: https://huggingface.co/datasets/FatimahEmadEldin/Isnad-AI-Identifying-Islamic-Citation.

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
1likes19downloads
Dataset Card

Isnad AI: AraBERT for Ayah & Hadith Span Detection in LLM Outputs

<p align="center"> <img src="https://placehold.co/800x200/dbeafe/3b82f6?text=Isnad+AI+-+Islamic+Citation+Detection" alt="Isnad AI - Islamic Citation Detection"> </p>

This repository contains the official fine-tuned model for the Isnad AI system, the submission to the [IslamicEval 2025 Shared Task 1A](https://sites.google.com/view/islamiceval-2025). The model is designed to identify character-level spans of Quranic verses (Ayahs) and Prophetic sayings (Hadiths) within text generated by Large Language Models (LLMs).

By: Fatimah Emad Eldin
Cairo University

![Paper](https://www.codabench.org/competitions/9820/) ![Code](https://github.com/astral-fate/IslamicEval) ![HuggingFace](https://huggingface.co/collections/FatimahEmadEldin/) ![License](https://github.com/astral-fate/IslamicEval/blob/main/LICENSE)


๐Ÿ“œ Model Description

This model fine-tunes AraBERTv2 (aubmindlab/bert-base-arabertv2) on a specialized token classification task. Its purpose is to label tokens within a given Arabic text according to the BIO schema:

  • โ€”B-Ayah (Beginning of a Quranic verse)
  • โ€”I-Ayah (Inside a Quranic verse)
  • โ€”B-Hadith (Beginning of a Prophetic saying)
  • โ€”I-Hadith (Inside a Prophetic saying)
  • โ€”O (Outside of any religious citation)

The key innovation behind this model is a novel rule-based data generation pipeline. This method was developed to address the critical lack of large, manually annotated datasets for this specific task. By programmatically creating a large-scale, high-quality training corpus from authentic religious texts, we completely eliminated the need for manual annotation. This approach proved highly effective, enabling the model to learn the contextual patterns of how LLMs cite Islamic sources, achieving an F1-score of 66.97% on the official blind test set.


๐Ÿš€ How to Use

You can easily use this model with the transformers library pipeline for token-classification (or ner). For best results, use aggregation_strategy="simple" to group token pieces into coherent entities.

python
from transformers import pipeline

# Load the token classification pipeline
model_id = "FatimahEmadEldin/Isnad-AI-Identifying-Islamic-Citation"
islamic_ner = pipeline(
    "token-classification",
    model=model_id,
    aggregation_strategy="simple"
)

# Example text from an LLM response
text = "ูŠูˆุถุญ ู„ู†ุง ุงู„ุฏูŠู† ุฃู‡ู…ูŠุฉ ุงู„ุตุฏู‚ุŒ ูููŠ ุงู„ุญุฏูŠุซ ุงู„ุดุฑูŠู ู†ุฌุฏ ุฃู† ุงู„ู†ุจูŠ ู‚ุงู„: ุนู„ูŠูƒู… ุจุงู„ุตุฏู‚. ูƒู…ุง ุฃู†ุฒู„ ุงู„ู„ู‡ ููŠ ูƒุชุงุจู‡ ุงู„ูƒุฑูŠู…: ูŠุง ุฃูŠู‡ุง ุงู„ุฐูŠู† ุขู…ู†ูˆุง ุงุชู‚ูˆุง ุงู„ู„ู‡ ูˆูƒูˆู†ูˆุง ู…ุน ุงู„ุตุงุฏู‚ูŠู†."

# Get the identified spans
results = islamic_ner(text)

# Print the results
for entity in results:
    print(f"Entity: {entity['word']}")
    print(f"Label: {entity['entity_group']}")
    print(f"Score: {entity['score']:.4f}\n")

# Expected output:
# Entity: ุนู„ูŠูƒู… ุจุงู„ุตุฏู‚
# Label: Hadith
# Score: 0.9876

# Entity: ูŠุง ุฃูŠู‡ุง ุงู„ุฐูŠู† ุขู…ู†ูˆุง ุงุชู‚ูˆุง ุงู„ู„ู‡ ูˆูƒูˆู†ูˆุง ู…ุน ุงู„ุตุงุฏู‚ูŠู†
# Label: Ayah
# Score: 0.9912

โš™๏ธ Dataset Curation and Statistics

The model was trained exclusively on a synthetically generated dataset. The motivation was to overcome the data scarcity problem for this specialized task by creating realistic, contextualized examples that mimic how LLMs cite religious texts. The entire training and validation dataset was generated using a multi-stage pipeline.

Data Sources and Preprocessing

  1. 1.Data Sourcing: Authentic texts were sourced from quran.json (containing all 6,236 Quranic verses) and a JSON file of the Six Major Hadith Collections (containing over 34,000 narrations).
  1. 1.Text Splitting: To prevent sequence truncation during tokenization, any Quranic verse exceeding a 25-token length was split into two smaller, more manageable segments. This crucial step increased the number of unique Ayah texts from 6,236 to 6,910.
  1. 1.Normalization and Augmentation (Tashkeel Removal): To improve the model's robustness against script variations, a duplicate version of every Ayah was created with all Arabic diacritics (Tashkeel) removed. This data augmentation step effectively doubled the number of unique Ayah texts to 13,820, training the model to recognize verses regardless of vocalization.
  1. 1.Template-Based Generation: The core of the pipeline involves embedding these processed religious texts into contextual templates. Each unique text was used to generate multiple training examples by randomly combining it with different prefixes, suffixes, and neutral connecting sentences (detailed below). This simulates how these texts are typically cited in generated content.

Dataset Splits and Distribution

From the augmented collection of 45,137 unique religious texts, a 70/30 split was employed to create the training and validation sets. The template-based generation process was then applied to both sets to create the final corpus.

StageCorpusAyah CountHadith CountTotal Unique TextsTotal Generated Examples
SourceOriginal Texts6,23634,66240,898-
PreprocessingAfter Augmentation13,82031,31745,137-
Final SplitTraining Set (70%)20,62272,47731,03393,099
Final SplitValidation Set (30%)20,31320,31313,54240,626
TOTAL-40,93592,79044,575133,725

Template Component Examples

The following table details the components used to programmatically construct the training data.

Component TypeClassTraining Set ExamplesValidation Set Examples
PrefixesAyahู‚ุงู„ ุงู„ู„ู‡ ุชุนุงู„ู‰:, ูˆู‚ุงู„ ุงู„ู„ู‡ ุนุฒ ูˆุฌู„:, ูƒู…ุง ูˆุฑุฏ ููŠ ุงู„ู‚ุฑุขู† ุงู„ูƒุฑูŠู…:, ูˆููŠ ูƒุชุงุจ ุงู„ู„ู‡:, ูˆู…ู† ุขูŠุงุช ุงู„ู„ู‡:, ูŠู‚ูˆู„ ุณุจุญุงู†ู‡ ูˆุชุนุงู„ู‰:ูˆููŠ ุงู„ู‚ุฑุขู† ุงู„ูƒุฑูŠู… ู†ุฌุฏ:, ูˆู…ู† ุขูŠุงุช ุงู„ู„ู‡:, ูˆู‚ุฏ ุฃู†ุฒู„ ุงู„ู„ู‡:, ูˆูŠู‚ูˆู„ ุงู„ุญู‚ ุชุจุงุฑูƒ ูˆุชุนุงู„ู‰:, ูˆููŠ ุงู„ุฐูƒุฑ ุงู„ุญูƒูŠู…:, ูˆุงู„ุฏู„ูŠู„ ุนู„ู‰ ุฐู„ูƒ ู‚ูˆู„ู‡ ุชุนุงู„ู‰:
SuffixesAyahุตุฏู‚ ุงู„ู„ู‡ ุงู„ุนุธูŠู…, ุขูŠุฉ ูƒุฑูŠู…ุฉ, ู…ู† ุงู„ู‚ุฑุขู† ุงู„ูƒุฑูŠู…, ูƒู„ุงู… ุงู„ู„ู‡ ุนุฒ ูˆุฌู„, ู…ู† ุงู„ุฐูƒุฑ ุงู„ุญูƒูŠู…, ูˆู‡ุฐุง ุจูŠุงู† ู„ู„ู†ุงุณู‡ุฐุง ู…ู† ูƒู„ุงู… ุงู„ู„ู‡, ุขูŠุฉ ุนุธูŠู…ุฉ, ู…ู† ุงู„ู‚ุฑุขู† ุงู„ูƒุฑูŠู…, ูƒู„ุงู… ุฑุจ ุงู„ุนุงู„ู…ูŠู†, ู…ู† ุงู„ุฐูƒุฑ ุงู„ุญูƒูŠู…, (ุตุฏู‚ ุงู„ู„ู‡ ุงู„ุนุธูŠู…)
PrefixesHadithู‚ุงู„ ุฑุณูˆู„ ุงู„ู„ู‡ ุตู„ู‰ ุงู„ู„ู‡ ุนู„ูŠู‡ ูˆุณู„ู…:, ูˆู‚ุงู„ ุงู„ู†ุจูŠ ุตู„ู‰ ุงู„ู„ู‡ ุนู„ูŠู‡ ูˆุณู„ู…:, ุนู† ุงู„ู†ุจูŠ ุตู„ู‰ ุงู„ู„ู‡ ุนู„ูŠู‡ ูˆุณู„ู…:, ุฑูˆู‰ ุฃู† ุงู„ู†ุจูŠ ุตู„ู‰ ุงู„ู„ู‡ ุนู„ูŠู‡ ูˆุณู„ู… ู‚ุงู„:, ูˆููŠ ุงู„ุญุฏูŠุซ ุงู„ุดุฑูŠู:ูˆููŠ ุงู„ุณู†ุฉ ุงู„ู†ุจูˆูŠุฉ:, ูˆู…ู† ู‡ุฏูŠ ุงู„ู†ุจูŠ ุตู„ู‰ ุงู„ู„ู‡ ุนู„ูŠู‡ ูˆุณู„ู…:, ูˆู‚ุฏ ุนู„ู…ู†ุง ุงู„ุฑุณูˆู„ ุตู„ู‰ ุงู„ู„ู‡ ุนู„ูŠู‡ ูˆุณู„ู…:, ูˆููŠ ุงู„ุญุฏูŠุซ ุงู„ุดุฑูŠู ู†ุฌุฏ:, ูƒู…ุง ุฌุงุก ููŠ ุงู„ุญุฏูŠุซ:
SuffixesHadithุฑูˆุงู‡ ุงู„ุจุฎุงุฑูŠ, ุฑูˆุงู‡ ู…ุณู„ู…, ุญุฏูŠุซ ุตุญูŠุญ, ุตู„ู‰ ุงู„ู„ู‡ ุนู„ูŠู‡ ูˆุณู„ู…, ู…ู† ุงู„ุณู†ุฉ ุงู„ู†ุจูˆูŠุฉ, (ู…ุชูู‚ ุนู„ูŠู‡)ู…ู† ุงู„ุณู†ุฉ ุงู„ู†ุจูˆูŠุฉ, ุญุฏูŠุซ ู†ุจูˆูŠ ุดุฑูŠู, ู…ู† ู‡ุฏูŠ ุงู„ู…ุตุทูู‰, ุตู„ู‰ ุงู„ู„ู‡ ุนู„ูŠู‡ ูˆุณู„ู…, (ุฑูˆุงู‡ ุงู„ุชุฑู…ุฐูŠ)
Neutral SentencesBothูˆุจู†ุงุก ุนู„ู‰ ุฐู„ูƒุŒ ูŠู…ูƒู†ู†ุง ุฃู† ู†ุณุชู†ุชุฌ., ูˆู‡ุฐุง ูŠูˆุถุญ ุนุธู…ุฉ ุงู„ุชุดุฑูŠุน., ูˆููŠ ู‡ุฐุง ู‡ุฏุงูŠุฉ ู„ู„ู…ุคู…ู†ูŠู†., ุฅู† ููŠ ุฐู„ูƒ ู„ุขูŠุงุช ู„ู‚ูˆู… ูŠุนู‚ู„ูˆู†.ูˆู„ู†ุชุฃู…ู„ ู…ุนุงู‹, ูˆููŠ ู‡ุฐุง ุงู„ุณูŠุงู‚, ูˆู„ู„ุชูˆุถูŠุญ, ูˆุฅู„ูŠูƒู… ุงู„ู…ุซุงู„, ูˆููŠ ู‡ุฐุง ุงู„ุตุฏุฏ, ูˆู‡ุฐุง ูŠุจูŠู† ู„ู†ุง ุฃู‡ู…ูŠุฉ ุงู„ู…ูˆุถูˆุน.

Fine-Tuning

The aubmindlab/bert-base-arabertv2 model was fine-tuned with the following key hyperparameters:

  • โ€”Learning Rate: 2e-5
  • โ€”Epochs: 10 (with early stopping patience of 3)
  • โ€”Effective Batch Size: 16 (4 per device with 4 gradient accumulation steps)
  • โ€”Optimizer: AdamW
  • โ€”Weight Decay: 0.01
  • โ€”Warmup Steps: 500
  • โ€”Mixed Precision: fp16 enabled
  • โ€”Max Sequence Length: 512 tokens

๐Ÿ“Š Evaluation Results

The model was evaluated using the official character-level Macro F1-Score metric for the IslamicEval 2025 shared task.

Official Test Set Results

The system achieved a final F1-score of 66.97% on the blind test set, demonstrating the effectiveness of the rule-based data generation approach.

MethodologyTest F1 Score
Isnad AI (Rule-Based Model)66.97%
Generative Data (Ablation)50.50%
Database Lookup (Ablation)34.80%

Development Set Performance

A detailed evaluation on the manually annotated development set provided by the organizers shows a strong and balanced performance.

Final Macro F1-Score on Dev Set: 65.08%

Per-Class Performance (Character-Level)
ClassPrecisionRecallF1-Score
๐ŸŸข Neither0.84230.96880.9011
๐Ÿ”ต Ayah0.83260.55740.6678
๐ŸŸก Hadith0.47500.33330.3917
Overall0.71660.61980.6535

(These results are from the official `scoring.py` script run on the development set).


โš ๏ธ Limitations and Bias

  • โ€”Performance on Hadith: The model's primary challenge is identifying Hadith texts, which have significantly more linguistic and structural variety than Quranic verses. The F1-score for the Hadith class is lower than for Ayah, indicating it may miss or misclassify some prophetic sayings.
  • โ€”Template Dependency: The model's knowledge is based on the rule-based templates used for training. It may be less effective at identifying citations that appear in highly novel or unconventional contexts not represented in the training data.
  • โ€”Scope: This model identifies intended citations, as per the shared task rules. It does not verify the authenticity or correctness of the citation itself. An LLM could generate a completely fabricated verse, and this model would still identify it if it is presented like a real one.

โœ๏ธ Citation

If you use this model or the methodology in your research, please cite the paper:

bibtex
  Coming soon