Instructions to use castellina/polyglot-ko-txt2sql with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use castellina/polyglot-ko-txt2sql with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="castellina/polyglot-ko-txt2sql") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("castellina/polyglot-ko-txt2sql") model = AutoModelForCausalLM.from_pretrained("castellina/polyglot-ko-txt2sql") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use castellina/polyglot-ko-txt2sql with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "castellina/polyglot-ko-txt2sql" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "castellina/polyglot-ko-txt2sql", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/castellina/polyglot-ko-txt2sql
- SGLang
How to use castellina/polyglot-ko-txt2sql with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "castellina/polyglot-ko-txt2sql" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "castellina/polyglot-ko-txt2sql", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "castellina/polyglot-ko-txt2sql" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "castellina/polyglot-ko-txt2sql", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use castellina/polyglot-ko-txt2sql with Docker Model Runner:
docker model run hf.co/castellina/polyglot-ko-txt2sql
polyglot-ko-1b-txt2sql
polyglot-ko-1b-txt2sql์ ํ๊ตญ์ด ์์ฐ์ด ์ง๋ฌธ์ SQL ์ฟผ๋ฆฌ๋ก ๋ณํํ๊ธฐ ์ํด ํ์ธํ๋๋ ํ
์คํธ ์์ฑ ๋ชจ๋ธ์
๋๋ค.
๊ธฐ๋ฐ ๋ชจ๋ธ์ EleutherAI/polyglot-ko-1.3b๋ฅผ ์ฌ์ฉํ์ผ๋ฉฐ, LoRA๋ฅผ ํตํด ๊ฒฝ๋ ํ์ธํ๋๋์์ต๋๋ค.
ํ์ธํ๋์ ์ฒ์ ํด๋ณธ ๊ธ์ด์ด๊ฐ ์ค์ต์ฉ์ผ๋ก ๋ง๋ ์ฒซ ๋ชจ๋ธ๋ก ์ฑ๋ฅ์ ๋ณด์ฅํ ์ ์์ผ๋ ์ฐธ๊ณ ๋ฐ๋๋๋ค.
๋ชจ๋ธ ์ ๋ณด
- Base model: EleutherAI/polyglot-ko-1.3b
- Fine-tuning: QLoRA (4bit quantization + PEFT)
- Task: Text2SQL (์์ฐ์ด โ SQL ๋ณํ)
- Tokenizer: ๋์ผํ ํ ํฌ๋์ด์ ์ฌ์ฉ
ํ์ต ๋ฐ์ดํฐ์
๋ชจ๋ธ์ ํ๊ตญ์ด SQL ๋ณํ ํ์คํฌ๋ฅผ ์ํด ์ค๊ณ๋ ์์ฐ์ด ์ง๋ฌธ-์ฟผ๋ฆฌ ํ์ด๋ก ํ์ธํ๋๋์์ต๋๋ค.
shangrilar/ko_text2sql ๋ฐ์ดํฐ์ ์ผ๋ถ
์ ์ฒ๋ฆฌ: DDL-Question-SQL ๊ตฌ์กฐ๋ก prompt ๊ตฌ์ฑ
ํฌ๊ธฐ: ์ฝ 25,000๊ฑด์ DDL + ์์ฐ์ด ์ง๋ฌธ + SQL ์ ๋ต ์
ํ๊ฐ ๊ฒฐ๊ณผ
- ํ๊ฐ ๋ฐฉ์: GPT-4.1-nano ๋ชจ๋ธ์๊ฒ gen_sql๊ณผ gt_sql ๋น๊ต ํ ํ๊ฐ ์์ฒญ
- ํ๊ฐ ๊ธฐ์ค: ๊ฒฐ๊ณผ ๋์ผ ์ฌ๋ถ ๊ธฐ๋ฐ yes/no ํ๋จ (JSON response: {"resolve_yn": "yes"})
- ํ๊ฐ ๊ฒฐ๊ณผ:
- ๋ฒ ์ด์ค ๋ชจ๋ธ ์ ํ๋: 68%
- ํ์ธํ๋ ๋ชจ๋ธ ์ ํ๋: 19%
๋ฌธ์ ์
๋ฒ ์ด์ค๋ผ์ธ ๋ชจ๋ธ์ gen_sql์ SQL ์ฟผ๋ฆฌ๋ฅผ ์์ฑํ์ง ๋ชปํ๊ณ , ์ง๋ฌธ์ ๋ฐ๋ณตํ๊ฑฐ๋ ์๋ฏธ ์๋ ํ ์คํธ๋ฅผ ์ถ๋ ฅํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์๋ค.
ํ์ธํ๋ ๋ชจ๋ธ์ SQL ํํ๋ฅผ ํ๋ด๋ด๊ธด ํ์ง๋ง, ์กด์ฌํ์ง ์๋ ์ปฌ๋ผ๋ช ์ด๋ ํ ์ด๋ธ๋ช ์ ํฌํจํ๋ ๋ฑ ๋ ผ๋ฆฌ์ ์ผ๋ก ํ๋ฆฐ ์ฟผ๋ฆฌ๋ฅผ ์์ฑํ๋ค.
ํ๊ฐ ๋ชจ๋ธ(GPT-4.1-nano)์ ๋ฒ ์ด์ค๋ผ์ธ ๋ชจ๋ธ์ด ์๋ชป ์์ฑํ ์ฟผ๋ฆฌ์ ๋ํด "resolve_yn": "yes"๋ผ๊ณ ์๋ชป ํ๋จํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์๋ค.
์๋ฅผ ๋ค์ด, gen_sql์ด SQL ํ์์ ์ ํ ๋ฐ๋ฅด์ง ์๋๋ผ๋ resolve_yn = yes๋ก ์๋ชป ํ๊ฐ๋๋ ๊ฒฝ์ฐ๊ฐ ์์๋ค.
์ปฌ๋ผ๋ช ๋ฐ ํ ์ด๋ธ๋ช ์ด ์กด์ฌํ์ง ์๊ฑฐ๋ ์๋ชป๋ ์ฟผ๋ฆฌ์์๋ resolve_yn = yes๋ก ์๋ชป ๋ถ๋ฅ๋ ๊ฒฝ์ฐ๊ฐ ์กด์ฌํ๋ค.
ํ๊ฐ์(GPT ๋ชจ๋ธ)๋ ๋ฌธ๋ฒ์ ํ๋น์ฑ์ด๋ ํ ์ด๋ธ ๊ตฌ์กฐ ๋ฐ์ ์ฌ๋ถ๋ฅผ ์ ๋๋ก ํ๋จํ์ง ๋ชปํ๊ณ , ๋จ์ ํ ์คํธ ์ ์ฌ์ฑ์ ๊ธฐ๋ฐํด ํ๋ณํ๋ ๊ฒฝํฅ์ ๋ณด์๋ค.
์ฌ์ฉ ์์
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
model = AutoModelForCausalLM.from_pretrained("your-username/polyglot-ko-1b-txt2sql", device_map="auto")
tokenizer = AutoTokenizer.from_pretrained("your-username/polyglot-ko-1b-txt2sql")
generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
prompt = """
๋น์ ์ SQL ์ ๋ฌธ๊ฐ์
๋๋ค.
### DDL:
CREATE TABLE players (
player_id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(255) UNIQUE NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
date_joined DATETIME NOT NULL,
last_login DATETIME
);
### Question:
์ฌ์ฉ์ ์ด๋ฆ์ 'admin'์ด ํฌํจ๋ ๊ณ์ ์๋?
### SQL:
"""
outputs = generator(prompt, do_sample=False, max_new_tokens=128)
print(outputs[0]["generated_text"])
- Downloads last month
- 3
Model tree for castellina/polyglot-ko-txt2sql
Base model
EleutherAI/polyglot-ko-1.3b
docker model run hf.co/castellina/polyglot-ko-txt2sql