PersianSciQA-LLaMA-13B
📣 Version 2 - August 2025 Update
This model card describes Version 2 of PersianSciQA-LLaMA-13B, which has been fine-tuned with a new, more robust instructional prompt. The primary goal of this update is to improve faithfulness by training the model to answer questions strictly from the provided context and to explicitly state when an answer cannot be found.
Model Description
This is a fine-tuned version of ViraIntelligentDataMining/PersianLLaMA-13B specialized for extractive question-answering on Persian scientific texts. It is designed to read a given context and a question, then provide a concise answer based only on the information present in the context.
If the context does not contain the information required to answer the question, the model is trained to output the exact string: CANNOT_ANSWER.
How to Use (Version 2)
To get the best results, you must use the specific instructional prompt format that the model was trained on.
Prompt Template
[INST] شما یک دستیار متخصص در زمینه اسناد علمی هستید. وظیفه شما این است که به سوال پرسیده شده، فقط و فقط بر اساس متن زمینه (Context) ارائه شده پاسخ دهید. پاسخ شما باید دقیق و خلاصه باشد.
دستورالعمل مهم: اگر اطلاعات لازم برای پاسخ دادن به سوال در متن زمینه وجود ندارد، باید دقیقا عبارت "CANNOT_ANSWER" را به عنوان پاسخ بنویسید و هیچ توضیح اضافهای ندهید.
زمینه (Context): {YOUR_CONTEXT_HERE} سوال (Question): {YOUR_QUESTION_HERE} [/INST]
Example Usage with transformers
Here is how to use the model with the transformers library:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "safora/PersianSciQA-LLaMA-13B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto"
)
def create_prompt(context, question):
return f"""<s>[INST] شما یک دستیار متخصص در زمینه اسناد علمی هستید. وظیفه شما این است که به سوال پرسیده شده، **فقط و فقط** بر اساس متن زمینه (Context) ارائه شده پاسخ دهید. پاسخ شما باید دقیق و خلاصه باشد.
**دستورالعمل مهم:** اگر اطلاعات لازم برای پاسخ دادن به سوال در متن زمینه وجود ندارد، باید **دقیقا** عبارت "CANNOT_ANSWER" را به عنوان پاسخ بنویسید و هیچ توضیح اضافهای ندهید.
**زمینه (Context):**
---
{context}
---
**سوال (Question):**
{question} [/INST]
"""
# --- Example 1: Answer is in the context ---
context1 = "سلولهای خورشیدی پروسکایتی (PSCs) به دلیل هزینه پایین و کارایی بالای تبدیل توان، توجه زیادی را به خود جلب کردهاند. کارایی آزمایشگاهی این سلولها به بیش از ۲۵ درصد رسیده است."
question1 = "حداکثر کارایی سلولهای خورشیدی پروسکایتی در آزمایشگاه چقدر است؟"
prompt1 = create_prompt(context1, question1)
inputs1 = tokenizer(prompt1, return_tensors="pt").to(model.device)
outputs1 = model.generate(**inputs1, max_new_tokens=100)
answer1 = tokenizer.decode(outputs1[0], skip_special_tokens=True)
print("--- Question 1 ---")
print(answer1)
# --- Example 2: Answer is NOT in the context ---
context2 = "سیاره مریخ چهارمین سیاره از خورشید در منظومه شمسی است و به دلیل رنگ قرمزش به آن سیاره سرخ نیز میگویند. این سیاره دارای دو قمر به نامهای فوبوس و دیموس است."
question2 = "اتمسفر مریخ از چه گازهایی تشکیل شده است؟"
prompt2 = create_prompt(context2, question2)
inputs2 = tokenizer(prompt2, return_tensors="pt").to(model.device)
outputs2 = model.generate(**inputs2, max_new_tokens=10)
answer2 = tokenizer.decode(outputs2[0], skip_special_tokens=True)
print("\n--- Question 2 ---")
print(answer2)
Fine-tuning Details (Version 2)
This model was fine-tuned using Parameter-Efficient Fine-Tuning (PEFT), specifically the LoRA method.
Base Model: ViraIntelligentDataMining/PersianLLaMA-13B
Dataset: safora/PersianSciQA-Extractive
Framework: TRL's SFTTrainer
Hyperparameters
Learning Rate: 5e-6
LR Scheduler: Cosine
Epochs: 3
Batch Size: 1
Gradient Accumulation: 8 steps (effective batch size of 8)
Precision: bfloat16
LoRA Configuration
r: 16
lora_alpha: 32
lora_dropout: 0.05
Target Modules: q_proj, v_proj, k_proj, o_proj, gate_proj, up_proj, down_proj
Limitations and Bias
This model is a fine-tuned version of a larger language model and inherits its capabilities and limitations. It is specifically trained on scientific texts and may not perform well on other domains. While trained to be factual, it can still make mistakes or generate plausible-sounding but incorrect information. The training data may contain biases which can be reflected in the model's outputs.
Citation
If you use this model in your work, please consider citing it:
@misc{safora_persiansciqa_llama_2025,
author = {jolfaei, safora},
title = {PersianSciQA-LLaMA-13B: A Fine-tuned Model for Extractive Question Answering in Persian Scientific Texts},
year = {2025},
publisher = {Hugging Face},
journal = {Hugging Face repository},
howpublished = {\url{[https://huggingface.co/safora/PersianSciQA-LLaMA-13B](https://huggingface.co/safora/PersianSciQA-LLaMA-13B)}}
}
- Downloads last month
- -