Views
No views yet
| 모델 (Model) | 학습 상태 | 전체 정확도 | Lv 1 (쉬움) | Lv 5 (매우 어려움) |
|---|---|---|---|---|
| EXAONE 2.4B | Baseline (순정) | 37.5% | 72.5% | 20.0% |
| EXAONE 2.4B | Fine-tuned (Ours) | 68.5% | 92.5% | 60.0% |
핵심 요약: LoRA 파인튜닝을 통해 한국어 질의에 대한 SQL 변환 정확도를 37.5%에서 68.5%로 대폭 끌어올렸으며, 2.4B의 작은 파라미터 크기에도 불구하고 복잡한 추론이 가능함을 입증했습니다.
1pip install torch transformers peft accelerate
2
3import torch
4from transformers import AutoTokenizer, AutoModelForCausalLM
5from peft import PeftModel
6
7# 1. 베이스 모델 및 토크나이저 로드
8base_model_id = "LGAI-EXAONE/EXAONE-3.5-2.4B-Instruct"
9adapter_id = "yeongseok11/exaone-2.4b-erp-nl2sql" # 본 모델 ID
10
11tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
12base_model = AutoModelForCausalLM.from_pretrained(
13 base_model_id,
14 torch_dtype=torch.bfloat16,
15 device_map="auto",
16 trust_remote_code=True
17)
18
19# 2. 파인튜닝된 LoRA 어댑터 병합
20model = PeftModel.from_pretrained(base_model, adapter_id)
21model.eval()
22
23# 3. 프롬프트 정의 (Alpaca 포맷 권장)
24schema_context = """
25[Tables]
26employees(emp_id, name, dept_id, hire_date, salary)
27departments(dept_id, dept_name, location)
28"""
29question = "IT 부서 직원들의 평균 연봉을 구해줘."
30
31prompt = f"""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
32
33### Instruction:
34아래 스키마를 참고하여 질문을 SQL로 변환하세요.
35
36### Input:
37### 질문:
38{question}
39
40### 스키마:
41{schema_context}
42
43### Response:
44"""
45
46# 4. SQL 생성
47inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
48
49with torch.no_grad():
50 outputs = model.generate(
51 **inputs,
52 max_new_tokens=256,
53 do_sample=False,
54 eos_token_id=tokenizer.eos_token_id
55 )
56
57generated_sql = tokenizer.decode(outputs[0], skip_special_tokens=True).split("### Response:")[-1].strip()
58print(f"🔹 생성된 SQL:\n{generated_sql}")