OpenNoorIlm commited on
Commit
723675b
Β·
verified Β·
1 Parent(s): 5afa310

Create README.md

Browse files

---
license: mit
language:
- en
- ar
- ur
base_model: Qwen/Qwen2.5-7B-Instruct
pipeline_tag: text-generation
tags:
- islamic
- quran
- hadith
- tafsir
- fiqh
- lora
- unsloth
- qwen2.5
- arabic
- urdu
- noor-al-ilm
- opennoorilm
datasets:
- OpenNoorIlm/Noor-Ul-Ilm-1.0-Qwen2.5-7B-training-dataset-15-03-2026
library_name: transformers
---

<div align="center">

# 🌟 Noor-Al-Ilm β€” Ω†ΩˆΨ± Ψ§Ω„ΨΉΩ„Ω…

### *Light of Knowledge β€” An Islamic AI for the Ummah*

**Fine-tuned by [OpenNoorIlm](https://huggingface.co/OpenNoorIlm)**

[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
[![Base Model](https://img.shields.io/badge/Base-Qwen2.5--7B--Instruct-blue)](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct)
[![Language](https://img.shields.io/badge/Language-English%20%7C%20Arabic%20%7C%20Urdu-orange)](/)
[![Dataset](https://img.shields.io/badge/Dataset-OpenNoorIlm-green)](https://huggingface.co/datasets/OpenNoorIlm/Noor-Ul-Ilm-1.0-Qwen2.5-7B-training-dataset-15-03-2026)

</div>

---

## πŸ“– About Noor-Al-Ilm

**Noor-Al-Ilm** (Ω†ΩˆΨ± Ψ§Ω„ΨΉΩ„Ω…, *Light of Knowledge*) is a fine-tuned Islamic AI assistant that provides accurate, citation-backed answers across the full spectrum of Islamic knowledge β€” Quran, Hadith, Tafsir, Fiqh, Islamic history, and general Islamic guidance.

Built on **Qwen2.5-7B-Instruct** and fine-tuned by **OpenNoorIlm** using curated classical Islamic texts, verified fatawa from traditional Sunni scholars, and custom instruction-tuning seeds. It features a unique **IDRAG** (Islamic Data RAG) pipeline that enriches every answer with locally retrieved Quran ayahs, hadiths, and fatawa before generation.

---

## πŸ›οΈ About OpenNoorIlm

**OpenNoorIlm** is an independent Islamic AI research initiative. Our mission is to make authentic Islamic knowledge accessible through intelligent, respectful, and well-attributed AI systems rooted in traditional Sunni scholarship β€” following the Ash'ari/Maturidi aqeedah and all four madhabs (Hanafi, Maliki, Shafi'i, Hanbali).

---

## 🧠 Model Details

| Detail | Value |
|--------|-------|
| **Model Name** | Noor-Al-Ilm |
| **Base Model** | [Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) |
| **Fine-tuned by** | OpenNoorIlm |
| **Fine-tuning Method** | LoRA via Unsloth (r=16, alpha=32) |
| **Training Versions** | v1 β†’ v2 (3 epochs, seq 512) β†’ v3 (5 epochs, seq 2048) |
| **Output Format** | GGUF (Ollama) + LoRA adapters |
| **Languages** | English (primary), Arabic terms, Urdu reference |
| **Max Sequence Length** | 2048 |

---

## πŸ“š Training Datasets

| Dataset | Description | Records | License |
|---------|-------------|---------|---------|
| Quran β€” Saheeh International (EN) | Complete Quran, English translation | ~6,236 ayahs | Public Domain |
| Kanzul Iman β€” Urdu | Imam Ahmad Raza Khan (d.1921) | ~6,236 ayahs | Public Domain |
| Tafsir al-Jalalayn | al-Mahalli & al-Suyuti (15th C.) | ~6,200 ayahs | Public Domain |
| Sahih al-Bukhari | Most authentic hadith collection | 7,277 hadiths | Public Domain |
| Sahih Muslim | Second most authentic collection | 7,459 hadiths | Public Domain |
| SeekersGuidance Fatawa | Sheikh Faraz Rabbani & scholars β€” all 4 madhabs | 260+ fatawa | Attributed |
| OpenNoorIlm Seeds | Custom instruction-tuning QA pairs | varies | MIT |

Full dataset: [OpenNoorIlm/Noor-Ul-Ilm-1.0-Qwen2.5-7B-training-dataset-15-03-2026](https://huggingface.co/datasets/OpenNoorIlm/Noor-Ul-Ilm-1.0-Qwen2.5-7B-training-dataset-15-03-2026)

---

## 🌟 Capabilities

Noor-Al-Ilm operates in a **Three-Brain System**:

| Mode | Tag | Scope |
|------|-----|-------|
| πŸ•Œ **Mufti Brain** | `[BRAIN:mufti]` | Halal/Haram, fiqh, worship, Islamic ethics |
| πŸ“š **Scholar Brain** | `[BRAIN:scholar]` | Islamic history, scholars, dynasties, books |
| 🌐 **Dunyawi Brain** | `[BRAIN:dunyawi]` | Science, math, coding, general knowledge |

---

## πŸš€ Inference

### Option 1 β€” Ollama (GGUF, simplest)

```bash
ollama run OpenNoorIlm/Noor-ul-ilm-7B-Qwen
```

---

### Option 2 β€” Unsloth (Fast, recommended for Colab / GPU)

```python
# !pip install -q unsloth

from unsloth import FastLanguageModel
import torch

model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "OpenNoorIlm/Noor-ul-ilm-7B-Qwen-15-3-2026",
max_seq_length = 2048,
dtype = None,
load_in_4bit = True,
)
FastLanguageModel.for_inference(model)

SYSTEM = """You are Noor-Al-Ilm, a deeply knowledgeable Islamic AI.
Answer every question with complete depth so the user has ZERO remaining questions.
Write in ENGLISH ONLY. Arabic Islamic terms are fine.
Start immediately with [ANS], [HALAL], [HARAM], or [FARD]. Never echo instructions."""

def ask(question, max_new_tokens=600):
messages = [
{"role": "system", "content": SYSTEM},
{"role": "user", "content": question},
]
inputs = tokenizer.apply_chat_template(
messages,
tokenize=True,
add_generation_prompt=True,
return_tensors="pt",
).to("cuda")

with torch.no_grad():
outputs = model.generate(
input_ids = inputs,
max_new_tokens = max_new_tokens,
temperature = 0.7,
top_p = 0.9,
repetition_penalty = 1.15,
do_sample = True,
pad_token_id = tokenizer.eos_token_id,
)
return tokenizer.decode(
outputs[0][inputs.shape[1]:], skip_special_tokens=True
).strip()

print(ask("Is cryptocurrency trading halal?"))
```

---

### Option 3 β€” Full IDRAG Pipeline (RAG + Web, as used in training)

> Complete production pipeline: FAISS vector retrieval over the full dataset + DuckDuckGo Sunni web search β†’ enriched context β†’ generation β†’ LML cleanup.

```python
# !pip install -q unsloth faiss-cpu sentence-transformers requests beautifulsoup4 lxml

from unsloth import FastLanguageModel
import torch, re, os, pickle
import faiss, requests
from bs4 import BeautifulSoup
from sentence_transformers import SentenceTransformer

# ── Load model ─────────────────────────────────────────────────────────────
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "OpenNoorIlm/Noor-ul-ilm-7B-Qwen-15-3-2026",
max_seq_length = 2048,
dtype = None,
load_in_4bit = True,
)
FastLanguageModel.for_inference(model)

# ── LML cleanup ────────────────────────────────────────────────────────────
_FALLBACK = '[ANS] Please try rephrasing your question. [/ANS]\n\n[BRAIN:mufti] [CONF:50] [LEVEL:basic]'
_RE_HASH3 = re.compile(r'###\s*\[')
_RE_HASH2 = re.compile(r'##\s*\[')
_RE_CJK = re.compile('[\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]+')
_RE_META2 = re.compile(r'\[BRAIN:\w+\]')
_RE_SPAM = re.compile(r'(.)\1{20,}')
_RE_CRANE = re.compile(r'\[CRANE:[^\]]*\].*?\[/CRANE\]', re.DOTALL)
_RE_INSTR = re.compile(
r'(═{6,}|LML TAGS\s*[—–-]|THREE BRAIN MODES|NEVER write ###'
r'|COMPLETE PROMPT START|COMPLETE PROMPT END)',
re.IGNORECASE
)

def clean_lml(text):
text = _RE_HASH3.sub('[', text)
text = _RE_HASH2.sub('[', text)
text = _RE_CRANE.sub('', text)
if _RE_SPAM.search(text):
return _FALLBACK
m = _RE_INSTR.search(text)
if m:
cut = text[:m.start()].rstrip()
text = cut if len(cut) > 80 else _FALLBACK
if not _RE_META2.search(text):
text += '\n\n[BRAIN:mufti] [CONF:70] [LEVEL:basic]'
text = _RE_CJK.sub('', text)
return text.strip()

# ── IDRAG: FAISS vector retrieval ──────────────────────────────────────────
RAG_INDEX = '/content/noor_rag' # path to your pre-built FAISS index
_idx, _chunks, _emb = None, None, None

def _load_faiss():
global _idx, _chunks, _emb
if _idx is not None: return
ip = f'{RAG_INDEX}/index.faiss'
cp = f'{RAG_INDEX}/chunks.pkl'
if not os.path.exists(ip): return
_idx = faiss.read_index(ip)
with open(cp, 'rb') as f: _chunks = pickle.load(f)
_emb = SentenceTransformer('all-MiniLM-L6-v2')
print(f'IDRAG: {_idx.ntotal} vectors loaded')

def _retrieve_local(q, top_k=8):
_load_faiss()
if _idx is None: return []
vec = _emb.encode([q], normalize_embeddings=True).astype('float32')
D, I = _idx.search(vec, top_k)
return [_chunks[i] for d, i in zip(D[0], I[0]) if i >= 0 and d >= 0.25]

# ── IDRAG: Sunni web search ────────────────────────────────────────────────
_SUNNI = ['seekersguidance.org','islamqa.info','daruliftaa.com',
'muftionline.co.za','islamweb.net','abuaminaelias.com']

def _web_search(q, n=3):
try:
sf = ' OR '.join(f'site:{s}' for s in _SUNNI)
url = f'https://html.duckduckgo.com/html/?q={requests.utils.quote(q+" ("+sf+")")}'
r = requests.get(url, headers={'User-Agent':'NoorAlIlm/1.0'}, timeout=8)
if r.status_code != 200: return []
soup = BeautifulSoup(r.text, 'html.parser')
out = []
for res in soup.select('.result')[:n]:
t = res.select_one('.result__title')
s = res.select_one('.result__snippet')
if t and s:
out.append({'title': t.get_text(strip=True),
'snippet': s.get_text(strip=True)})
return out
except Exception:
return []

def build_context(question):
parts = []
local = _retrieve_local(question)
if local:
parts.append('── Relevant Islamic Sources ──')
for c in local: parts.append(f"β€’ {c['text'][:400]}")
web = _web_search(question)
if web:
parts.append('\n── Sunni Scholar Guidance ──')
for w in web: parts.append(f"β€’ {w['title']}: {w['snippet'][:

Files changed (1) hide show
  1. README.md +19 -0
README.md ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ datasets:
4
+ - OpenNoorIlm/Noor-Ul-Ilm-1.0-Qwen2.5-7B-training-dataset-15-03-2026
5
+ language:
6
+ - en
7
+ - ar
8
+ base_model:
9
+ - Qwen/Qwen2.5-7B-Instruct
10
+ library_name: transformers
11
+ tags:
12
+ - islamic
13
+ - quran
14
+ - hadith
15
+ - fiqh
16
+ - lora
17
+ - unsloth
18
+ - qwen2.5
19
+ ---