Datasets:
Tasks:
Text2Text Generation
Modalities:
Text
Formats:
parquet
Languages:
English
Size:
1K - 10K
Tags:
text-to-sql
License:
HusnaManakkot
commited on
Commit
•
a56e568
1
Parent(s):
d6893cb
Update spider.py
Browse files
spider.py
CHANGED
@@ -1,24 +1,22 @@
|
|
1 |
-
from datasets import load_dataset, Dataset
|
2 |
import pandas as pd
|
|
|
3 |
|
4 |
-
# Step 1:
|
5 |
-
|
|
|
6 |
|
7 |
-
# Step 2:
|
8 |
-
my_spider_df = pd.DataFrame(my_spider_dataset)
|
9 |
-
|
10 |
-
# Step 3: Add a new row to the DataFrame
|
11 |
new_example = {
|
12 |
-
'db_id': '
|
13 |
-
'query': "SELECT
|
14 |
-
'question': '
|
15 |
-
'query_toks': ['SELECT', '
|
16 |
-
'query_toks_no_value': ['SELECT', '
|
17 |
-
'question_toks': ['
|
18 |
'sql': {
|
19 |
-
'select': [(0, [(3, (0, '
|
20 |
'from': {'table_units': [('table_unit', 0)], 'conds': []}, # ('table_unit', table_id), assuming 'employees' is the first table
|
21 |
-
'where': [(0, False, [(2, (0, '
|
22 |
'groupBy': [],
|
23 |
'having': [],
|
24 |
'orderBy': [],
|
@@ -28,11 +26,7 @@ new_example = {
|
|
28 |
'except': None
|
29 |
}
|
30 |
}
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
# Step 4: Convert the modified DataFrame back to a Hugging Face dataset
|
35 |
-
modified_spider_dataset = Dataset.from_pandas(my_spider_df)
|
36 |
-
|
37 |
-
# Step 5: Push the modified dataset back to your Hugging Face account
|
38 |
-
modified_spider_dataset.push_to_hub("HusnaManakkot/new-spider-HM")
|
|
|
|
|
1 |
import pandas as pd
|
2 |
+
from datasets import Dataset
|
3 |
|
4 |
+
# Step 1: Read the Parquet files
|
5 |
+
train_df = pd.read_parquet('train-00000-of-00001.parquet')
|
6 |
+
validation_df = pd.read_parquet('validation-00000-of-00001.parquet')
|
7 |
|
8 |
+
# Step 2: Add the new row to the training DataFrame
|
|
|
|
|
|
|
9 |
new_example = {
|
10 |
+
'db_id': 'hr_1', # Replace with the actual database ID
|
11 |
+
'query': "SELECT COUNT(*) FROM employees WHERE department = 'Sales' AND salary > 50000;",
|
12 |
+
'question': 'How many employees in the Sales department have a salary greater than $50,000?',
|
13 |
+
'query_toks': ['SELECT', 'COUNT', '(', '*', ')', 'FROM', 'employees', 'WHERE', 'department', '=', "'Sales'", 'AND', 'salary', '>', '50000', ';'],
|
14 |
+
'query_toks_no_value': ['SELECT', 'COUNT', '(', '*', ')', 'FROM', 'employees', 'WHERE', 'department', '=', 'VALUE', 'AND', 'salary', '>', 'VALUE', ';'],
|
15 |
+
'question_toks': ['How', 'many', 'employees', 'in', 'the', 'Sales', 'department', 'have', 'a', 'salary', 'greater', 'than', '$50,000', '?'],
|
16 |
'sql': {
|
17 |
+
'select': [(0, [(3, (0, '*'))])], # (agg_id, val_unit), agg_id for COUNT is 0, val_unit is (column_id, column_name)
|
18 |
'from': {'table_units': [('table_unit', 0)], 'conds': []}, # ('table_unit', table_id), assuming 'employees' is the first table
|
19 |
+
'where': [(0, False, [(2, (0, 'department')), '=', (1, "'Sales'")]), 'AND', (0, False, [(2, (0, 'salary')), '>', (1, '50000')])],
|
20 |
'groupBy': [],
|
21 |
'having': [],
|
22 |
'orderBy': [],
|
|
|
26 |
'except': None
|
27 |
}
|
28 |
}
|
29 |
+
train_df = train_df.append(new_example, ignore_index=True)
|
30 |
|
31 |
+
# Step 3: Write the modified DataFrame back to Parquet
|
32 |
+
train_df.to_parquet('train-00000-of-00001.parquet')
|
|
|
|
|
|
|
|
|
|