๐Ÿ’œ Github   |   ๐Ÿค— Hugging Face   |   ๐Ÿ“š Cookbooks  
๐Ÿ–ฅ๏ธ Demo  

๐Ÿ•Œ 3arabLM-4B-Islamic-v2

A Specialized Arabic Language Model for Islamic Heritage


๐Ÿ“– Abstract

3arabLM-4B-Islamic-v2 is an ongoing research model dedicated to learning, preserving, recalling, and reconstructing the Arabic Islamic scholarly heritage from classical and authoritative sources. Unlike general-purpose conversational LLMs, the primary objective of 3arabLM is not to imitate everyday conversations or produce short modern summaries. Instead, the project investigates whether a language model can function as a compressed digital library of classical Islamic scholarship, with substantial scholarly knowledge encoded directly into its parameters.

Learn from the books. Preserve the language. Preserve the methodology. Preserve the diversity.

โš ๏ธ **The current model represents less than 5% of the planned continual pretraining schedule. The full project is expected to expand over multiple stages covering nearly the complete Al-Maktaba Al-Shamela ecosystem. .


๐ŸŒŸ Project Vision

3arabLM is a long-term research project focused on building a large-scale Arabic language model specialized in the Islamic scholarly heritage. The long-term objective is to gradually expand the model across a broad range of Islamic and Arabic sciences rather than limiting it to a single discipline.


๐Ÿ“š Current Domains (Version v2)

The current release has been continued-pretrained on six scholarly domains from the Shamela corpus:

Domain Description
๐Ÿ“– Fiqh Islamic Jurisprudence
๐Ÿ“œ Tafsir Quranic Exegesis
๐Ÿ“š Hadith Prophetic Traditions and Hadith Sciences
๐Ÿ•Œ Aqeedah Islamic Creed and Theology
โœ๏ธ Nahw and Sarf Arabic Grammar and Morphology
โš–๏ธ Fatwas Legal Opinions and Verdicts

๐Ÿ—บ๏ธ Planned Corpus Expansion

Future releases will progressively expand the corpus with additional collections, commentaries, manuscripts, scholarly editions, and specialized literature across Hadith, Tafsir, Fiqh, Arabic linguistics, history, biography, literature, and related fields.


๐Ÿง  Research Philosophy

The central philosophy of 3arabLM can be summarized as:

Large Language Models as Compressed Digital Libraries

Instead of treating a language model primarily as a text generator, this project investigates whether model parameters can encode substantial amounts of classical scholarly knowledge.

The project therefore explores a different paradigm:

Retrieval from Weights

rather than relying exclusively on:

Retrieval-Augmented Generation (RAG)

The objective is not to eliminate retrieval systems, but to investigate how much scholarly knowledge can be learned and reconstructed directly from the model's internal parameters.


๐Ÿ“– Training Philosophy

3arabLM follows a source-oriented training philosophy.

Instead of maximizing general internet-scale diversity, the project focuses on carefully curated scholarly literature.

The model is trained to learn:

  • Classical Arabic vocabulary.
  • Scholarly terminology.
  • Author-specific writing styles.
  • Book structures.
  • Scholarly argumentation.
  • Different methodologies.
  • Different schools of jurisprudence.
  • Different interpretations.
  • Historical context.
  • Relationships between scholarly works.

The objective is to preserve the diversity of Islamic scholarship rather than collapsing it into a single generalized representation.


๐Ÿ›๏ธ Preserving Scholarly Diversity

A central objective of this project is to preserve differences between scholars, books, schools, and methodologies.

For example:

  • Tafsir al-Tabari โ‰  Tafsir Ibn Kathir โ‰  Tafsir al-Qurtubi
  • Hanafi โ‰  Maliki โ‰  Shafi'i โ‰  Hanbali

The model is intended to learn that different scholars may have:

  • Different methodologies.
  • Different interpretations.
  • Different evidence.
  • Different terminology.
  • Different jurisprudential positions.
  • Different writing styles.

Scholarly disagreement is therefore treated as part of the knowledge itself rather than as noise to be removed.


โœ๏ธ Classical Arabic Preservation

One of the main objectives of 3arabLM is to preserve the linguistic characteristics of classical Arabic scholarship.

The model is designed to learn:

  • Classical Arabic syntax.
  • Classical vocabulary.
  • Scholarly terminology.
  • Traditional expressions.
  • Author-specific language.
  • Classical argumentation.
  • Historical linguistic patterns.

The project investigates whether continual pretraining on large scholarly corpora can produce models capable of reconstructing texts in language close to their original scholarly style.


๐Ÿ“š Training Corpus

A major foundation of the project is Al-Maktaba Al-Shamela, together with other Arabic scholarly and heritage sources.

The current and developing corpus covers a broad range of Arabic and Islamic scholarship, including:

๐Ÿ“– Tafsir & Quranic Sciences ๐Ÿ“š Hadith Sciences & Hadith Literature โš–๏ธ Fiqh & Usul al-Fiqh ๐Ÿง  Aqeedah & Islamic Theology ๐Ÿ•‹ Sirah & Prophetic Biography ๐Ÿ› Islamic History & Civilization ๐Ÿ‘ค Biography, Tabaqat & Rijal ๐Ÿ“ Arabic Language, Grammar & Morphology ๐Ÿ”ค Lexicography & Dictionaries ๐Ÿ“š Classical Literature & Poetry ๐Ÿ•ฏ Spiritual & Ethical Literature ๐Ÿ“‘ Scholarly Research, Bibliographies & Catalogs The corpus is continuously expanding to provide broader coverage of the classical Arabic scholarly tradition and its diverse textual genres. Official Library: goldenshamela


๐Ÿ”ง Knowledge Extraction Pipeline

The corpus is transformed through a dedicated extraction and preprocessing pipeline.

                    Shamela
                       โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ”‚                             โ”‚
      Books                       Indices
        โ”‚                             โ”‚
        โ–ผ                             โ–ผ
   Text Parser                  Keyword Parser
        โ”‚                             โ”‚
        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ–ผ
            Unified Page Builder
                       โ”‚
      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
      โ–ผ            โ–ผ            โ–ผ
   Metadata        TOC       Keywords
                       โ”‚
                       โ–ผ
                 pages.parquet
                       โ”‚
      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
      โ–ผ            โ–ผ            โ–ผ
      CPT          SFT          RAG
                       โ”‚
        Book โ†’ Chapter โ†’ Section โ†’ Paragraph โ†’ Sentence


The preprocessing pipeline aims to preserve the hierarchical structure of scholarly books:


This structure provides contextual information beyond plain text.

๐Ÿงฌ Metadata-Aware Training

Future training stages will increasingly incorporate structured metadata.

Planned metadata includes:

Field Description
Book ID Unique book identifier
Author ID Author identifier
Century Historical period
Madhhab Jurisprudential school
Book Hierarchy Book โ†’ Chapter โ†’ Section
Discipline Scholarly domain
Semantic Tags Domain-specific information

The objective is to strengthen the model's understanding of scholarly context and relationships between texts.


๐Ÿ“Š Preliminary Results

Initial experiments suggest that the model is developing distinguishable internal representations across Islamic scholarly domains.

Key Findings from Representation Diagnostic Analysis

Metric Layer 0 Layer 31
Linear Probe Accuracy 53.80% 82.78%
Macro-F1 0.537 0.824
Average Domain CKA 0.0542 0.0259
Stable Rank 10.59 5.76

These results indicate that:

  • Domain discriminability increases substantially with depth.
  • Cross-domain representation similarity decreases sharply in the final layer.
  • Stable rank follows a non-monotonic trajectory and reaches a pronounced minimum at the final layer.

This suggests that continued pretraining on Shamela is associated with increasingly specialized final-layer representations, characterized by higher domain discriminability and a more concentrated activation spectrum. ** research paper :**

๐Ÿง  Why Memorization?

Modern LLM research frequently relies on Retrieval-Augmented Generation (RAG).


A traditional RAG pipeline can be represented as:
User Question
โ†“
Retriever
โ†“
External Knowledge Base
โ†“
Relevant Documents
โ†“
Language Model
โ†“
Answer


3arabLM investigates a complementary direction:
User Question
โ†“
Language Model
โ†“
Internal Parameters
โ†“
Knowledge Recall
โ†“
Reconstruction

The central research question is:

Can a sufficiently trained language model become a compressed scholarly library?

This project does not claim that external retrieval is unnecessary. Instead, it investigates the capacity of model parameters to store and reconstruct specialized scholarly knowledge.


๐Ÿ—๏ธ Long-Term Architecture

The long-term vision is based on a shared foundation model followed by specialized expert models.


3arabLM Foundation
โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ–ผ      โ–ผ      โ–ผ       โ–ผ       โ–ผ
Fiqh Hadith Tafsir Aqeedah History
Expert Expert Expert Expert Expert
โ”‚ โ”‚ โ”‚ โ”‚ โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
Islamic Heritage
Expert Ecosystem

Potential future experts include:

  • Fiqh Expert.
  • Hadith Expert.
  • Tafsir Expert.
  • Aqeedah Expert.
  • Islamic History Expert.
  • Arabic Language Expert.
  • Literature Expert.
  • Spiritual Literature Expert.

๐Ÿ“ˆ Future Model Scaling

Future research will investigate ways to increase model capacity while preserving previously learned knowledge.

Potential directions include:

  • Additional Transformer layers.
  • Duplicated upper Transformer blocks.
  • Small stochastic initialization.
  • Continual pretraining.
  • Knowledge-preserving scaling.
  • Expert-specialized adapters.
  • Metadata-aware training.
  • Catastrophic forgetting mitigation.

The goal is to increase memorization capacity while maintaining previously acquired scholarly knowledge.


๐Ÿ“ฆ Current Release

Model: sherif1313/3arabLM-4B-islamic-v2

This release represents a new stage in the 3arabLM research project. The previous development focused more narrowly on Islamic scholarly domains such as Fiqh and Tafsir. The new direction expands the training curriculum toward a broader Islamic Heritage Foundation Model covering multiple branches of Islamic and Arabic scholarship. The model should still be considered an early research milestone. A sustantial portion of the planned training curriculum remains to be completed.

These books have been preserved in the model weightsูˆ 

ุงู„ู†ุญูˆ ุงู„ูˆุงููŠ
ุชู…ู‡ูŠุฏ ุงู„ู‚ูˆุงุนุฏ ุจุดุฑุญ ุชุณู‡ูŠู„ ุงู„ููˆุงุฆุฏ
ุดุฑุญ ุฃู„ููŠุฉ ุงุจู† ู…ุงู„ูƒ ู„ู„ุญุงุฒู…ูŠ
ุดุฑุญ ุฃู„ููŠุฉ ุงุจู† ู…ุงู„ูƒ ู„ู„ุดุงุทุจูŠ = ุงู„ู…ู‚ุงุตุฏ ุงู„ุดุงููŠุฉ
ุดุฑุญ ุงู„ู…ูุตู„ ู„ุงุจู† ูŠุนูŠุด
ุงู„ู…ูˆุณูˆุนุฉ ุงู„ูู‚ู‡ูŠุฉ ุงู„ูƒูˆูŠุชูŠุฉ
ู…ูˆุณูˆุนุฉ ุงู„ุฅุฌู…ุงุน ููŠ ุงู„ูู‚ู‡ ุงู„ุฅุณู„ุงู…ูŠ
ู…ูˆุณูˆุนุฉ ูู‚ู‡ ุงู„ุนุจุงุฏุงุช
ูุชุงูˆู‰ ุงู„ุดุจูƒุฉ ุงู„ุฅุณู„ุงู…ูŠุฉ
ู…ุฌู…ูˆุน ูุชุงูˆู‰ ูˆุฑุณุงุฆู„ ุงู„ุนุซูŠู…ูŠู†
ุงู„ุณู†ู† ุงู„ูƒุจุฑู‰ ู„ู„ุจูŠู‡ู‚ูŠ ุช ุงู„ุชุฑูƒูŠ
ุงู„ู…ุญูŠุท ููŠ ุงู„ุงุญุงุฏูŠุซ ุงู„ู†ุจูˆูŠุฉ ูˆุงู„ุณู†ู† ูˆุงู„ุงุซุงุฑ
ุฌุงู…ุน ุงู„ุฑูˆูŠุงุช
ุญู„ูŠุฉ ุงู„ุฃูˆู„ูŠุงุก ูˆุทุจู‚ุงุช ุงู„ุฃุตููŠุงุก
ุตุญูŠุญ ุงู„ุจุฎุงุฑูŠ 
ุงู„ุฌุงู…ุน ู„ุดุนุจ ุงู„ุฅูŠู…ุงู† ู„ู„ุจูŠู‡ู‚ูŠ
ุงู„ู…ูˆุณูˆุนุฉ ุงู„ุนู‚ุฏูŠุฉ - ุงู„ุฏุฑุฑ ุงู„ุณู†ูŠุฉ
ุงู„ู…ู‡ุฐุจ ุงู„ู†ู‚ูŠ ุงู„ุฌุงู…ุน ู„ุชูุณูŠุฑ ุงุจู† ุฌุฑูŠุฑ ุงู„ุทุจุฑูŠ
ุงู„ู…ูˆุณูˆุนุฉ ุงู„ู‚ุฑุขู†ูŠุฉ
ุชูุณูŠุฑ ุงุจู† ูƒุซูŠุฑ _ 
ุชูุณูŠุฑ ุงู„ู‚ุฑุทุจูŠ
ุฑูˆุญ ุงู„ุจูŠุงู†

When selecting other books, please modify the code.
            do_sample=True,               
            repetition_penalty=1.08,
            no_repeat_ngram_size=4,

๐Ÿš€ Usage Example The code must be used because it is compatible with the training method.

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

# ============================================================
# ๐Ÿ”ง ุงู„ุฅุนุฏุงุฏุงุช
# ============================================================

MODEL_PATH = "sherif1313/3arabLM-4B-islamic-v2"  # ุบูŠู‘ุฑู‡ ุฅู„ู‰ ู…ุณุงุฑ ู†ู…ูˆุฐุฌูƒ
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
MAX_NEW_TOKENS = 384

# ============================================================
# ๐Ÿ“ฆ ุชุญู…ูŠู„ ุงู„ู†ู…ูˆุฐุฌ ูˆุงู„ู…ุญู„ู„ ุงู„ู„ุบูˆูŠ
# ============================================================

print("โณ ุชุญู…ูŠู„ ุงู„ู†ู…ูˆุฐุฌ...")
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, trust_remote_code=True)

if tokenizer.pad_token_id is None:
    tokenizer.pad_token = tokenizer.eos_token

model = AutoModelForCausalLM.from_pretrained(
    MODEL_PATH,
    dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True
)
model.eval()

# ============================================================
# ๐Ÿ“ ุฏุงู„ุฉ ุชู†ุณูŠู‚ ุงู„ู…ูŠุชุงุฏุงุชุง (ู…ุทุงุจู‚ุฉ ุชู…ุงู…ุงู‹ ู„ู„ุชุฏุฑูŠุจ)
# ============================================================

def format_prefix(book=None, author=None, category=None, part=None, page=None, hierarchy=None):
    """
    ุชูˆู„ูŠุฏ ุงู„ู…ูŠุชุงุฏุงุชุง ุจู†ูุณ ุชู†ุณูŠู‚ ุงู„ุชุฏุฑูŠุจ:
    - ุฌู…ูŠุน ุงู„ุญู‚ูˆู„ ููŠ ุณุทุฑ ูˆุงุญุฏุŒ ู…ูุตูˆู„ุฉ ุจู…ุณุงูุงุช
    - ุจุฏูˆู† ู†ู‚ุทุชูŠู† (:) ุจุนุฏ ุงุณู… ุงู„ุญู‚ู„
    - part> ูˆ page> ูˆ title> (ู…ุน >)
    - hierarchy ุชุคุฎุฐ ู…ู†ู‡ุง ุงู„ู‚ูŠู…ุฉ ุงู„ุฃุฎูŠุฑุฉ ูู‚ุท
    """
    tags = []

    if book:
        tags.append(f"book {book}")
    if author:
        tags.append(f"author {author}")
    if category:
        tags.append(f"category {category}")
    if part is not None and str(part).strip():
        tags.append(f"part> {part}")
    if page is not None and str(page).strip():
        tags.append(f"page> {page}")
    if hierarchy:
        parts = hierarchy.split('|')
        title = parts[-1] if parts else ''
        if title:
            tags.append(f"title> {title}")

    return " ".join(tags)

# ============================================================
# ๐Ÿค– ุฏุงู„ุฉ ุชูˆู„ูŠุฏ ุงู„ุฅุฌุงุจุฉ (ุงุณุชุฑุฌุงุน ุฃู…ูŠู†)
# ============================================================

def generate_text(prompt, book=None, author=None, category=None, part=None, page=None, hierarchy=None):
    # ุจู†ุงุก ุงู„ู€ prompt ุจุงู„ุดูƒู„: "metadata\nุงู„ู†ุต"
    prefix = format_prefix(book, author, category, part, page, hierarchy)
    full_prompt = f"{prefix}\n{prompt}" if prefix else prompt

    print(f"\n๐Ÿ“ ุงู„ุณุคุงู„/ุงู„ู†ุต: {prompt}")
    print("-" * 50)

    inputs = tokenizer(full_prompt, return_tensors="pt").to(DEVICE)

    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            do_sample=False,                # ุงุณุชุฑุฌุงุน ุญุชู…ูŠ (Greedy)
            repetition_penalty=1.02,
            no_repeat_ngram_size=2,
            #repetition_penalty=None
            #no_repeat_ngram_size=None

           
            max_new_tokens=MAX_NEW_TOKENS,
            eos_token_id=tokenizer.eos_token_id,
            pad_token_id=tokenizer.pad_token_id,
        )

    answer = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
    print(f"๐Ÿค– ุฅุฌุงุจุฉ ุงู„ู†ู…ูˆุฐุฌ:\n{answer}")
    print("=" * 80)

# ============================================================
# ๐Ÿ“š ุฃุณุฆู„ุฉ ุชุณุชู†ุฏ ุฅู„ู‰ ุงู„ูƒุชุจ ุงู„ู…ูˆุฌูˆุฏุฉ ูุนู„ุงู‹ ููŠ ./1/2
# ============================================================

TEST_CASES = [

    # ================================================
    # ุงู„ูู‚ู‡
    # ========================================================

    {
        "prompt": " ุญูƒู… ุงู„ู…ุณุญ ุนู„ู‰ ุงู„ุฎููŠู†ุŸ",
        "book": "ุงู„ู…ูˆุณูˆุนุฉ ุงู„ูู‚ู‡ูŠุฉ ุงู„ูƒูˆูŠุชูŠุฉ",
        "author": "ูˆุฒุงุฑุฉ ุงู„ุฃูˆู‚ุงู ูˆุงู„ุดุคูˆู† ุงู„ุฅุณู„ุงู…ูŠุฉ ุจุงู„ูƒูˆูŠุช",
        "category": "ูู‚ู‡ ุนุงู…"
    },


    
    {
        "prompt": " ู…ุจุทู„ุงุช ุงู„ูˆุถูˆุกุŸ",
        "book": "ู…ูˆุณูˆุนุฉ ูู‚ู‡ ุงู„ุนุจุงุฏุงุช",
        "author": "ุนู„ูŠ ุจู† ู†ุงูŠู ุงู„ุดุญูˆุฏ",
        "category": "ูู‚ู‡ ุนุงู…"
    },

    
    {
        "prompt": " ุญูƒู… ุงู„ุฌู…ุน ูˆุงู„ู‚ุตุฑ ููŠ ุงู„ุณูุฑุŸ",
        "book": "ูุชุงูˆู‰ ุงู„ุดุจูƒุฉ ุงู„ุฅุณู„ุงู…ูŠุฉ",
        "author": "ู„ุฌู†ุฉ ุงู„ูุชูˆู‰ ุจุงู„ุดุจูƒุฉ ุงู„ุฅุณู„ุงู…ูŠุฉ",
        "category": "ุงู„ูุชุงูˆู‰"
    },


    # ========================================================
    # ุงู„ุญุฏูŠุซ ูˆุงู„ุขุซุงุฑ
    # ========================================================

    {
        "prompt": " ุฃูˆู„ ุญุฏูŠุซ ููŠ ุตุญูŠุญ ุงู„ุจุฎุงุฑูŠุŸ",
        "book": "ุตุญูŠุญ ุงู„ุจุฎุงุฑูŠ - ุท ุงู„ุดุนุจ",
        "author": "ู…ุญู…ุฏ ุจู† ุฅุณู…ุงุนูŠู„ ุงู„ุจุฎุงุฑูŠ",
        "category": "ู…ุชูˆู† ุงู„ุญุฏูŠุซ"
    },

   
    {
        "prompt": " ุญุฏูŠุซ ุฌุจุฑูŠู„ ููŠ ุงู„ุฅุณู„ุงู… ูˆุงู„ุฅูŠู…ุงู† ูˆุงู„ุฅุญุณุงู†ุŸ",
        "book": "ุตุญูŠุญ ุงู„ุจุฎุงุฑูŠ - ุท ุงู„ุดุนุจ",
        "author": "ู…ุญู…ุฏ ุจู† ุฅุณู…ุงุนูŠู„ ุงู„ุจุฎุงุฑูŠ",
        "category": "ู…ุชูˆู† ุงู„ุญุฏูŠุซ"
    },

    {
        "prompt": " ูุถู„ ุทู„ุจ ุงู„ุนู„ู…ุŸ",
        "book": "ุงู„ุฌุงู…ุน ู„ุดุนุจ ุงู„ุฅูŠู…ุงู† ู„ู„ุจูŠู‡ู‚ูŠ",
        "author": "ุฃุญู…ุฏ ุจู† ุงู„ุญุณูŠู† ุงู„ุจูŠู‡ู‚ูŠ",
        "category": "ู…ุชูˆู† ุงู„ุญุฏูŠุซ"
    },

    {
        "prompt": " ูุถู„ ุงู„ุตุฏู‚ุŸ",
        "book": "ุงู„ุณู†ู† ุงู„ูƒุจุฑู‰ ู„ู„ุจูŠู‡ู‚ูŠ ุช ุงู„ุชุฑูƒูŠ",
        "author": "ุฃุญู…ุฏ ุจู† ุงู„ุญุณูŠู† ุงู„ุจูŠู‡ู‚ูŠ",
        "category": "ู…ุชูˆู† ุงู„ุญุฏูŠุซ"
    },

    {
        "prompt": " ูุถู„ ุฐูƒุฑ ุงู„ู„ู‡ ุชุนุงู„ู‰ุŸ",
        "book": "ุงู„ู…ุญูŠุท ููŠ ุงู„ุงุญุงุฏูŠุซ ุงู„ู†ุจูˆูŠุฉ ูˆุงู„ุณู†ู† ูˆุงู„ุงุซุงุฑ",
        "author": "ุบูŠุฑ ู…ุญุฏุฏ",
        "category": "ู…ุชูˆู† ุงู„ุญุฏูŠุซ"
    },

    {
        "prompt": " ูุถู„ ุงู„ุตู„ุงุฉ ุนู„ู‰ ุงู„ู†ุจูŠ ุตู„ู‰ ุงู„ู„ู‡ ุนู„ูŠู‡ ูˆุณู„ู…ุŸ",
        "book": "ุฌุงู…ุน ุงู„ุฑูˆูŠุงุช",
        "author": "ุบูŠุฑ ู…ุญุฏุฏ",
        "category": "ู…ุชูˆู† ุงู„ุญุฏูŠุซ"
    },

    {
        "prompt": " ู…ู†ุฒู„ุฉ ุงู„ุตุฏู‚ ููŠ ุณูŠุฑุฉ ุงู„ุตุงู„ุญูŠู†ุŸ",
        "book": "ุญู„ูŠุฉ ุงู„ุฃูˆู„ูŠุงุก ูˆุทุจู‚ุงุช ุงู„ุฃุตููŠุงุก",
        "author": "ุฃุจูˆ ู†ุนูŠู… ุงู„ุฃุตุจู‡ุงู†ูŠ",
        "category": "ู…ุชูˆู† ุงู„ุญุฏูŠุซ"
    },


    # ========================================================
    # ุงู„ุนู‚ูŠุฏุฉ
    # ========================================================

    
    
    {
        "prompt": " ู…ุนู†ู‰ ุงู„ุฅูŠู…ุงู† ุจุงู„ู„ู‡ุŸ",
        "book": "ุงู„ู…ูˆุณูˆุนุฉ ุงู„ุนู‚ุฏูŠุฉ - ุงู„ุฏุฑุฑ ุงู„ุณู†ูŠุฉ",
        "author": "ุงู„ู…ูˆุณูˆุนุฉ ุงู„ุนู‚ุฏูŠุฉ",
        "category": "ุงู„ุนู‚ูŠุฏุฉ"
    },


    # ========================================================
    # ุงู„ุชูุณูŠุฑ
    # ========================================================

    {
        "prompt": " ุชูุณูŠุฑ ุณูˆุฑุฉ ุงู„ูุงุชุญุฉุŸ",
        "book": "ุชูุณูŠุฑ ุงู„ู‚ุฑุทุจูŠ",
        "author": "ู…ุญู…ุฏ ุจู† ุฃุญู…ุฏ ุงู„ู‚ุฑุทุจูŠ",
        "category": "ุงู„ุชูุงุณูŠุฑ"
    },

    {
        "prompt": " ู…ุนู†ู‰ ู‚ูˆู„ู‡ ุชุนุงู„ู‰: ุงู„ุญู…ุฏ ู„ู„ู‡ ุฑุจ ุงู„ุนุงู„ู…ูŠู†ุŸ",
        "book": "ุชูุณูŠุฑ ุงู„ุฑุงุฒูŠ = ู…ูุงุชูŠุญ ุงู„ุบูŠุจ ุฃูˆ ุงู„ุชูุณูŠุฑ ุงู„ูƒุจูŠุฑ",
        "author": "ูุฎุฑ ุงู„ุฏูŠู† ุงู„ุฑุงุฒูŠ",
        "category": "ุงู„ุชูุงุณูŠุฑ"
    },

    {
        "prompt": " ุชูุณูŠุฑ ู‚ูˆู„ู‡ ุชุนุงู„ู‰: ู‚ู„ ู‡ูˆ ุงู„ู„ู‡ ุฃุญุฏุŸ",
        "book": "ุฑูˆุญ ุงู„ุจูŠุงู†",
        "author": "ุฅุณู…ุงุนูŠู„ ุญู‚ูŠ",
        "category": "ุงู„ุชูุงุณูŠุฑ"
    },
  
    {
        "prompt": " ุชูุณูŠุฑ ู‚ูˆู„ู‡ ุชุนุงู„ู‰: ู‚ู„ ู‡ูˆ ุงู„ู„ู‡ ุฃุญุฏุŸ",
        "book": "ุชูุณูŠุฑ ุงุจู† ูƒุซูŠุฑ",
        "author": "ุงุจู† ูƒุซูŠุฑ",
        "category": "ุงู„ุชูุงุณูŠุฑ"
    },
  
    {
        "prompt": " ู…ุนู†ู‰ ุงู„ุชู‚ูˆู‰ ููŠ ุงู„ู‚ุฑุขู† ุงู„ูƒุฑูŠู…ุŸ",
        "book": "ุงู„ู…ูˆุณูˆุนุฉ ุงู„ู‚ุฑุขู†ูŠุฉ",
        "author": "ุบูŠุฑ ู…ุญุฏุฏ",
        "category": "ุงู„ุชูุงุณูŠุฑ"
    },

]


# ============================================================
# ๐Ÿš€ ุชุดุบูŠู„ ุงู„ุงุฎุชุจุงุฑ
# ============================================================

print("\n๐Ÿš€ ุจุฏุก ุงุฎุชุจุงุฑ ุงู„ู†ู…ูˆุฐุฌ ุนู„ู‰ ุฃุณุฆู„ุฉ ู…ุชู†ูˆุนุฉ...\n")

for test in TEST_CASES:
    generate_text(
        prompt=test["prompt"],
        book=test.get("book"),
        author=test.get("author"),
        category=test.get("category"),
        part=test.get("part"),
        page=test.get("page"),
        hierarchy=test.get("hierarchy")
    )

print("\nโœ… ุงู†ุชู‡ู‰ ุงู„ุงุฎุชุจุงุฑ.")

โš ๏ธ Current Limitations

The current model has several limitations:

  • The training curriculum is still incomplete.
  • Some disciplines remain underrepresented.
  • Source attribution is still under development.
  • Generated claims should be verified against original sources.

๐Ÿ”ฌ Research Directions

The project explores several research questions:

Full-Parameter Memorization

How much classical scholarly knowledge can be encoded directly into model parameters?

Knowledge Reconstruction

Can a language model reconstruct scholarly passages without relying entirely on external retrieval?

Hierarchical Representation

Can ู„book, chapter, section, and paragraph structures improve scholarly representations?

Metadata-Aware Pretraining

Can author, book, century, madhhab, and discipline metadata improve knowledge organization?

Knowledge-Preserving Scaling

Can model capacity be increased without catastrophic forgetting?

Expert Models

Can specialized Islamic experts be efficiently developed from a shared foundation?


๐Ÿ“– Large Language Models as Compressed Digital Libraries

The central research hypothesis of 3arabLM is that language models may function not only as generators, but also as compressed representations of large scholarly corpora. The project therefore explores the possibility of building:

  • ๐Ÿ“– Knowledge Recall Models
  • ๐Ÿง  Memorization-Oriented Language Models
  • ๐Ÿ› Compressed Digital Libraries

The ultimate objective is to study how much classical Arabic scholarly knowledge can be represented and reconstructed from model parameters.


๐ŸŽฏ Project Goal

The ultimate objective of 3arabLM is:

To preserve, recall, and reconstruct the Arabic Islamic scholarly heritage with the highest possible degree of fidelity while maintaining the language, terminology, methodologies, and diversity of the original scholarly tradition.

The project is not intended to replace scholars.

It is a research effort exploring how modern language-model technology can contribute to:

  • Digital preservation.
  • Computational study of Islamic heritage.
  • Classical Arabic NLP.
  • Scholarly knowledge representation.
  • Knowledge memorization.
  • Text reconstruction.

๐Ÿ—“๏ธ Roadmap

Stage Description Status
Stage 1 Foundation โ€” Continual pretraining on selected Islamic scholarly domains โœ… Complete
Stage 2 Scholarly Expansion โ€” Expansion into Hadith, Sirah, History, Aqeedah, Arabic Language, Literature, and Spiritual Literature ๐Ÿ”„ In Progress
Stage 3 Metadata Integration โ€” Adding structured information about books, authors, periods, schools, and disciplines โณ Planned
Stage 4 Capacity Scaling โ€” Increasing model capacity while preserving previously learned knowledge โณ Planned
Stage 5 Expert Models โ€” Developing specialized experts for individual scholarly disciplines โณ Planned
Stage 6 Islamic Heritage Foundation โ€” Building a large-scale Arabic foundation model โณ Long-Term

๐Ÿค Research & Collaboration

The project welcomes researchers and contributors interested in:

  • Arabic NLP.
  • Islamic heritage digitization.
  • Classical Arabic.
  • Continual pretraining.
  • Knowledge memorization.
  • Scholarly text reconstruction.
  • Digital humanities.
  • Metadata-aware language modeling.
  • Islamic manuscript and library digitization.

๐Ÿ“œ Associated Research

The project is associated with the research work:

A Representation-Diagnostic Framework for Arabic Heritage Language Models: A Case Study on Continued Pretraining with the Shamela Corpus

The research investigates representation diagnostics and domain-specific adaptation of Arabic language models using classical Arabic heritage corpora.


๐Ÿ•Œ Final Statement

3arabLM explores a simple but ambitious question:

Can a language model become a compressed digital library of the Arabic Islamic scholarly heritage?

The project seeks to preserve not only:

  • what scholars wrote,

but also:

  • how they wrote,
  • how their methodologies differed,
  • and how Islamic scholarship developed across centuries.

The long-term vision is a continually expanding Arabic foundation model that represents major branches of Islamic and Arabic scholarly heritage while preserving their linguistic, methodological, and historical diversity.


๐Ÿ“ Citation

If you use this model in academic research, please cite the associated research work:

@article{3arabLM-4B-islamic-v2,
    title={3arabLM-4B-islamic-v2},
    author={Hassan, Sherif},
    year={2026},
    url={https://huggingface.co/sherif1313/3arabLM-4B-islamic-v2}
}
Downloads last month
15
Safetensors
Model size
4B params
Tensor type
BF16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for sherif1313/3arabLM-4B-islamic-v2

Finetuned
(1)
this model
Quantizations
2 models

Space using sherif1313/3arabLM-4B-islamic-v2 1

Collection including sherif1313/3arabLM-4B-islamic-v2