Views
No views yet
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.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.CANNOT_ANSWER.transformerstransformers library:1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_id = "safora/PersianSciQA-LLaMA-13B"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 torch_dtype=torch.bfloat16,
10 device_map="auto"
11)
12
13def create_prompt(context, question):
14 return f"""<s>[INST] شما یک دستیار متخصص در زمینه اسناد علمی هستید. وظیفه شما این است که به سوال پرسیده شده، **فقط و فقط** بر اساس متن زمینه (Context) ارائه شده پاسخ دهید. پاسخ شما باید دقیق و خلاصه باشد.
15
16**دستورالعمل مهم:** اگر اطلاعات لازم برای پاسخ دادن به سوال در متن زمینه وجود ندارد، باید **دقیقا** عبارت "CANNOT_ANSWER" را به عنوان پاسخ بنویسید و هیچ توضیح اضافهای ندهید.
17
18**زمینه (Context):**
19---
20{context}
21---
22
23**سوال (Question):**
24{question} [/INST]
25"""
26
27# --- Example 1: Answer is in the context ---
28context1 = "سلولهای خورشیدی پروسکایتی (PSCs) به دلیل هزینه پایین و کارایی بالای تبدیل توان، توجه زیادی را به خود جلب کردهاند. کارایی آزمایشگاهی این سلولها به بیش از ۲۵ درصد رسیده است."
29question1 = "حداکثر کارایی سلولهای خورشیدی پروسکایتی در آزمایشگاه چقدر است؟"
30
31prompt1 = create_prompt(context1, question1)
32inputs1 = tokenizer(prompt1, return_tensors="pt").to(model.device)
33
34outputs1 = model.generate(**inputs1, max_new_tokens=100)
35answer1 = tokenizer.decode(outputs1[0], skip_special_tokens=True)
36
37print("--- Question 1 ---")
38print(answer1)
39
40
41# --- Example 2: Answer is NOT in the context ---
42context2 = "سیاره مریخ چهارمین سیاره از خورشید در منظومه شمسی است و به دلیل رنگ قرمزش به آن سیاره سرخ نیز میگویند. این سیاره دارای دو قمر به نامهای فوبوس و دیموس است."
43question2 = "اتمسفر مریخ از چه گازهایی تشکیل شده است؟"
44
45prompt2 = create_prompt(context2, question2)
46inputs2 = tokenizer(prompt2, return_tensors="pt").to(model.device)
47
48outputs2 = model.generate(**inputs2, max_new_tokens=10)
49answer2 = tokenizer.decode(outputs2[0], skip_special_tokens=True)
50
51print("\n--- Question 2 ---")
52print(answer2)
53
54Fine-tuning Details (Version 2)
55This model was fine-tuned using Parameter-Efficient Fine-Tuning (PEFT), specifically the LoRA method.
56
57Base Model: ViraIntelligentDataMining/PersianLLaMA-13B
58
59Dataset: safora/PersianSciQA-Extractive
60
61Framework: TRL's SFTTrainer
62
63Hyperparameters
64Learning Rate: 5e-6
65
66LR Scheduler: Cosine
67
68Epochs: 3
69
70Batch Size: 1
71
72Gradient Accumulation: 8 steps (effective batch size of 8)
73
74Precision: bfloat16
75
76LoRA Configuration
77r: 16
78
79lora_alpha: 32
80
81lora_dropout: 0.05
82
83Target Modules: q_proj, v_proj, k_proj, o_proj, gate_proj, up_proj, down_proj
84
85Limitations and Bias
86This 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.
87
88Citation
89If you use this model in your work, please consider citing it:
90@misc{safora_persiansciqa_llama_2025,
91 author = {jolfaei, safora},
92 title = {PersianSciQA-LLaMA-13B: A Fine-tuned Model for Extractive Question Answering in Persian Scientific Texts},
93 year = {2025},
94 publisher = {Hugging Face},
95 journal = {Hugging Face repository},
96 howpublished = {\url{[https://huggingface.co/safora/PersianSciQA-LLaMA-13B](https://huggingface.co/safora/PersianSciQA-LLaMA-13B)}}
97}