SPARK2 / README.md
KISTEP's picture
Add files using upload-large-folder tool
d80f4d0 verified
|
Raw History Blame Contribute Delete
4.9 kB
---
language:
- ko
base_model:
- google/gemma-3-27b-it
- google/gemma-3-27b-pt
pipeline_tag: text-generation
---
## Usage Guide
๊ฐœ์ธ์€ ์ž์œ ๋กญ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๊ธฐ์—… ๋ฐ ๊ธฐ๊ด€์€ ๋น„์ƒ์—…์  ๋ชฉ์ ์œผ๋กœ ์ด์šฉํ•ด ์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
๋˜ํ•œ, ์ถ”ํ›„ ํ˜‘์—… ๋ฐ ๋„คํŠธ์›Œํฌ ๊ตฌ์ถ•์„ ์œ„ํ•ด ๊ธฐ๊ด€ ์ •๋ณด์™€ AI ๋ชจ๋ธ ์‚ฌ์šฉ ๋‹ด๋‹น์ž ์ •๋ณด๋ฅผ ๋ฉ”์ผ๋กœ ๋ณด๋‚ด์ฃผ์‹œ๋ฉด ์—ฐ๋ฝ๋“œ๋ฆฌ๊ฒ ์Šต๋‹ˆ๋‹ค.
## CONTACT : kistep_ax@kistep.re.kr
Individuals are free to use this without restrictions.
For companies and institutions, please use it for non-commercial purposes.
Additionally, to facilitate future collaboration and network building, please send us an email with your institution's information and the contact details of the person responsible for using the AI model. We will get in touch with you.
### 1. Description
**SPARK2** is a large language model developed by the Korea Institute of S&T Evaluation and Planning (KISTEP). As the successor to SPARK-RAG and SPARK-Report, SPARK2 unifies KISTEP's task-specific models into a single model. It is optimized for RAG (Retrieval-Augmented Generation) tasks and incorporates Chain of Thought (CoT) reasoning to enhance its response accuracy and performance.
### 2. Key Features
- **Enhanced Reliability through RAG:** Provides highly reliable responses by leveraging the organization's internal databases through Retrieval-Augmented Generation (RAG).
- **Transparent Reasoning:** Trained to demonstrate its reasoning process through Chain of Thought (CoT) inside `<think>` tags, clearly showing the information sources and logic behind each response with `<source>` citations.
- **Structured Output:** Responses in well-formatted markdown, including tables, text, and summaries for improved readability and clarity.
- **Base Model:** Built on Gemma-3-27b as the foundation model. Supervised Fine-Tuning (SFT) was performed on `google/gemma-3-27b-pt`, and the fine-tuned model was merged with `google/gemma-3-27b-it` using TIES (mergekit).
- **Training Method:** Trained with Supervised Fine-Tuning (SFT), using LoRA (rsLoRA, r=64) with FSDP2 and Context Parallelism.
- **Context Length:** The maximum context length for training data is 12,288.
### 3. Data
| source | KISTEP Documents<br>(synthetic QA) | KISTEP Documents<br>(evolved QA) |
| ------ | ---------------------------------- | -------------------------------- |
| count | 7,534 | 2,547 |
- The training data generated from KISTEP documents consists of `(Q, CONTEXT, A)` format, with Chain of Thought (CoT) reasoning included in the answers.
- Evolved QA augments the base synthetic QA with multi-hop, keyword, unanswerable, and multi-turn variations.
- Train / validation split: 9,080 / 1,001.
### 4. Usage
- Please combine files into a single file using the command below before use. (When using ollama, you can utilize the GGUF file.)
```
cat SPARK2-bf16_part1.gguf SPARK2-bf16_part2.gguf > SPARK2-bf16.gguf
```
- Python code
```python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "kistepAI/SPARK2"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
model.eval()
messages = [
{"role": "user", "content": "์•ˆ๋…•ํ•˜์„ธ์š”."}
]
input_ids = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_tensors="pt"
).to(model.device)
terminators = [
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<end_of_turn>")
]
outputs = model.generate(
input_ids,
max_new_tokens=2048,
eos_token_id=terminators,
do_sample=True,
temperature=0.3,
top_p=0.95,
)
response = outputs[0][input_ids.shape[-1]:]
print(tokenizer.decode(response, skip_special_tokens=True))
```
### 5. Prompt Template (RAG)
SPARK2 is trained with the following RAG prompt format. Place the user question in `<question>`, retrieved chunks in `<context>`, and previous conversation in `<history>`.
```
๋‹น์‹ ์€ RAG ์ „๋ฌธ๊ฐ€์ž…๋‹ˆ๋‹ค. <question>์—๋Š” ์‚ฌ์šฉ์ž ์งˆ๋ฌธ, <context>์—๋Š” ์‚ฌ์šฉ์ž ์งˆ๋ฌธ์œผ๋กœ ๊ฒ€์ƒ‰ํ•œ ๊ฒฐ๊ณผ, <history>์—๋Š” ๊ณผ๊ฑฐ ๋Œ€ํ™” ๋‚ด์—ญ์ด ์žˆ์Šต๋‹ˆ๋‹ค. <context>๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ์งˆ๋ฌธ์— ๋‹ต๋ณ€ํ•˜์„ธ์š”.
<question>
{question}
</question>
<context>
{context}
</context>
<history>
{history}
</history>
**๋‹ต๋ณ€ ํ˜•์‹:**
1. <think> ํƒœ๊ทธ์— ์ถ”๋ก  ๊ณผ์ • ์ž‘์„ฑ (1 depth ๊ฐœ์กฐ์‹, 10์ค„ ์ดํ•˜)
- ์งˆ๋ฌธ ๋ถ„์„ โ†’ ์ถœ์ฒ˜ ๋ถ„์„ (๋ฌธ์„œ๋ช…, ๋‚ ์งœ, ํŽ˜์ด์ง€, ์ตœ์‹ ์„ฑ, ์ผ์น˜์„ฑ) โ†’ ์ •๋ณด ์ข…ํ•ฉ โ†’ ๊ตฌ์กฐํ™” ์ˆœ์„œ
2. ๋ณธ๋ฌธ ๋‹ต๋ณ€ ์ž‘์„ฑ
- ๊ฐœ์กฐ์‹ ๋˜๋Š” ํ‘œ ํ˜•์‹์œผ๋กœ ๊ตฌ์กฐํ™”
- ์ตœ์‹  ์ •๋ณด ์šฐ์„ , ์‹œ๊ฐ„์ˆœ ๋น„๊ต ์ œ์‹œ
- ๊ฐ ์ •๋ณด ๋’ค์— <source>[์ถœ์ฒ˜ + ์ธ๋ฑ์Šค]</source> ํ‘œ๊ธฐ
์ด์ œ ๋‹ต๋ณ€์„ ์ž‘์„ฑํ•˜์„ธ์š”.
```