-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.ipynb_checkpoints | ||
.DS_Store | ||
text-classifier/__pycache__ | ||
text-classifier/venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Neural Networks Programming | ||
# Machine Learning Programming | ||
|
||
1. [Linear Regression](https://github.com/jpuri/neural-networks/tree/main/linear-regression) | ||
2. [Shallow Neural Network](https://github.com/jpuri/neural-networks/tree/main/shallow-neural-network) | ||
3. [Deep Neural Network](https://github.com/jpuri/neural-networks/tree/main/deep-neural-network) | ||
4. [Text Classification](https://github.com/jpuri/neural-networks/tree/main/text-classifier) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Text Classification | ||
|
||
Project setup: | ||
|
||
```bash | ||
pip install -r requirements.txt | ||
python3 text_classifier.py | ||
``` | ||
|
||
Open url like: `http://0.0.0.0:8000/classify?text=This is a test sentence.` | ||
|
||
The api is deployed at: [https://text-classifier-na9p.onrender.com/classify?text=This is a test sentence](https://text-classifier-na9p.onrender.com/classify?text=This is a test sentence.). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
annotated-types==0.7.0 | ||
anyio==4.7.0 | ||
click==8.1.7 | ||
fastapi==0.115.6 | ||
h11==0.14.0 | ||
idna==3.10 | ||
joblib==1.4.2 | ||
nltk==3.9.1 | ||
pydantic==2.10.3 | ||
pydantic_core==2.27.1 | ||
regex==2024.11.6 | ||
sniffio==1.3.1 | ||
starlette==0.41.3 | ||
textblob==0.18.0.post0 | ||
tqdm==4.67.1 | ||
typing_extensions==4.12.2 | ||
uvicorn==0.32.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from fastapi import FastAPI | ||
from textblob import TextBlob | ||
from textblob.classifiers import NaiveBayesClassifier | ||
import nltk | ||
import uvicorn | ||
|
||
nltk.download('punkt') | ||
nltk.download('punkt_tab') | ||
|
||
data = [ | ||
('I love my country.', 'pos'), | ||
('This is an amazing place!', 'pos'), | ||
('I do not like the smell of this place.', 'neg'), | ||
('I do not like this restaurant', 'neg'), | ||
('I am tired of hearing your nonsense.', 'neg'), | ||
("I always aspire to be like him", 'pos'), | ||
("It's a horrible performance.", "neg") | ||
] | ||
|
||
model = NaiveBayesClassifier(data) | ||
|
||
app = FastAPI() | ||
|
||
@app.get("/classify") | ||
async def read_root(text: str): | ||
return { "class": model.classify(text) } | ||
|
||
if __name__ == "__main__": | ||
uvicorn.run("text_classifier:app", host="0.0.0.0", port=8000, reload=False) |