๊ฐ์
- ๊ณผ์ ๋ช : [2025]ํ๊ตญ์ด ์ด๋ฌธ ๊ท๋ฒ ๊ธฐ๋ฐ ์์ฑ(RAG) ๋งํ(๊ฐ ์ ํ)
- ํ๋ช : filot
ํ์ต ๋ฐ์ดํฐ
- korean_language_rag_V1.0_train.json
- korean_language_rag_V1.0_dev.json
- ๊ตญ์ด ์ง์ ๊ธฐ๋ฐ ์์ฑ(RAG) ์ฐธ์กฐ ๋ฌธ์.txt(pdf -> txt)
์คํ๋ฐฉ๋ฒ
- vllm ์ค์น
- ์ค์น ํ ์๋ ๋ช ๋ น์ด๋ก ๋ชจ๋ธ ์๋น
vllm serve filot/kanana-1.5-8b-instruct-2505-rag \
--port 8000 \
--enable-prefix-caching \
--enable-chunked-prefill \
--gpu-memory-utilization 0.95 \
--seed 42 \
--max-model-len 32K
- ์๋ ์ฝ๋๋ฅผ ์ํ
import json
import requests
from tqdm import tqdm
test_file = "../dataset/korean_language_rag_V1.0_test.json"
headers = {"Content-type": "application/json"}
SYSTEM_PROMPT = """---์ญํ ---
๋น์ ์ ๋์ด์ฐ๊ธฐ, ๋ฌธ์ฅ๋ถํธ, ์ธ๋์ด ํ๊ธฐ๋ฒ, ํ๊ธ ๋ง์ถค๋ฒ, ํ์ค์ด ๊ท์ ์ ๋ฌธ๊ฐ์
๋๋ค.
---๋ชฉํ---
์ง์ ๊ธฐ๋ฐ(Knowledge Base)์ ๊ธฐ๋ฐ์ผ๋ก ๊ฐ๊ฒฐํ ์๋ต์ ์์ฑํ๋, ํ์ฌ ์ฌ์ฉ์์ ์ง๋ฌธ์ ๊ณ ๋ คํ์ฌ ์๋ตํ์ธ์.
---์ง์ ๊ทธ๋ํ ๋ฐ ๋ฌธ์ ์กฐ๊ฐ(Knowledge Graph and Document Chunks)---
{context_data}
---์๋ต ๊ท์น---
- ํ์ค๋ก๋ง ๋ต๋ณ์ ํ์ธ์.
- ์ฌ์ฉ์ ์ง๋ฌธ์ ์ธ์ด์ ๋ง์ถฐ์ ์๋ตํ์ธ์.
- ์ ๋ต์ ๋ชจ๋ฅผ ๊ฒฝ์ฐ์๋ ๋ชจ๋ฅธ๋ค๊ณ ํ์ธ์.
- ์ง์ ๊ทธ๋ํ ๋ฐ ๋ฌธ์ ์กฐ๊ฐ(Knowledge Graph and Document Chunks)๋ง์ ์ฐธ์กฐํ์ฌ ๋ต๋ณํ์ธ์.
- ๋น์ ์ด ์๊ณ ์๋ ํ๊ตญ์ด ๋์ด์ฐ๊ธฐ, ๋ฌธ์ฅ๋ถํธ, ์ธ๋์ด ํ๊ธฐ๋ฒ, ํ๊ธ ๋ง์ถค๋ฒ, ํ์ค์ด ๊ท์ ๋ง ํ์ฉํ์ธ์.
{user_prompt}
Response:"""
def make_addtional_user_format(input):
# question type๋ณ instruction ์ ์
type_instructions = {
"๊ต์ ํ": (
"- [์ง๋ฌธ]์ ์ ์ฝ๊ณ ๋ต๋ณ์ ์์ฑํ์์ค.\n"
"[์ง์นจ]\n"
"1. ๋ฌธ์ ๋ฅผ ๊ทธ๋๋ก ์ถ๋ ฅํ์ง ๋ง์์ค.\n"
"2. ์ง๋ฌธ์ ๋ฌธ์ฅ ๋ถํธ๊ฐ ๊ดํธ( )์ธ ๊ฒฝ์ฐ, ์๋ง์ ๋ฌธ์ฅ ๋ถํธ๋ฅผ ์์ฑํ์ธ์.\n"
'3. ์ฃผ์ด์ง ๋ฌธ์ฅ์ด ์ฌ๋ฐ๋ฅธ์ง ํ๋จํ๊ณ , ํ๋ฆฐ ๊ฒฝ์ฐ ์ฌ๋ฐ๋ฅด๊ฒ ๊ต์ ํ์ฌ "~๊ฐ ์ณ๋ค." ํํ๋ก ๋ต๋ณํ๊ณ , ๊ทธ ์ด์ ๋ฅผ 300์ ์ด๋ด๋ก ์ค๋ช
ํ์์ค.\n\n'
"[์์#1]\n"
'์ง๋ฌธ: ๋ค์ ๋ฌธ์ฅ์์ ์ด๋ฌธ ๊ท๋ฒ์ ๋ถํฉํ์ง ์๋ ๋ถ๋ถ์ ์ฐพ์ ๊ณ ์น๊ณ , ๊ทธ ์ด์ ๋ฅผ ์ค๋ช
ํ์ธ์.\n"์ค๋์ ํผ์ฆ ๋ง์ถ๊ธฐ๋ฅผ ํด ๋ณผ ๊ฑฐ์์."\n'
"๋ต๋ณ: \"์ค๋์ ํผ์ฆ ๋ง์ถ๊ธฐ๋ฅผ ํด ๋ณผ ๊ฑฐ์์.\"๊ฐ ์ณ๋ค. '์ ์๋ฆฌ์ ๋ง๊ฒ ๋ถ์ด๋ค, ์ฃผ๋ฌธํ๋ค, ๋๋ฐ๋ฅด๊ฒ ํ๋ค, ๋น๊ตํ๋ค' ๋ฑ์ ๋ป์ด ์๋ ๋ง์ '๋ง์ถ๋ค'๊ฐ ์๋ '๋ง์ถ๋ค'๋ก ์ ๋๋ค.\n\n"
"[์์#2]\n"
'์ง๋ฌธ: ๋ค์ ๋ฌธ์ฅ์์ ์ด๋ฌธ ๊ท๋ฒ์ ๋ถํฉํ์ง ์๋ ๋ถ๋ถ์ ์ฐพ์ ๊ณ ์น๊ณ , ๊ทธ ์ด์ ๋ฅผ ์ค๋ช
ํ์ธ์."๋ง์ง๋ง ํ์์์ธ ์
์นด์ค ์ญ์ ๋ค๋ฅธ ์์ฃผ๋ฏผ ๋ถ์กฑ์ธ ๋ง๊ตฌ์์๊ฒ ์ฃฝ์์ ๋นํ ๋ชจ์ต์ด์์."\n'
"๋ต๋ณ: \"๋ง์ง๋ง ํ์์์ธ ์
์นด์ค ์ญ์ ๋ค๋ฅธ ์์ฃผ๋ฏผ ๋ถ์กฑ์ธ ๋ง๊ตฌ์์๊ฒ ์ฃฝ์์ ๋นํ ๋ชจ์ต์ด์์.\"๊ฐ ์ณ๋ค. '-์์'๋ '์ด๋ค'๋ '์๋๋ค'์ ์ด๊ฐ ๋ค์ ๋ถ๋ ์ด๋ฏธ๋ก, '์ด๋ค'์ '-์์'๊ฐ ๊ฒฐํฉํ๋ฉด '์ด์์'๊ฐ ๋๋ค. '์ด์์'๋ ์๋ง์ ๋ฐ์นจ์ด ์์ ๋ '์์'๋ก ์ค์ฌ ์ด๋ค. ๋ฐ๋ผ์ '๋ชจ์ต'์ '์ด์์'๊ฐ ๋ถ๋ ๊ฒฝ์ฐ '๋ชจ์ต์ด์์'๋ผ๊ณ ์จ์ผ ํ๋ค."
),
"์ ํํ": (
"- [์ง๋ฌธ]์ ์ ์ฝ๊ณ ๋ต๋ณ์ ์์ฑํ์์ค\n"
"[์ง์นจ]\n"
"1. ๋ฌธ์ ๋ฅผ ๊ทธ๋๋ก ์ถ๋ ฅํ์ง ๋ง์์ค.\n"
"2. ์ค๊ดํธ(""{}"")์ธ ๊ฒฝ์ฐ, ์ด๋ฌธ๊ท๋ฒ(๋ง์ถค๋ฒ, ํ์ค์ด ๊ท์ , ๋์ด์ฐ๊ธฐ, ๋ฌธ์ฅ ๋ถํธ, ์ธ๋์ด ํ๊ธฐ๋ฒ)์ ๊ธฐ๋ฐํ์ฌ ์ ํํ์ธ์.\n"
'3. ์ฃผ์ด์ง ๋ณด๊ธฐ๋ค ์ค์์ ๊ฐ์ฅ ์ ์ ํ ๊ฒ์ ์ ํํ์ฌ "~๊ฐ ์ณ๋ค." ํํ๋ก ๋ต๋ณํ๊ณ , ๊ทธ ์ด์ ๋ฅผ 300์ ์ด๋ด๋ก ์ค๋ช
ํ์์ค.\n\n'
"[์์#1]\n"
'์ง๋ฌธ: "๋๋ ๊ทธ๋ฅผ ๋ณธ ์ ์ด ์์์ {๊ธฐ์ตํด๋๋ค/๊ธฐ์ตํด ๋๋ค}." ๊ฐ์ด๋ฐ ์ฌ๋ฐ๋ฅธ ๊ฒ์ ์ ํํ๊ณ , ๊ทธ ์ด์ ๋ฅผ ์ค๋ช
ํ์ธ์.\n'
"๋ต๋ณ: \"๋๋ ๊ทธ๋ฅผ ๋ณธ ์ ์ด ์์์ ๊ธฐ์ตํด ๋๋ค.\"๊ฐ ์ณ๋ค. '๊ธฐ์ตํด ๋๋ค'๋ '๊ธฐ์ตํ-+-์+๋๋ค'์ ๊ตฌ์ฑ์ด๋ค. ์ด์ฒ๋ผ '๋ณธ์ฉ์ธ+-์/-์ด+๋ณด์กฐ ์ฉ์ธ' ๊ตฌ์ฑ์ธ ๊ฒฝ์ฐ ๋ณธ์ฉ์ธ๊ณผ ๋ณด์กฐ ์ฉ์ธ์ ๋ถ์ฌ ์ฐ๋ ๊ฒ์ด ํ์ฉ๋์ง๋ง, ์ด๋ฌํ ๊ตฌ์ฑ์ ๊ฐ๋๋ผ๋ ์๋ง์ด 3์์ ์ด์์ ํฉ์ฑ์ด๋ ํ์์ด๋ผ๋ฉด ๋ณด์กฐ ์ฉ์ธ์ ๋ถ์ฌ ์ฐ๋ ๊ฒ์ด ํ์ฉ๋์ง ์๋๋ค. '๊ธฐ์ตํ๋ค'๋ '๊ธฐ์ต'๊ณผ '-ํ๋ค'๊ฐ ๊ฒฐํฉํ ํ์์ด์ด๋ฉฐ '๊ธฐ์ตํด'๋ 3์์ ์ด๋ค. ๋ฐ๋ผ์ '๊ธฐ์ตํด'์ '๋๋ค'๋ ๋์ด ์จ์ผ ํ๋ค.\n\n"
"[์์#2]\n"
'์ง๋ฌธ: "{๋คํ/๋ ํ} " ๊ฐ์ด๋ฐ ์ฌ๋ฐ๋ฅธ ๊ฒ์ ์ ํํ๊ณ , ๊ทธ ์ด์ ๋ฅผ ์ค๋ช
ํ์ธ์."\n'
"๋ต๋ณ: \"๋คํ\"์ด ์ณ๋ค. ๋คํ(dumping)์ ์์ด ๋ฐ์์ [หdสmpษชล]์ผ๋ก [ส]๋ '์ด'๋ก ํ๊ธฐํ๋ค. ๋ฐ๋ผ์ '๋คํ'์ด ์ณ๋ค."
),
}
# question type์ ๋ฐ๋ฅธ instruction ์ ํ
instruction = type_instructions.get(input["question_type"], "")
return instruction
with open(test_file, "r") as reader, requests.Session() as session:
test_data = json.load(reader)
for idx, data in tqdm(enumerate(test_data), total=len(test_data)):
query = data["input"]["question"].strip()
system_prompt = SYSTEM_PROMPT.format(
context_data="RAG๋ก ๊ฒ์๋ chunks",
user_prompt=make_addtional_user_format(data["input"]),
)
data = {
"messages": [
{"role": "system", "content": system_prompt},
{"role": "user", "content": query},
],
"model": "filot/kanana-1.5-8b-instruct-2505-rag",
"presence_penalty": 0.2,
"frequency_penalty": 0.2,
"repetition_penalty": 1.0,
"temperature": 0.0,
"top_p": 1.0,
"seed": 42,
}
response = session.post(
"http://localhost:8000/v1/chat/completions",
headers=headers,
data=json.dumps(data),
)
answer = response.json()["choices"][0]["message"]["content"].strip()
test_data[idx]["output"] = {"answer": answer}
for idx, data in tqdm(enumerate(test_data), total=len(test_data)):
test_data[idx]["output"]["answer"] = data["output"]["answer"].strip()
- Downloads last month
- 6
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
๐
Ask for provider support