Can LLM Already Serve as A Database Interface? A BIg Bench for Large-Scale Database Grounded Text-to-SQLs
Paper • 2305.03111 • Published • 12
How to use hoadm/qwen25-bird-translator-vi with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-7B-Instruct")
model = PeftModel.from_pretrained(base_model, "hoadm/qwen25-bird-translator-vi")Vietnamese dual-field translator for the BIRD Text-to-SQL benchmark. Fine-tuned from Qwen/Qwen2.5-7B-Instruct with QLoRA (4-bit NF4) to translate both the question and evidence fields from English into Vietnamese in a single pass.
Used to produce hoadm/vibird.
| Base model | Qwen/Qwen2.5-7B-Instruct |
| Method | QLoRA (4-bit NF4, bfloat16 compute) |
| LoRA rank | 16 |
| LoRA alpha | 32 |
| Target modules | q/k/v/o/gate/up/down proj |
| Training data | 3,772 hybrid items (human + GPT, BIRD train) |
| Epochs | 3 |
| Optimizer | paged_adamw_8bit |
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
import torch
base = "Qwen/Qwen2.5-7B-Instruct"
adapter = "hoadm/qwen25-bird-translator-vi"
bnb = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_quant_type="nf4",
)
tokenizer = AutoTokenizer.from_pretrained(base)
model = AutoModelForCausalLM.from_pretrained(base, quantization_config=bnb, device_map="auto")
model = PeftModel.from_pretrained(model, adapter)
model.eval()
def translate(question: str, evidence: str) -> dict:
system = (
"You are an expert translator. Translate the English Text-to-SQL question "
"and evidence into Vietnamese. Return JSON: "
'{"question_vi": "...", "evidence_vi": "..."}'
)
user = f'Question: {question}\nEvidence: {evidence if evidence.strip() else "(no evidence)"}'
messages = [{"role": "system", "content": system},
{"role": "user", "content": user}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
with torch.no_grad():
out = model.generate(**inputs, max_new_tokens=256, do_sample=False)
return tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print(translate(
"What is the highest eligible free rate for K-12 students in Alameda County?",
"Eligible free rate for K-12 = `Free Meal Count (K-12)` / `Enrollment (K-12)`"
))
@article{li2024bird,
title = {Can LLM Already Serve as a Database Interface? A Big Bench for Large-Scale Database Grounded Text-to-SQLs},
author = {Li, Jinyang and Hui, Binyuan and Qu, Ge and Yang, Jiaxi and others},
journal = {Advances in Neural Information Processing Systems},
volume = {36},
year = {2024},
url = {https://arxiv.org/abs/2305.03111}
}