Text-to-SQL LoRA Model (Vietnamese + English)

Model Description

This is a LoRA (Low-Rank Adaptation) fine-tuned model based on google/gemma-3-270m-it for converting natural language queries to SQL statements. The model supports both Vietnamese and English input queries.

Model Details

  • Base Model: google/gemma-3-270m-it
  • Fine-tuning Method: LoRA (Low-Rank Adaptation)
  • Task: Text-to-SQL Generation
  • Languages: Vietnamese, English
  • License: Apache 2.0

Training Configuration

  • LoRA Rank (r): 16
  • LoRA Alpha: 32
  • Training Epochs: 3
  • Learning Rate: 0.0002
  • Target Modules: q_proj, v_proj, k_proj, o_proj, gate_proj, up_proj, down_proj

Usage

Using with transformers + PEFT

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

# Load base model and tokenizer
base_model_name = "google/gemma-3-270m-it"
model = AutoModelForCausalLM.from_pretrained(
    base_model_name,
    torch_dtype=torch.float16,
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(base_model_name)

# Load LoRA adapter
model = PeftModel.from_pretrained(model, "lam2/text2sql")

# Generate SQL
def generate_sql(text):
    prompt = f"<start_of_turn>user\nConvert the following natural language query to SQL:\n{text}<end_of_turn>\n<start_of_turn>model\n"
    
    inputs = tokenizer(prompt, return_tensors="pt")
    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_new_tokens=256,
            temperature=0.1,
            do_sample=True,
            pad_token_id=tokenizer.eos_token_id
        )
    
    result = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return result.split("<start_of_turn>model\n")[-1].strip()

# Example usage
sql = generate_sql("Thông tin cơ bản của người dùng")
print(sql)

Using with vLLM (Recommended for Production)

from vllm import LLM, SamplingParams

llm = LLM(
    model="lam2/text2sql",
    enable_lora=True,
    max_model_len=2048
)

sampling_params = SamplingParams(
    temperature=0.1,
    max_tokens=256,
    stop=["<end_of_turn>"]
)

prompt = "Convert the following natural language query to SQL:\nShow all customers"
outputs = llm.generate([prompt], sampling_params)
print(outputs[0].outputs[0].text)

Example Queries

Vietnamese Examples:

  • Input: "Thông tin của điện thoại samsung Ultra24"
  • Output: SELECT * FROM catalog WHERE model='ss24';

Performance

  • Inference Speed: ~0.1-0.5 seconds per query (GPU)
  • Model Size: ~32MB (LoRA adapters only)
  • Memory Usage: ~2GB GPU memory
  • Accuracy: High accuracy on Vietnamese and English text-to-SQL tasks

Limitations

  • Optimized for specific database schemas
  • May require fine-tuning for domain-specific terminology
  • Best performance with queries similar to training data

Training Data

The model was trained on a dataset containing Vietnamese and English text-to-SQL pairs, focusing on:

  • Business intelligence queries
  • Database operations
  • Vietnamese language constructs
  • Technical terminology

Ethical Considerations

This model should be used responsibly:

  • Validate generated SQL queries before execution
  • Be aware of potential SQL injection risks
  • Consider privacy implications when processing sensitive queries

Citation

@misc{text-to-sql-lora-gemma,
  title={Text-to-SQL LoRA Model based on Gemma},
  author={Your Name},
  year={2024},
  publisher={Hugging Face},
  url={https://huggingface.co/lam2/text2sql}
}

Contact

For questions or issues, please create an issue in the model repository.


Generated on 2025-08-28 09:28:45 UTC

Downloads last month
7
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for lam2/text2sql

Adapter
(13)
this model