{"id":14181809,"url":"https://github.com/benbogin/spider-schema-gnn","last_synced_at":"2025-08-07T14:31:39.392Z","repository":{"id":96079660,"uuid":"186848417","full_name":"benbogin/spider-schema-gnn","owner":"benbogin","description":"Author implementation of the paper \"Representing Schema Structure with Graph Neural Networks for Text-to-SQL Parsing\"","archived":false,"fork":false,"pushed_at":"2024-07-25T10:15:57.000Z","size":69,"stargazers_count":136,"open_issues_count":1,"forks_count":45,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-08-18T11:13:40.657Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benbogin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-15T14:54:21.000Z","updated_at":"2024-02-15T17:15:05.000Z","dependencies_parsed_at":"2023-03-13T16:38:15.815Z","dependency_job_id":null,"html_url":"https://github.com/benbogin/spider-schema-gnn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbogin%2Fspider-schema-gnn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbogin%2Fspider-schema-gnn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbogin%2Fspider-schema-gnn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benbogin%2Fspider-schema-gnn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benbogin","download_url":"https://codeload.github.com/benbogin/spider-schema-gnn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229052495,"owners_count":18012563,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-18T11:04:13.977Z","updated_at":"2024-12-10T11:30:19.425Z","avatar_url":"https://github.com/benbogin.png","language":"Python","funding_links":[],"categories":["💬 Classic Model","Python"],"sub_categories":[],"readme":"# Representing Schema Structure with Graph Neural Networks for Text-to-SQL Parsing\n\nAuthor implementation of this [ACL 2019 paper](https://arxiv.org/abs/1905.06241).\n\nPlease also see the [follow-up repository](https://github.com/benbogin/spider-schema-gnn-global) with improved results, for this [EMNLP paper](https://www.aclweb.org/anthology/D19-1378.pdf).\n\n## Install \u0026 Configure\n\n1. Install pytorch version 1.0.1.post2 that fits your CUDA version \n   \n   (this repository should probably work with the latest pytorch version, but wasn't tested for it. If you use another version, you'll need to also update the versions of packages in `requirements.txt`)\n    ```\n    pip install https://download.pytorch.org/whl/cu100/torch-1.0.1.post2-cp37-cp37m-linux_x86_64.whl # CUDA 10.0 build\n    ```\n    \n2. Install the rest of required packages\n    ```\n    pip install -r requirements.txt\n    ```\n    \n3. Run this command to install NLTK punkt.\n```\npython -c \"import nltk; nltk.download('punkt')\"\n```\n\n4. Download the dataset from the [official Spider dataset website](https://yale-lily.github.io/spider)\n\n5. Edit the config file `train_configs/defaults.jsonnet` to update the location of the dataset:\n```\nlocal dataset_path = \"dataset/\";\n```\n\n## Training\n\n1. Use the following AllenNLP command to train:\n```\nallennlp train train_configs/defaults.jsonnet -s experiments/name_of_experiment \\\n--include-package dataset_readers.spider \\ \n--include-package models.semantic_parsing.spider_parser\n``` \n\nFirst time loading of the dataset might take a while (a few hours) since the model first loads values from tables and calculates similarity features with the relevant question. It will then be cached for subsequent runs.\n\nYou should get results similar to the following (the `sql_match` is the one measured in the official evaluation test):\n```\n  \"best_validation__match/exact_match\": 0.3715686274509804,\n  \"best_validation_sql_match\": 0.47549019607843135,\n  \"best_validation__others/action_similarity\": 0.5731271471206189,\n  \"best_validation__match/match_single\": 0.6254612546125461,\n  \"best_validation__match/match_hard\": 0.3054393305439331,\n  \"best_validation_beam_hit\": 0.6070588235294118,\n  \"best_validation_loss\": 7.383035182952881\n  \"best_epoch\": 32\n```\n\nNote that the hyper-parameters used in `defaults.jsonnet` are different than those mentioned in the paper\n(most importantly, 3 timesteps are used instead of 2), thanks to the [following contribution from @wlhgtc](https://github.com/benbogin/spider-schema-gnn/pull/13).\nThe original training config file is still available in `train_configs/paper_Defaults.jsonnet`.\n\n## Inference\n\nUse the following AllenNLP command to output a file with the predicted queries:\n\n```\nallennlp predict experiments/name_of_experiment dataset/dev.json \\\n--predictor spider \\\n--use-dataset-reader \\\n--cuda-device=0 \\\n--output-file experiments/name_of_experiment/prediction.sql \\\n--silent \\\n--include-package models.semantic_parsing.spider_parser \\\n--include-package dataset_readers.spider \\\n--include-package predictors.spider_predictor \\\n--weights-file experiments/name_of_experiment/best.th \\\n-o \"{\\\"dataset_reader\\\":{\\\"keep_if_unparsable\\\":true}}\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenbogin%2Fspider-schema-gnn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenbogin%2Fspider-schema-gnn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenbogin%2Fspider-schema-gnn/lists"}