rakeshkiriyath commited on
Commit
ffb8cc9
1 Parent(s): 2127d3e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +37 -9
README.md CHANGED
@@ -10,6 +10,7 @@ tags:
10
  - sql
11
  datasets:
12
  - b-mc2/sql-create-context
 
13
  ---
14
  # Model Card
15
 
@@ -18,23 +19,50 @@ datasets:
18
  This is my first fine tuned LLM project.
19
 
20
 
21
- ## Prompt
22
 
23
- query = List the creation year, name and budget of each department
 
24
 
25
- f"Translate the following English question to SQL: {query}
 
26
 
27
- ## Output
 
28
 
29
- SELECT creation_year, name, budget FROM department
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
 
32
  #### Training Hyperparameters
33
 
34
- num_train_epochs=1
35
- per_device_train_batch_size=3
36
- gradient_accumulation_steps=9
37
- learning_rate=5e-5
38
  weight_decay=0.01
39
 
40
 
 
10
  - sql
11
  datasets:
12
  - b-mc2/sql-create-context
13
+ license: other
14
  ---
15
  # Model Card
16
 
 
19
  This is my first fine tuned LLM project.
20
 
21
 
22
+ ## Usage
23
 
24
+ ```
25
+ from transformers import GPT2LMHeadModel, GPT2Tokenizer
26
 
27
+ finetunedGPT = GPT2LMHeadModel.from_pretrained("rakeshkiriyath/gpt2Medium_text_to_sql")
28
+ finetunedTokenizer = GPT2Tokenizer.from_pretrained("rakeshkiriyath/gpt2Medium_text_to_sql")
29
 
30
+ def generate_text_to_sql(query, model, tokenizer, max_length=256):
31
+ prompt = f"Translate the following English question to SQL: {query}"
32
 
33
+ input_tensor = tokenizer.encode(prompt, return_tensors='pt').to('cuda')
34
+
35
+ output = model.generate(input_tensor, max_length=max_length, num_return_sequences=1, pad_token_id=tokenizer.eos_token_id)
36
+
37
+ decoded_output = tokenizer.decode(output[0], skip_special_tokens=True)
38
+
39
+ # Return only the SQL part (removing the input text)
40
+ sql_output = decoded_output[len(prompt):].strip()
41
+
42
+ return sql_output
43
+
44
+ queryList = ["I need a list of employees who joined in the company last 6 months with a salary hike of 30% ",
45
+ "Give me loginid,status,company of a user who is mapped to the organization XYZ "]
46
+
47
+ for query in queryList:
48
+
49
+ sql_result = generate_text_to_sql(query, finetunedGPT, finetunedTokenizer)
50
+ print(sql_result,"\n")
51
+
52
+ ```
53
+
54
+ ### Output
55
+
56
+ SELECT COUNT(*) FROM employees WHERE last_6_months = "6 months" AND salary_hike = "30%" \
57
+ SELECT loginid,status,company FROM user_mapped_to_organization WHERE mapping = "XYZ"
58
 
59
 
60
  #### Training Hyperparameters
61
 
62
+ num_train_epochs=1 \
63
+ per_device_train_batch_size=3 \
64
+ gradient_accumulation_steps=9 \
65
+ learning_rate=5e-5 \
66
  weight_decay=0.01
67
 
68