Model Card for gemma-3-text-to-sql-fast

This model is a fine-tuned version of google/gemma-3-1b-it. It has been trained using TRL.

Quick start

# Cài đặt thư viện cốt lõi để chạy mô hình AI
%pip install "transformers>=4.51.3" "torchao>=0.16.0" accelerate

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
from peft import PeftModel

print("Bước 1: Đang tải bộ tách từ (Tokenizer)...")
tokenizer = AutoTokenizer.from_pretrained("hduc01/gemma-3-text-to-sql-fast")

print("Bước 2: Tải mô hình nền tảng gốc của Google...")
base_model = AutoModelForCausalLM.from_pretrained(
    "google/gemma-3-1b-it",
    torch_dtype=torch.float16,
    low_cpu_mem_usage=True,
    device_map="auto"
)

print("Bước 3: Bọc mảnh Adapter của bạn lên trên mô hình gốc...")
# Lấy file 1.27 GB trên Hub của bạn về để ráp vào mô hình gốc
model = PeftModel.from_pretrained(base_model, "hduc01/gemma-3-text-to-sql-fast")

print("Bước 4: Vá lỗi toán học cấu hình tầng sâu (Sửa lỗi Issue #2777)...")
# Ép bộ não sau khi đã bọc Adapter phải tắt tính năng liên kết trọng số từ vựng
model.config.tie_word_embeddings = False

print("Bước 5: Khởi tạo dây chuyền Pipeline suy luận...")
generator = pipeline(
    "text-generation", 
    model=model, 
    tokenizer=tokenizer
)

# 1. Định nghĩa SCHEMA và Câu hỏi chuẩn chuyên môn Text-to-SQL
test_schema = """CREATE TABLE orders (
    order_id INT,
    customer_id INT,
    order_date DATE,
    total_amount DECIMAL(10,2),
    status VARCHAR(20)
);"""

test_question = "Find the total amount spent on all orders that have a status of 'Completed' after January 1st, 2020."

formatted_prompt = f"""Given the <SCHEMA> and the <USER_QUERY>, generate the corresponding SQL command to retrieve the desired data, considering the query's syntax, semantics, and schema constraints.
<SCHEMA>
{test_schema}
</SCHEMA>
<USER_QUERY>
{test_question}
</USER_QUERY>"""

messages = [
    {"role": "system", "content": "You are a text to SQL query translator. Users will ask you questions in English and you will generate a SQL query based on the provided SCHEMA."},
    {"role": "user", "content": formatted_prompt}
]

print("AI đang đọc SCHEMA và tiến hành dịch sang câu lệnh SQL...")
output = generator(
    messages, 
    max_new_tokens=100, 
    temperature=0.1,    # Khóa độ sáng tạo ở mức thấp nhất
    do_sample=False,
    return_full_text=False
)

print("\nCÂU LỆNH SQL:")
print(output[0]["generated_text"])

Training procedure

This model was trained with SFT.

Framework versions

  • TRL: 1.7.1
  • Transformers: 5.12.1
  • Pytorch: 2.11.0+cu128
  • Datasets: 5.0.0
  • Tokenizers: 0.22.2

Citations

Cite TRL as:

@software{vonwerra2020trl,
  title   = {{TRL: Transformers Reinforcement Learning}},
  author  = {von Werra, Leandro and Belkada, Younes and Tunstall, Lewis and Beeching, Edward and Thrush, Tristan and Lambert, Nathan and Huang, Shengyi and Rasul, Kashif and Gallouédec, Quentin},
  license = {Apache-2.0},
  url     = {https://github.com/huggingface/trl},
  year    = {2020}
}
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for hduc01/gemma-3-text-to-sql-fast

Finetuned
(559)
this model