🏛️ AlimZeka-Gemma (Deep Reasoning)

AlimZeka is a "Deep Reasoning" model developed based on the Gemma-4-E2B architecture, focusing on Islamic sciences, jurisprudential reasoning, and ethical values. This project, carried out under the AlimZeka initiative, is designed as an assistant capable of answering complex religious, social, and moral questions through a logical chain of reasoning.

🚀 Key Features

  • Deep Reasoning: Before generating answers, the model runs an internal thinking process (<|think|>) to reach logical conclusions step by step.
  • Text-Focused Optimization: Instead of visual capabilities, the model focuses on text-based analysis, conceptual relationships, and moral reasoning capacity.
  • Ethical and Moral Alignment: It adopts a tone that prioritizes academic integrity, Islamic ethical principles, and general ethical standards.
  • Lightweight yet Powerful: Thanks to the E2B (Edge) architecture, it delivers high reasoning performance with low system resource usage (on mobile and desktop devices).

📊 Data Methodology (Data Engineering)

AlimZeka’s training infrastructure is based on modern data engineering techniques and transparency principles:

  • Synthetic Data Generation: The model’s reasoning ability has been enhanced with specially generated synthetic datasets created through a one-time API call mechanism consisting of 3000 high-fidelity samples.
  • Why Synthetic Data? This method is preferred to ensure full compliance with jurisprudential and academic standards, maintain strict control over data quality, and adhere to privacy principles (Privacy-by-Design).

💻 Usage

You can use the model via the transformers library as follows:

from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = "mahmut2142/alimzeka-gemma-reasoning" 
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")

# Example Usage Flow
import torch
from transformers import AutoModelForCausalLM, AutoProcessor, TextIteratorStreamer
import threading, os
os.environ["PYTORCH_ALLOC_CONF"] = "expandable_segments:True"

model_id = "................................."

SYSTEM_PROMPT = (
    "You are ALIMZEKA — an academic research assistant specialized in Islamic sciences "
    "and general knowledge. Your task is to provide accurate, source-based, and professional "
    "responses in accordance with the principles of the Quran, Sunnah, and Ijma. "
    "If a topic is unknown or disputed, you clearly state this; you do not produce "
    "unsupported, unsourced, or unverified Arabic text. At the end of every answer, "
    "you include a Confidence Score (High/Medium/Low) and conclude your statements "
    "with 'Allah knows best.' Before answering, you must always analyze complex issues "
    "step by step within a chain-of-thought (<thought>...</thought>). "
    "STRICT RULE: After completing the reasoning process, you MUST close the </thought> tag "
    "and then provide the user with a detailed final answer! It is FORBIDDEN to respond "
    "with only the reasoning process."
)

print("\n==================================")
print("   ALIMZEKA Terminal Chat Test")
print(f"   Model: {model_id}")
print("==================================\n")

print("⏳ Loading processor...")
processor = AutoProcessor.from_pretrained(model_id)
if processor.tokenizer.pad_token is None:
    processor.tokenizer.pad_token = processor.tokenizer.eos_token

print("⏳ Loading model (bfloat16 + 4-bit quantization)...")
from transformers import BitsAndBytesConfig
bnb = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_compute_dtype=torch.bfloat16,
    bnb_4bit_use_double_quant=True,
    bnb_4bit_quant_type="nf4",
)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    device_map="auto",
    quantization_config=bnb,
    torch_dtype=torch.bfloat16,
)
model.eval()

print("\n✅ System Ready. Type 'exit' or 'quit' to leave.\n")

while True:
    try:
        user_input = input("\nYou: ")
        if user_input.lower() in ['exit', 'quit', 'çıkış']:
            break
        if not user_input.strip():
            continue

        messages = [
            {"role": "system", "content": [{"type": "text", "text": SYSTEM_PROMPT}]},
            {"role": "user",   "content": [{"type": "text", "text": user_input}]},
        ]

        inputs = processor.apply_chat_template(
            messages,
            add_generation_prompt=True,
            tokenize=True,
            return_dict=True,
            return_tensors="pt",
        ).to(model.device)

        for k, v in inputs.items():
            if torch.is_floating_point(v):
                inputs[k] = v.to(model.dtype)

        streamer = TextIteratorStreamer(processor.tokenizer, skip_prompt=True, skip_special_tokens=True)
        t = threading.Thread(
            target=model.generate,
            kwargs=dict(**inputs, streamer=streamer, max_new_tokens=3000,
                        do_sample=True, temperature=0.6, top_p=0.9),
        )
        t.start()

        print("\nAlimZeka: ", end="", flush=True)
        for chunk in streamer:
            print(chunk, end="", flush=True)
        t.join()
        print()

    except KeyboardInterrupt:
        break

print("\nExited.")

⚖️ Legal Notice and Disclaimer
AlimZeka is a technology development and academic research project. The responses generated by the model are analytical and supportive in nature; they should **not** be considered as definitive religious rulings (fatwas), legal judgments, or formal advice. Final decisions should always rely on qualified authorities and official sources.

🛠️ Developer Information

Lead Developer:Mahmut ERDEM

Architecture: Google DeepMind Gemma 4

License: Apache License 2.0
Downloads last month
16
Safetensors
Model size
5B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for mahmut2142/alimzeka-gemma-reasoning

Finetuned
(205)
this model

Space using mahmut2142/alimzeka-gemma-reasoning 1