Views
No views yet
DatasetDict object with train, test, and validation sets.1DatasetDict({
2 train: Dataset({
3 features: ['answer', 'question', 'context', 'afr question'],
4 num_rows: 118692
5 })
6 test: Dataset({
7 features: ['answer', 'question', 'context', 'afr question'],
8 num_rows: 14838
9 })
10 validation: Dataset({
11 features: ['answer', 'question', 'context', 'afr question'],
12 num_rows: 14838
13 })
14})question, the model also takes in the schema context such that it can generate more accurate queries for a given database.1Table context: CREATE TABLE table_55794 (
2 "Home team" text,
3 "Home team score" text,
4 "Away team" text,
5 "Away team score" text,
6 "Venue" text,
7 "Crowd" real,
8 "Date" text
9)
10Question: Watter tuisspan het'n span mebbourne?
11Answer:SELECT "Home team score" FROM table_55794 WHERE "Away team" = 'melbourne'input_ids to generate an output SQL query. However the prompt must be structured in a specific way.prompt must start with the table/schema description followed by the question followed by an empty answer. Below we illustrate an example on how to use it. Furthermore, our combined dataset looks as follows:1DatasetDict({
2 train: Dataset({
3 features: ['input_ids', 'labels'],
4 num_rows: 118692
5 })
6 test: Dataset({
7 features: ['input_ids', 'labels'],
8 num_rows: 14838
9 })
10 validation: Dataset({
11 features: ['input_ids', 'labels'],
12 num_rows: 14838
13 })
14})1from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, Trainer, TrainingArguments
2# Load the model and tokenizer from Hugging Face Hub
3repo_name = "JsteReubsSoftware/en-af-sql-training-1727527893"
4en_af_sql_model = AutoModelForSeq2SeqLM.from_pretrained(repo_name, torch_dtype=torch.bfloat16)
5en_af_sql_model = en_af_sql_model.to('cuda')
6tokenizer = AutoTokenizer.from_pretrained(repo_name)
7
8question = "Watter tuisspan het'n span mebbourne?"
9context = "CREATE TABLE table_55794 (
10 "Home team" text,
11 "Home team score" text,
12 "Away team" text,
13 "Away team score" text,
14 "Venue" text,
15 "Crowd" real,
16 "Date" text
17)"
18
19prompt = f"""Tables:
20{context}
21
22Question:
23{question}
24
25Answer:
26"""
27inputs = tokenizer(prompt, return_tensors='pt')
28inputs = inputs.to('cuda')
29
30output = tokenizer.decode(
31 en_af_sql_model.generate(
32 inputs["input_ids"],
33 max_new_tokens=200,
34 )[0],
35 skip_special_tokens=True
36)
37
38print("Predicted SQL Query:")
39print(output)1output_dir = f'./en-af-sql-training-{str(int(time.time()))}'
2
3training_args = TrainingArguments(
4 output_dir=output_dir,
5 learning_rate=5e-3,
6 num_train_epochs=2,
7 per_device_train_batch_size=16, # batch size per device during training
8 per_device_eval_batch_size=16, # batch size for evaluation
9 weight_decay=0.01,
10 logging_steps=50,
11 evaluation_strategy='steps', # evaluation strategy to adopt during training
12 eval_steps=500, # number of steps between evaluation
13)
14
15trainer = Trainer(
16 model=finetuned_model,
17 args=training_args,
18 train_dataset=tokenized_datasets['train'],
19 eval_dataset=tokenized_datasets['validation'],
20)| Training Loss | Epoch | Step | Validation Loss |
|---|---|---|---|
| 0.0573 | 0.1348 | 500 | 0.0452 |
| 0.0424 | 0.2695 | 1000 | 0.0364 |
| 0.037 | 0.4043 | 1500 | 0.0323 |
| 0.0356 | 0.5391 | 2000 | 0.0287 |
| 0.0328 | 0.6739 | 2500 | 0.0269 |
| 0.0281 | 0.8086 | 3000 | 0.0255 |
| 0.0286 | 0.9434 | 3500 | 0.0238 |
| 0.0269 | 1.0782 | 4000 | 0.0233 |
| 0.0247 | 1.2129 | 4500 | 0.0225 |
| 0.0245 | 1.3477 | 5000 | 0.0217 |
| 0.0226 | 1.4825 | 5500 | 0.0214 |
| 0.0245 | 1.6173 | 6000 | 0.0211 |
| 0.024 | 1.7520 | 6500 | 0.0210 |
| 0.0249 | 1.8868 | 7000 | 0.0210 |
1@misc{jstereubssoftware_2024_Afr2SQL,
2 title = {en-af-sql fine-tuned model},
3 author = {JsteReubsSoftware},
4 year = {2024},
5 url = {https://huggingface.co/JsteReubsSoftware/en-af-sql-training-1727527893}
6}