Text Generation
Transformers
PyTorch
Safetensors
English
t5
text2text-generation
text2sql
conversational
text-generation-inference
Instructions to use gaussalgo/T5-LM-Large-text2sql-spider with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use gaussalgo/T5-LM-Large-text2sql-spider with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="gaussalgo/T5-LM-Large-text2sql-spider") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("gaussalgo/T5-LM-Large-text2sql-spider") model = AutoModelForSeq2SeqLM.from_pretrained("gaussalgo/T5-LM-Large-text2sql-spider", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use gaussalgo/T5-LM-Large-text2sql-spider with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "gaussalgo/T5-LM-Large-text2sql-spider" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gaussalgo/T5-LM-Large-text2sql-spider", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/gaussalgo/T5-LM-Large-text2sql-spider
- SGLang
How to use gaussalgo/T5-LM-Large-text2sql-spider with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "gaussalgo/T5-LM-Large-text2sql-spider" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gaussalgo/T5-LM-Large-text2sql-spider", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "gaussalgo/T5-LM-Large-text2sql-spider" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gaussalgo/T5-LM-Large-text2sql-spider", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use gaussalgo/T5-LM-Large-text2sql-spider with Docker Model Runner:
docker model run hf.co/gaussalgo/T5-LM-Large-text2sql-spider
File size: 4,209 Bytes
52943d3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | import json
import random
from typing import List, Dict, Tuple
from adaptor.evaluators.generative import ROUGE, BLEU
from adaptor.lang_module import LangModule
from adaptor.objectives.seq2seq import Sequence2Sequence
from adaptor.utils import AdaptationArguments, StoppingStrategy
from adaptor.schedules import ParallelSchedule
from adaptor.adapter import Adapter
import wandb
# Dataset creation
## Define paths to JSON files
db_path = 'db_schemas.json'
spider_dataset_train_path = 'spider/train_spider.json'
spider_dataset_dev_path = 'spider/dev.json'
spider_syn_train_path = 'Spider-Syn/train_spider.json'
spider_syn_dev_path = 'Spider-Syn/dev.json'
## Open files
with open(db_path, 'r') as file_db:
database_schemas = json.load(file_db)
with open(spider_dataset_train_path, 'r') as file_spider:
spider_train_dataset = json.load(file_spider)
with open(spider_dataset_dev_path, 'r') as file_spider:
spider_dev_dataset = json.load(file_spider)
with open(spider_syn_train_path, 'r') as file_spider:
spider_syn_train_dataset = json.load(file_spider)
with open(spider_syn_dev_path, 'r') as file_spider:
spider_syn_dev_dataset = json.load(file_spider)
## Include spider questions with synonyms (questions include text which is not in DB columns)
spider_train_dataset.extend([question for question in spider_syn_train_dataset if question['SpiderQuestion']!=question['SpiderSynQuestion']])
spider_dev_dataset.extend([question for question in spider_syn_dev_dataset if question['SpiderQuestion']!=question['SpiderSynQuestion']])
random.shuffle(spider_train_dataset)
random.shuffle(spider_dev_dataset)
def create_prompt(question: str, schema: str) -> str:
return " ".join(["Question: ",question, "Schema:", schema])
def create_vals_and_labels(dataset: List[dict], db_dict: Dict[str, str]) -> Tuple[List[str], List[str]]:
list_labels = [data["query"] for data in dataset]
list_prompts = [create_prompt(data["question"], db_dict[data["db_id"]])
if "question" in data else create_prompt(data["SpiderSynQuestion"], db_dict[data["db_id"]]) for data in dataset]
return list_prompts, list_labels
## Training prompts and labels
prompts_train, labels_train = create_vals_and_labels(spider_train_dataset, database_schemas)
assert len(prompts_train)==len(labels_train)
## Evaluation prompts and labels
prompts_eval, labels_eval = create_vals_and_labels(spider_dev_dataset, database_schemas)
assert len(prompts_eval)==len(labels_eval)
# Training
lang_module = LangModule("google/t5-large-lm-adapt")
evaluators = [BLEU(), ROUGE(decides_convergence=True)]
wandb.init(project="chatbot")
seq_qa = Sequence2Sequence(lang_module,
texts_or_path=prompts_train,
labels_or_path=labels_train,
val_texts_or_path=prompts_eval,
val_labels_or_path=labels_eval,
batch_size=4,
val_evaluators=evaluators,
objective_id="txt2SQL_Spider")
training_arguments = AdaptationArguments(output_dir="checkpoints-txt2sql",
learning_rate=5e-5,
stopping_strategy=StoppingStrategy.ALL_OBJECTIVES_CONVERGED,
stopping_patience=8,
save_total_limit=8,
do_train=True,
do_eval=True,
bf16=True,
warmup_steps=100,
gradient_accumulation_steps=8,
logging_steps=10,
eval_steps=200,
save_steps=200,
num_train_epochs=10,
evaluation_strategy="steps")
schedule = ParallelSchedule(objectives=[seq_qa],
args=training_arguments)
adapter = Adapter(lang_module, schedule, args=training_arguments)
adapter.train() |