Create The SQL Generation Code
Browse files- The SQL Generation Code +14 -0
The SQL Generation Code
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 2 |
+
|
| 3 |
+
tokenizer = AutoTokenizer.from_pretrained("ansumanpandey/codgen-finetuned-SQLQueryGeneration")
|
| 4 |
+
model = AutoModelForCausalLM.from_pretrained("ansumanpandey/codgen-finetuned-SQLQueryGeneration")
|
| 5 |
+
|
| 6 |
+
def get_sql(query):
|
| 7 |
+
input_text = "Write a SQL query to %s </s>" % query
|
| 8 |
+
features = tokenizer([input_text], return_tensors='pt')
|
| 9 |
+
|
| 10 |
+
output = model.generate(input_ids=features['input_ids'],
|
| 11 |
+
attention_mask=features['attention_mask'],
|
| 12 |
+
max_new_tokens=70)
|
| 13 |
+
sql_query= tokenizer.decode(output[0])
|
| 14 |
+
return sql_query
|