1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_id = "Kandil7/Baligh-1.5B"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 torch_dtype=torch.float16,
10 device_map="auto"
11)
12
13messages = [
14 {"role": "system", "content": "أنت بليغ، مساعد ذكاء اصطناعي عربي متخصص في المعرفة الإسلامية. أجب بدقة واستند إلى المصادر."},
15 {"role": "user", "content": "ما هي أركان الإسلام الخمسة؟"}
16]
17
18text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
19inputs = tokenizer(text, return_tensors="pt").to(model.device)
20
21with torch.no_grad():
22 outputs = model.generate(
23 **inputs,
24 max_new_tokens=512,
25 temperature=0.7,
26 top_p=0.9,
27 repetition_penalty=1.1,
28 do_sample=True,
29 )
30
31response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
32print(response)
1# Athar + Baligh pipeline
2from athar import HybridRetriever
3from transformers import pipeline
4
5# 1. Retrieve relevant passages
6retriever = HybridRetriever(qdrant_url="...", collection="athar-shamela4")
7passages = retriever.search(query="أركان الإسلام", top_k=5)
8
9# 2. Build grounded prompt
10context = "\n\n".join([p["text"] for p in passages])
11prompt = f"""استناداً إلى المصادر التالية:
12{context}
13
14السؤال: أركان الإسلام الخمسة؟
15الجواب:"""
16
17# 3. Generate grounded response with Baligh
18pipe = pipeline("text-generation", model="Kandil7/Baligh-1.5B", device_map="auto")
19response = pipe(prompt, max_new_tokens=300, temperature=0.3)
1@misc{kandil2025baligh,
2 author = {Mohamed Kandil},
3 title = {Baligh-1.5B: A Knowledge-Grounded Arabic LLM for Islamic Domain QA},
4 year = {2025},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/Kandil7/Baligh-1.5B}
7}
Mohamed Kandil — AI / NLP Engineer | Arabic LLMs, RAG, and Applied AI
📍 Kafr El-Sheikh, Egypt
🔗
GitHub ·
HuggingFace ·
LinkedIn