Downloads · 30 days
0
hduc01/gemma-3-text-to-sql-fast
gemma-3-text-to-sql-fast is a machine learning model from hduc01. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers.
This model is a fine-tuned version of google/gemma-3-1b-it. It has been trained using TRL.
Downloads · 30 days
0
Access
Public
Updated Jul 5, 2026
Repo size
1.3 GB
Likes
0
Public
Click a slice to open those files.
.safetensors1.2 GB · 97%
From the Hugging Face model README
This model is a fine-tuned version of google/gemma-3-1b-it. It has been trained using TRL.
# 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"])
This model was trained with SFT.
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}
}