{"id":13432503,"url":"https://github.com/defog-ai/sqlcoder","last_synced_at":"2025-05-14T08:08:47.862Z","repository":{"id":189887567,"uuid":"679890936","full_name":"defog-ai/sqlcoder","owner":"defog-ai","description":"SoTA LLM for converting natural language questions to SQL queries","archived":false,"fork":false,"pushed_at":"2024-05-23T03:06:26.000Z","size":1462,"stargazers_count":3700,"open_issues_count":1,"forks_count":239,"subscribers_count":36,"default_branch":"main","last_synced_at":"2025-04-11T02:52:01.346Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/defog-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2023-08-17T21:19:32.000Z","updated_at":"2025-04-10T11:43:43.000Z","dependencies_parsed_at":"2023-11-14T18:46:49.101Z","dependency_job_id":"92839178-10c8-4ffd-8811-01bcaa6845c1","html_url":"https://github.com/defog-ai/sqlcoder","commit_stats":null,"previous_names":["defog-ai/sqlcoder"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/defog-ai%2Fsqlcoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/defog-ai%2Fsqlcoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/defog-ai%2Fsqlcoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/defog-ai%2Fsqlcoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/defog-ai","download_url":"https://codeload.github.com/defog-ai/sqlcoder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101558,"owners_count":22014908,"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-07-31T02:01:12.497Z","updated_at":"2025-05-14T08:08:46.648Z","avatar_url":"https://github.com/defog-ai.png","language":"Jupyter Notebook","readme":"# Defog SQLCoder\nDefog's SQLCoder is a family of state-of-the-art LLMs for converting natural language questions to SQL queries.\n\n[Interactive Demo](https://defog.ai/sqlcoder-demo/) | [🤗 HF Repo](https://huggingface.co/defog/llama-3-sqlcoder-8b) | [♾️ Colab](https://colab.research.google.com/drive/1z4rmOEiFkxkMiecAWeTUlPl0OmKgfEu7?usp=sharing) | [🐦 Twitter](https://twitter.com/defogdata)\n\n## TL;DR\nSQLCoder is a family of large language models that outperforms `gpt-4` and `gpt-4-turbo` for natural language to SQL generation tasks on our [sql-eval](https://github.com/defog-ai/sql-eval) framework, and significantly outperform all popular open-source models.\n\n![Percentage of correctly generated SQL queries on novel schemas not seen in training (n = 200), with 4 beams (2)](https://github.com/defog-ai/sqlcoder/assets/5008293/22b891db-2201-4b30-a52d-22376ba8ec86)\n\n\n## Installing SQLCoder\nIf running on a device with an NVIDIA GPU with more than 16GB VRAM (best performance)\n`pip install \"sqlcoder[transformers]\"`\n\nIf running on Apple Silicon (less good performance, because of quantization and lack of beam search)\n`CMAKE_ARGS=\"-DLLAMA_METAL=on\" pip install \"sqlcoder[llama-cpp]\"`\n\nIf running on a non-apple silicon computer without GPU access, please run this on Linux/Intel Mac\n`CMAKE_ARGS=\"-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS\" pip install \"sqlcoder[llama-cpp]\"`\n\nAnd run this on Windows\n```bash\n$env:CMAKE_ARGS = \"-DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS\"\npip install \"sqlcoder[llama-cpp]\"\n```\n\nSQLCoder has not been tested on other platforms yet. Contributions for testing on other platforms are very welcome!\n\n## Running SQLCoder\nIn your terminal, run\n`sqlcoder launch`\n\nWith this, you will be able to connect straight to your database, so you can add your metadata and query it visually.\n\n## License\nThe code in this repo (what little there is of it) is Apache-2 licensed. The model weights have a `CC BY-SA 4.0` license. The TL;DR is that you can use and modify the model for any purpose – including commercial use. However, if you modify the weights (for example, by fine-tuning), you must open-source your modified weights under the same license terms.\n\n## Training\nDefog was trained on more than 20,000 human-curated questions. These questions were based on 10 different schemas. None of the schemas in the training data were included in our evaluation framework. \n\nYou can read more about our [training approach](https://defog.ai/blog/open-sourcing-sqlcoder2-7b/) and [evaluation framework](https://defog.ai/blog/open-sourcing-sqleval/).\n\n## Results by question category\nWe classified each generated question into one of 6 categories. The table displays the percentage of questions answered correctly by each model, broken down by category.\n|                | date | group_by | order_by | ratio | join | where |\n| -------------- | ---- | -------- | -------- | ----- | ---- | ----- |\n| sqlcoder-70b   | 96   | 91.4     | 97.1     | 85.7  | 97.1 | 91.4  |\n| sqlcoder-7b-2  | 96   | 91.4     | 94.3     | 91.4  | 94.3 | 77.1  |\n| sqlcoder-34b   | 80   | 94.3     | 85.7     | 77.1  | 85.7 | 80    |\n| gpt-4          | 72   | 94.3     | 97.1     | 80    | 91.4 | 80    |\n| gpt-4-turbo    | 76   | 91.4     | 91.4     | 62.8  | 88.6 | 77.1  |\n| natural-sql-7b | 56   | 88.6     | 85.7     | 60    | 88.6 | 80    |\n| sqlcoder-7b    | 64   | 82.9     | 74.3     | 54.3  | 74.3 | 74.3  |\n| gpt-3.5        | 72   | 77.1     | 82.8     | 34.3  | 65.7 | 71.4  |\n| claude-2       | 52   | 71.4     | 74.3     | 57.1  | 65.7 | 62.9  |\n\n## Using SQLCoder\nYou can use SQLCoder via the `transformers` library by downloading our model weights from the Hugging Face repo. We have added sample code for [inference](./inference.py) on a [sample database schema](./metadata.sql). \n```bash\npython inference.py -q \"Question about the sample database goes here\"\n\n# Sample question:\n# Do we get more revenue from customers in New York compared to customers in San Francisco? Give me the total revenue for each city, and the difference between the two.\n```\n\nYou can also use a demo on our website [here](https://defog.ai/sqlcoder-demo)\n\n## Hardware Requirements\nSQLCoder-34B has been tested on a 4xA10 GPU with `float16` weights. You can also load an 8-bit and 4-bit quantized version of the model on consumer GPUs with 20GB or more of memory – like RTX 4090, RTX 3090, and Apple M2 Pro, M2 Max, or M2 Ultra Chips with 20GB or more of memory.\n\n## Todo\n\n- [x] Open-source the v1 model weights\n- [x] Train the model on more data, with higher data variance\n- [ ] Tune the model further with Reward Modelling and RLHF\n- [ ] Pretrain a model from scratch that specializes in SQL analysis\n\n## Star History\n\n[![Star History Chart](https://api.star-history.com/svg?repos=defog-ai/sqlcoder\u0026type=Date)](https://star-history.com/#defog-ai/sqlcoder\u0026Date)\n","funding_links":[],"categories":["AI Сервисы для разработки ПО","Jupyter Notebook","🔧 Practice Project","Papers","Tools \u0026 Frameworks"],"sub_categories":["Чат-боты","LLM-based models","Text2SQL"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefog-ai%2Fsqlcoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdefog-ai%2Fsqlcoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdefog-ai%2Fsqlcoder/lists"}