A production-ready sentiment analysis API that classifies product reviews as positive, negative, or neutral.
A live demo can be found here: Demo
P.S. I hate front-end. Don't judge
You have two options to run the app: clone this Github repo or use Docker.
- Using Github
mkdir realy-discriptive-name-that-isnt-super-long
cd ./realy-discriptive-name-that-isnt-super-long
# Clone the project
git clone https://github.com/Niazi04/Farsi-Product-Sentiment-API.git .
# Once you've cloned the project, install dependencies:
# Use a virtual environment to avoid version conflicts
pip install -r requirements.txt
# Then run the app:
python app.py- Using docker
If you want to explore the notebooks, clone the repository via GitHub instead.
docker pull nastyhedgeh0g/farsi-product-sentiment-api:FirstStable
docker run -p 5000:5000 nastyhedgeh0g/farsi-product-sentiment-api:FirstStableTo use a different port:
docker run -p 8080:5000 nastyhedgeh0g/farsi-product-sentiment-api:FirstStableYou can simply test the app using curl or any http client
curl http://localhost:5000/healthExpected response code: 200 OK
Response body should look like:
{
"dependencies": {
"svm":"available",
"vectorizer":"available"
},
"model":"not loaded in memory",
"timestamp":"2026-02-14T19:50:58.760383+00:00"
}If either 'svm' or 'vectorizer' show "missing", it means they are not found in ./model directory.
Initially 'model' is not loaded in memory. Because I coded it that way. After your first POST request, it will be loaded in memory
💡 Tip: Use Postman, Insomnia, or a similar tool for sending Persian text, as terminals may not handle Unicode properly.
This is how your JSON body should look like:
{
"review": "گوشی واقعا عالی بود"
}Send a POST request to http://localhost:5000/predict
If all the previous steps were successfull, you should get a response like so:
{
"polarity": "positive",
"success": true
}After your first request, the model remains loaded in memory for faster subsequent responses.
Send a GET request to ./health endpoint and verify this.
The dataset used for training this sentiment analysis model is Pars-ABSA, a benchmark corpus for Persian aspect-based sentiment analysis.
- Name: Pars-ABSA
- Size: 10,002 samples (5,114 positive, 3,061 negative, 1,827 neutral)
- Language: Farsi (Persian)
Due to licensing and storage constraints, the full dataset is not included in this repository. However for testing purposes, I have included a sample csv file under 'pipeline/data/processed/sample.csv'
The data is already cleaned and processed and is ready to be fed into the already trained model (look at 'model' dir)
- Visit the original repository:
https://github.com/Titowak/Pars-ABSA - Download 'Pars-ABSA_xml.xml'
- Place the downloaded file in
pipline/data/raw/directory
@misc{ataei2019parsabsaaspectbasedsentimentanalysis,
title={Pars-ABSA: an Aspect-based Sentiment Analysis dataset for Persian},
author={Taha Shangipour Ataei and Kamyar Darvishi and Soroush Javdan and Behrouz Minaei-Bidgoli and Sauleh Eetemadi},
year={2019},
eprint={1908.01815},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/1908.01815}
}