{"id":13856916,"url":"https://github.com/lettergram/sentence-classification","last_synced_at":"2026-01-23T20:20:25.430Z","repository":{"id":34020559,"uuid":"163911045","full_name":"lettergram/sentence-classification","owner":"lettergram","description":"Sentence Classifications with Neural Networks","archived":false,"fork":false,"pushed_at":"2023-03-25T00:56:05.000Z","size":109709,"stargazers_count":236,"open_issues_count":6,"forks_count":37,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-08-06T03:02:29.724Z","etag":null,"topics":["cnn","fasttext","hyperparameter-tuning","neural-network","rnn","sentence-classification"],"latest_commit_sha":null,"homepage":"https://austingwalters.com/neural-networks-to-production-from-an-engineer/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lettergram.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["LETTERGRAM"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-01-03T02:03:01.000Z","updated_at":"2024-07-04T20:56:43.000Z","dependencies_parsed_at":"2024-01-18T05:04:17.100Z","dependency_job_id":null,"html_url":"https://github.com/lettergram/sentence-classification","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/lettergram%2Fsentence-classification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lettergram%2Fsentence-classification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lettergram%2Fsentence-classification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lettergram%2Fsentence-classification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lettergram","download_url":"https://codeload.github.com/lettergram/sentence-classification/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225912406,"owners_count":17544165,"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":["cnn","fasttext","hyperparameter-tuning","neural-network","rnn","sentence-classification"],"created_at":"2024-08-05T03:01:18.684Z","updated_at":"2026-01-23T20:20:25.423Z","avatar_url":"https://github.com/lettergram.png","language":"Python","funding_links":["https://github.com/sponsors/LETTERGRAM"],"categories":["Python"],"sub_categories":[],"readme":"Sentence Classification\n======================\n\nThe goal of this project is to classify sentences, based on type:\n\n- Statement (Declarative Sentence)\n- Question (Interrogative Sentence)\n- Exclamation (Exclamatory Sentence)\n- Command (Imperative Sentence)\n\nEach of the above broad sentence categories can be expanded and can be made more indepth. The way these networks and scripts are designed it should be possible expand to classify other sentence types, provided the data is provided.\n\nThis was developed for applications at [Metacortex](https://metacortex.me) and is accompanied by a guide on building practical/applied neural networks on [austingwalters.com](https://austingwalters.com).\n\nPlease, feel free to add PRs to update, improve, and use freely!\n\n---------------------\n\n## To Install\n\n* Install CUDA and CuDNN if you have a GPU (on your system of choice)\n* Install requirements (on python 3, python 2.x *will not work*)\n\n```\npip3 install -r requirements.txt --user\n```\n\n## To execute:\n\nPretrained model:\n\n```\npython3 sentence_cnn_save.py models/cnn\n```\n\nTo build your own model:\n\n```\npython3 sentence_cnn_save.py models/\u003cmodel name\u003e\n```\n\nThe models/\u003cmodel name\u003e will load any pretrained model with said name, or retrain it.\n\nSee supplemental material for full guide.\n\n\n## Supplemental Material\n\nThis repository was created in conjunction with a guide titled [Neural Networks to Production, From an Engineer](https://austingwalters.com/neural-networks-to-production-from-an-engineer/).\n\nBelow is the guides table of contents:\n\n* [Acquiring \u0026 formatting data for deep learning applications](https://austingwalters.com/data-acquisition-and-formatting-for-deep-learning-applications/)\n* [Word embedding and data splitting](https://austingwalters.com/word-embedding-and-data-splitting/)\n* [Bag-of-words to classify sentence types (Dictionary)](https://austingwalters.com/bag-of-words-to-classify-sentence-types/)\n* [Classify sentences via a multilayer perceptron (MLP)](https://austingwalters.com/classify-sentences-via-a-multilayer-perceptron-mlp/)\n* [Classify sentences via a recurrent neural network (LSTM)](https://austingwalters.com/classify-sentences-via-a-recurrent-neural-network-lstm/)\n* [Convolutional neural networks to classify sentences (CNN)](https://austingwalters.com/convolutional-neural-networks-cnn-to-classify-sentences/)\n* [FastText for sentence classification (FastText)](https://austingwalters.com/fasttext-for-sentence-classification/)\n* [Hyperparameter tuning for sentence classification](https://austingwalters.com/hyperparameter-tuning-for-sentence-classification/)\n\nAdditional, (more complex models) are available in the *advanced_modeling* directory. Eventually, posts should come out of them.\n\n---------------------\n\n## Dataset\n\nThe dataset is created from parsing out the [SQuAD](https://rajpurkar.github.io/SQuAD-explorer/) dataset and combining it with the [SPAADIA](http://martinweisser.org/index.html#Amex_a) dataset. \n\nThe samples in the dataset:\n\n* Command 1111\n* Statement 80167\n* Question 131001\n\nNote: Questions in this case are only one sentence, statements are a single sentence or more. They are classified correctly, but don't include sentences prior to questions. \n\n## Results\n\nWith the above, we are able to get the following accuracy:\n\n| Model | Accuracy | Train Speed | Classification Speed |\n| -------- | ----------- | --------- | ----------------- |\n| Dict | 85% | **Fastest** | **Fastest** |\n| CNN | **97.80%** | Fast (185 μs/step) | Very Fast (35 μs/step) |\n| CNN (2-layer) | **99.33%** | Fast (210 μs/step) | **Very Fast (42 μs/step)** |\t\n| MLP | 95.5% | **Very Fast (60 μs/step)** | Very Fast (42 μs/step)|\n| FastText (1-gram)| 94.40% | Fast (83 μs/step) | **Very Fast (26 μs/step)** |\n| FastText (2-gram)| 95.59% | Fast (196 μs/step) | **Very Fast (26 μs/step)** |\n| RNN (LSTM) | 98.49% | Very Slow (7000 μs/step) | Very Slow (1000 μs/step)|\n| RNN (GRU) | **99.73%** | Very Slow (2000 μs/step) | Very Slow (1000 μs/step)|\n| CNN + LSTM | **99.55%** | Very Slow (3000 μs/step) | Very Slow (722 μs/step)|\n| CNN + GRU | **99.82%** | Very Slow (2000 μs/step) | Very Slow (591 μs/step)|\n| CNN + MLP | **99.75%** | Slow (1000 μs/step) | **Fast (97 μs/step)** |\t\n\nWith some hyperparameter tuning:\n\n| Model | Accuracy | Train Speed | Classification Speed |\n| -------- | ----------- | --------- | ----------------- |\n| Dict | 85% | **Fastest** | **Fastest** |\n| CNN | **99.40%** | Fast (200 μs/step) | **Very Fast (26 μs/step)** |\n| CNN (2-layer) | **99.33%** | Fast (210 μs/step) | **Very Fast (42 μs/step)** |\t\n| MLP | 95.5% | **Very Fast (60 μs/step)** | Very Fast (42 μs/step)|\n| FastText (1-gram)| 94.40% | Fast (117 μs/step) | **Very Fast (26 μs/step)** |\n| FastText (2-gram)| 95.59% | Fast (196 μs/step) | **Very Fast (26 μs/step)** |\n| RNN (LSTM) | 98.49% | Very Slow (7000 μs/step) | Very Slow (1000 μs/step)|\n| RNN (GRU) | **99.73%** | Very Slow (2000 μs/step) | Very Slow (1000 μs/step)|\n| CNN + LSTM | **99.55%** | Very Slow (3000 μs/step) | Very Slow (722 μs/step)|\n| CNN + GRU | **99.82%** | Very Slow (2000 μs/step) | Very Slow (340 μs/step)|\n| CNN + MLP | **99.75%** | Slow (1000 μs/step) | **Fast (97 μs/step)** |\t\n\n#### Computer Configuration:\n\n* GTX 1080\n* 32 Gb RAM\n* 8x 3.6 Ghz cores (AMD)\n* Arch Linux, up to date on 12/16/2018\n\n## CNN Hyperparameter tuning\n\n| Accuracy | Speed | Batch Size | Embedding Dims | Filters | Kernel | Hidden Dims | Epochs |\n|--------|------------|------|-----|-----|----|-----|---|\n| 99.40% | 26 μs/step |   64 |  75 | 100 |  5 | 350 | 7 |                        \n| 99.36% | 40 μs/step |   64 |  50 | 250 | 10 | 150 | 5 |                      \n| 99.33% | 25 μs/step |   64 |  75 |  75 |  5 | 350 | 5 |                      \n| 99.31% | 59 μs/step |   64 | 100 | 350 |  5 | 300 | 3 |                      \n| 99.29% | 25 μs/step |   64 |  50 | 100 |  7 | 350 | 5 |                      \n| 99.27% | 62 μs/step |   32 |  75 | 350 |  5 | 250 | 3 |                      \n| 99.25% | 25 μs/step |   64 |  75 | 100 |  3 | 350 | 5 |                      \n| 99.25% | 25 μs/step |   64 |  50 | 100 |  7 | 250 | 3 |                      \n| 99.24% | 53 μs/step |   64 |  75 | 350 | 10 | 250 | 3 |                      \n| 99.23% | 56 μs/step |   64 |  75 | 350 | 10 | 200 | 3 |                      \n| 99.18% | 36 μs/step |   64 |  50 | 250 |  5 | 300 | 5 |                       \n| 99.12% | 52 μs/step |   64 |  75 | 350 |  5 | 250 | 3 |                       \n| 99.11% | 22 μs/step |   64 |  50 |  75 |  5 | 300 | 4 |                       \n| 99.11% | 26 μs/step |   64 |  50 | 100 | 10 | 250 | 3 |                      \n| 99.04% | 62 μs/step |   32 |  75 | 350 |  5 | 350 | 3 |                      \n| 99.00% | 24 μs/step |   64 | 100 |  50 |  5 | 350 | 3 |                      \n| 99.00% | 52 μs/step |   64 |  75 | 350 |  5 | 350 | 3 |                      \n| 99.00% | 40 μs/step |   64 |  75 | 250 |  5 | 350 | 3 |                      \n| 98.84% | 50 μs/step |   64 |  50 | 350 | 10 | 150 | 3 |                      \n| 98.86% | 40 μs/step |   64 |  75 | 250 |  5 | 250 | 3 |\n| 98.79% | 26 μs/step |   64 |  50 | 100 | 10 | 150 | 3 |                      \n| 98.76% | 30 μs/step |  128 |  50 | 200 |  3 | 150 | 3 |                      \n| 98.66% | 31 μs/step |   64 |  50 | 150 | 10 | 150 | 3 |                      \n| 98.62% | 45 μs/step |  128 | 100 | 350 |  3 | 250 | 3 |                      \n| 98.17% | 19 μs/step |   64 |  75 |  50 |  3 | 350 | 6 |                      \n| 98.07% | 34 μs/step |  128 |  75 | 250 |  5 | 250 | 3 |                      \n| 98.06% | 45 μs/step |   64 |  75 | 350 |  3 | 250 | 3 |                      \n| 97.53% | 35 μs/step |  128 |  75 | 250 |  5 | 350 | 3 |                      \n| 96.10% | 32 μs/step |  128 |  75 | 250 |  3 | 350 | 3 | \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flettergram%2Fsentence-classification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flettergram%2Fsentence-classification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flettergram%2Fsentence-classification/lists"}