metadata
language: ko
license: apache-2.0
tags:
- function-calling
- korean
- hybridko
base_model: Yaongi/hybridko-exp6
datasets:
- heegyu/glaive-function-calling-v2-ko
HybriKo-117M Function Calling
HybriKo-117M (checkpoint 1962) ๋ชจ๋ธ์ Function Calling ๋ฐ์ดํฐ๋ก ๋ฏธ์ธ์กฐ์ ํ ๋ชจ๋ธ์ ๋๋ค.
ํ์ต ์ ๋ณด
- Base Model: Yaongi/hybridko-exp6
- Dataset: heegyu/glaive-function-calling-v2-ko (5,000 samples)
- Epochs: 2
- Final Loss: ~0.14
- Performance: ๊ธฐ๋ณธ ํฌ๋งท ํ์ต ์๋ฃ (Calculation, Search, Weather ๋ฑ ์ง์)
์ฌ์ฉ๋ฒ (Colab)
import torch
import torch.nn.functional as F
import sentencepiece as spm
from transformers import AutoModelForCausalLM
from huggingface_hub import hf_hub_download
# 1. ๋ชจ๋ธ ๋ก๋
print("๐ฅ Model loading...")
model = AutoModelForCausalLM.from_pretrained(
"Yaongi/HybriKo-117M-Exp6-FunctionCall",
trust_remote_code=True,
torch_dtype=torch.float32
)
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
model.eval()
# 2. ํ ํฌ๋์ด์ ๋ก๋
print("๐ฅ Tokenizer loading...")
sp_path = hf_hub_download("Yaongi/HybriKo-117M-Exp6-FunctionCall", "HybriKo_tok.model")
sp = spm.SentencePieceProcessor()
sp.Load(sp_path)
# 3. ์์ฑ ํจ์ (Stop Logic ํฌํจ)
def generate(text, max_len=200, temp=0.01, top_k=1):
input_ids = torch.tensor([[sp.bos_id()] + sp.EncodeAsIds(text)]).to(device)
# ์ค์ง ํ
์คํธ ๋ฆฌ์คํธ
stop_sequences = ["<|im_end|>", "</tool_code>"]
print("๐ค Generating...", end="", flush=True)
with torch.no_grad():
for _ in range(max_len):
outputs = model(input_ids[:, -512:])
logits = outputs.logits[:, -1] / temp
if top_k:
v, _ = torch.topk(logits, min(top_k, logits.size(-1)))
logits[logits < v[:, [-1]]] = float("-inf")
probs = F.softmax(logits, dim=-1)
next_token = torch.multinomial(probs, 1)
# EOS ํ ํฐ ์ฒดํฌ
if next_token.item() == sp.eos_id():
break
input_ids = torch.cat([input_ids, next_token], dim=1)
# ๐ก Stop Sequence ์ฒดํฌ (๋งค ์คํ
๋์ฝ๋ฉํ์ฌ ํ์ธ)
curr_text = sp.DecodeIds(input_ids[0].tolist())
# ํ๋กฌํํธ ์ดํ ์์ฑ๋ ๋ถ๋ถ๋ง ์๋ผ์ ํ์ธ
# (SentencePiece ํน์ฑ์ ์ ํํ ์ฌ๋ผ์ด์ฑ์ ์ํด ์ ์ฒด ๋์ฝ๋ฉ ํ ๋น๊ต๊ฐ ์์ )
gen_part = curr_text[len(text):] # ๊ทผ์ฌ์ ์ธ ๋ฐฉ๋ฒ
# ์ ํ๋๋ฅผ ์ํด full text์์ ๊ฒ์
should_stop = False
for seq in stop_sequences:
if seq in curr_text and not (seq in text): # ํ๋กฌํํธ์ ์ด๋ฏธ ์๋ ๊ฒฝ์ฐ๋ ์ ์ธ
# ๋ฐฉ๊ธ ์์ฑ๋ ๋ถ๋ถ์ ํ ํฐ์ด ์์ฑ๋์๋์ง ํ์ธ
should_stop = True
break
if should_stop:
break
return sp.DecodeIds(input_ids[0].tolist())
# 4. ์คํ ์์
prompt = '''<|im_start|>system
๋น์ ์ ๋๊ตฌ ํธ์ถ(function calling)์ด ๊ฐ๋ฅํ AI ์ด์์คํดํธ์
๋๋ค.
<tools>
{"name": "get_news_headlines", "parameters": {"country": "string"}}
</tools><|im_end|>
<|im_start|>user
ํ๊ตญ์ ์ต์ ๋ด์ค ์๋ ค์ค<|im_end|>
<|im_start|>assistant
'''
print("\nPrompt:")
print(prompt)
result = generate(prompt, max_len=200)
# ์ถ๋ ฅ ๊น๋ํ๊ฒ ์ ๋ฆฌ
print("\n" + "="*50)
print("Result:")
print(result)
print("="*50)
'''