This project aims to perform sentiment analysis using the BERT model and Transformers by Hugging Face. The project includes the following key components:
- Scraping data from Google Play
- Preprocessing the data
- Building and training a sentiment classifier
- Creating a REST API for sentiment analysis
-
Clone the repository:
git clone https://github.com/CruiseDevice/Sentiment-Analysis-using-BERT.git cd sentiment_analyzer
-
Install the required dependencies:
pip install -r requirements.txt
-
Download and prepare the pre-trained model: Ensure the best_model_state.bin is placed in the ./models directory or adjust the path in config.json.
To run the API, use the following command:
uvicorn sentiment_analyzer.api:app --reload
This will start the server on http://localhost:8000.
You can test the API endpoint using the following URL: http://localhost:8000/predict`
To predict the sentiment of a text, send a POST request with the following JSON body:
{
"text": "This app is a total waste of time!"
}
The API will respond with a JSON object containing the predicted sentiment, the confidence score, and the probabilities for each sentiment class:
{
"sentiment": "negative",
"confidence": 0.9952511787414551,
"probabilities": {
"negative": 0.9952511787414551,
"neutral": 0.0025495770387351513,
"positive": 0.002199336187914014
}
}