Views
No views yet
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.| 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 |
1from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
2from peft import PeftModel
3import torch
4
5base = "Qwen/Qwen2.5-7B-Instruct"
6adapter = "hoadm/qwen25-bird-translator-vi"
7
8bnb = BitsAndBytesConfig(
9 load_in_4bit=True,
10 bnb_4bit_compute_dtype=torch.bfloat16,
11 bnb_4bit_quant_type="nf4",
12)
13tokenizer = AutoTokenizer.from_pretrained(base)
14model = AutoModelForCausalLM.from_pretrained(base, quantization_config=bnb, device_map="auto")
15model = PeftModel.from_pretrained(model, adapter)
16model.eval()
17
18def translate(question: str, evidence: str) -> dict:
19 system = (
20 "You are an expert translator. Translate the English Text-to-SQL question "
21 "and evidence into Vietnamese. Return JSON: "
22 '{"question_vi": "...", "evidence_vi": "..."}'
23 )
24 user = f'Question: {question}\nEvidence: {evidence if evidence.strip() else "(no evidence)"}'
25 messages = [{"role": "system", "content": system},
26 {"role": "user", "content": user}]
27 text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
28 inputs = tokenizer(text, return_tensors="pt").to(model.device)
29 with torch.no_grad():
30 out = model.generate(**inputs, max_new_tokens=256, do_sample=False)
31 return tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
32
33print(translate(
34 "What is the highest eligible free rate for K-12 students in Alameda County?",
35 "Eligible free rate for K-12 = `Free Meal Count (K-12)` / `Enrollment (K-12)`"
36))1@article{li2024bird,
2 title = {Can LLM Already Serve as a Database Interface? A Big Bench for Large-Scale Database Grounded Text-to-SQLs},
3 author = {Li, Jinyang and Hui, Binyuan and Qu, Ge and Yang, Jiaxi and others},
4 journal = {Advances in Neural Information Processing Systems},
5 volume = {36},
6 year = {2024},
7 url = {https://arxiv.org/abs/2305.03111}
8}