{"id":13754399,"url":"https://github.com/huybery/r2sql","last_synced_at":"2025-04-12T21:13:08.079Z","repository":{"id":60202607,"uuid":"326941267","full_name":"huybery/r2sql","owner":"huybery","description":":hot_pepper: R²SQL: \"Dynamic Hybrid Relation Network for Cross-Domain Context-Dependent Semantic Parsing.\" (AAAI 2021)","archived":false,"fork":false,"pushed_at":"2021-12-20T08:53:41.000Z","size":895,"stargazers_count":62,"open_issues_count":0,"forks_count":11,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-12T21:13:01.544Z","etag":null,"topics":["semantic-parsing","text2sql"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2101.01686","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/huybery.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}},"created_at":"2021-01-05T08:55:38.000Z","updated_at":"2025-01-27T19:50:59.000Z","dependencies_parsed_at":"2022-09-26T17:10:16.826Z","dependency_job_id":null,"html_url":"https://github.com/huybery/r2sql","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/huybery%2Fr2sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huybery%2Fr2sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huybery%2Fr2sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huybery%2Fr2sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huybery","download_url":"https://codeload.github.com/huybery/r2sql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631681,"owners_count":21136562,"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":["semantic-parsing","text2sql"],"created_at":"2024-08-03T09:01:58.312Z","updated_at":"2025-04-12T21:13:08.039Z","avatar_url":"https://github.com/huybery.png","language":"Python","readme":"# R²SQL\nThe PyTorch implementation of paper [Dynamic Hybrid Relation Network for Cross-Domain Context-Dependent Semantic Parsing.](https://arxiv.org/pdf/2101.01686) (AAAI 2021)\n\n\n## Requirements\nThe model is tested in python 3.6 with following requirements:\n```\ntorch==1.0.0\ntransformers==2.10.0\nsqlparse\npymysql\nprogressbar\nnltk\nnumpy\nsix\nspacy\n```\nAll experiments on SParC and CoSQL datasets were run on NVIDIA V100 GPU with 32GB GPU memory.\n* Tips: The 16GB GPU memory may appear out-of-memory error.\n\n## Setup\n\nThe SParC and CoSQL experiments in two different folders, you need to download different datasets from [[SParC](https://yale-lily.github.io/spider) | [CoSQL](https://yale-lily.github.io/cosql)] to the `{sparc|cosql}/data` folder separately.\nAnother related data file could be download from [EditSQL](https://github.com/ryanzhumich/editsql/tree/master/data).\nThen, download the database sqlite files from [[here](https://drive.google.com/file/d/1a828mkHcgyQCBgVla0jGxKJ58aV8RsYK/view?usp=sharing)] as `data/database`.\n\nDownload Pretrained BERT model from [[here](https://drive.google.com/file/d/1f_LEWVgrtZLRuoiExJa5fNzTS8-WcAX9/view?usp=sharing)] as `model/bert/data/annotated_wikisql_and_PyTorch_bert_param/pytorch_model_uncased_L-12_H-768_A-12.bin`.\n\nDownload Glove embeddings file (`glove.840B.300d.txt`) and change the `GLOVE_PATH` for your own path in all scripts. \n\nDownload Reranker models from [[SParC reranker](https://drive.google.com/file/d/1cA106xgSx6KeonOxD2sZ06Eolptxt_OG/view?usp=sharing) | [CoSQL reranker](https://drive.google.com/file/d/1UURYw15T6zORcYRTvP51MYkzaxNmvRIU/view?usp=sharing)] as `submit_models/reranker_roberta.pt`, besides the roberta-base model could download from [here](https://drive.google.com/file/d/1LkTe-Z0AFg2dAAWgUKuCLEhSmtW-CWXh/view?usp=sharing) for `./[sparc|cosql]/local_param/`.\n\n## Usage\n\nTrain the model from scratch.\n```bash\n./sparc_train.sh\n```\n\nTest the model for the concrete checkpoint:\n```bash\n./sparc_test.sh\n```\nthen the dev prediction file will be appeared in `results` folder, named like `save_%d_predictions.json`.\n\nGet the evaluation result from the prediction file:\n```bash\n./sparc_evaluate.sh\n```\nthe final result will be appeared in `results` folder, named `*.eval`.\n\nSimilarly, the CoSQL experiments could be reproduced in same way.\n\n---\n\nYou could download our trained checkpoint and results in here:\n\n* SParC: [[log](https://drive.google.com/file/d/19ySQ_4x3R-T0cML2uJQBaYI2EyTlPr1G/view?usp=sharing) | [results](https://drive.google.com/file/d/12-kTEnNJKKblPDx5UIz5W0lVvf_sWpyS/view?usp=sharing)]\n* CoSQL: [[log](https://drive.google.com/file/d/1QaxM8AUu3cQUXIZvCgoqW115tZCcEppl/view?usp=sharing) | [results](https://drive.google.com/file/d/1fCTRagV46gvEKU5XPje0Um69rMkEAztU/view?usp=sharing)]\n\n### Reranker\nIf your want train your own reranker model, you could download the training file from here:\n\n* SParC: [[reranker training data](https://drive.google.com/file/d/1XEiYUmDsVGouCO6NZS1yyMkUDxvWgCZ9/view?usp=sharing)]\n* CoSQL: [[reranker training data](https://drive.google.com/file/d/1mzjywnMiABOTHYC9BWOoUOn4HnokcX8i/view?usp=sharing)]\n\nThen you could train, test and predict it:\n\ntrain:\n```bash\npython -m reranker.main --train --batch_size 64 --epoches 50\n```\n\ntest:\n```bash\npython -m reranker.main --test --batch_size 64\n```\n\npredict:\n```bash\npython -m reranker.predict\n```\n\n\n## Improvements\nWe have improved the origin version (descripted in paper) and got more performance improvements :partying_face:!\n\nCompare with the origin version, we have made the following improvements：\n\n* add the self-ensemble strategy for prediction, which use different epoch checkpoint to get final result. In order to easily perform this strategy, we remove the task-related representation in Reranker module.\n* remove the decay function in DCRI, we find that DCRI is unstable with decay function, so we let DCRI degenerate into vanilla cross attention.\n* replace the BERT-based with RoBERTa-based model for Reranker module.\n\nThe final performance comparison on dev as follows:\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003e\u003c/th\u003e\n    \u003cth colspan=\"2\"\u003eSParC\u003c/th\u003e\n    \u003cth colspan=\"2\"\u003eCoSQL\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003c/td\u003e\n    \u003ctd\u003eQM\u003c/td\u003e\n    \u003ctd\u003eIM\u003c/td\u003e\n    \u003ctd\u003eQM\u003c/td\u003e\n    \u003ctd\u003eIM\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eEditSQL\u003c/td\u003e\n    \u003ctd\u003e47.2\u003c/td\u003e\n    \u003ctd\u003e29.5\u003c/td\u003e\n    \u003ctd\u003e39.9\u003c/td\u003e\n    \u003ctd\u003e12.3\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eR²SQL v1 (origin paper)\u003c/td\u003e\n    \u003ctd\u003e54.1\u003c/td\u003e\n    \u003ctd\u003e35.2\u003c/td\u003e\n    \u003ctd\u003e45.7\u003c/td\u003e\n    \u003ctd\u003e19.5\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eR²SQL v2 (this repo)\u003c/td\u003e\n    \u003ctd\u003e54.0\u003c/td\u003e\n    \u003ctd\u003e35.2\u003c/td\u003e\n    \u003ctd\u003e46.3\u003c/td\u003e\n    \u003ctd\u003e19.5\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eR²SQL v2 + ensemble \u003c/td\u003e\n    \u003ctd\u003e55.1\u003c/td\u003e\n    \u003ctd\u003e36.8\u003c/td\u003e\n    \u003ctd\u003e47.3\u003c/td\u003e\n    \u003ctd\u003e20.9\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n## Citation\nPlease star this repo and cite paper if you want to use it in your work.\n\n\n## Acknowledgments\nThis implementation is based on [\"Editing-Based SQL Query Generation for Cross-Domain Context-Dependent Questions\"](https://github.com/ryanzhumich/editsql) EMNLP 2019.\n\n","funding_links":[],"categories":["其他_NLP自然语言处理"],"sub_categories":["其他_文本生成、文本对话"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuybery%2Fr2sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuybery%2Fr2sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuybery%2Fr2sql/lists"}