Skip to content

oozan/sentiment-analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Advanced AI-Powered Sentiment Analysis App

Overview

This application leverages Go and Python to provide an advanced sentiment analysis API. It integrates a pre-trained machine learning model from Hugging Face to analyze text sentiment (Positive, Negative, or Neutral) and calculates confidence levels. Additionally, the app extracts significant keywords from the input text.


Features

  • ML-Based Sentiment Analysis: Utilizes a pre-trained DistilBERT model for accurate sentiment classification.
  • Confidence Scoring: Computes a confidence level for the sentiment classification.
  • Keyword Extraction: Extracts meaningful keywords from the input text.
  • Hybrid Architecture: Combines the speed and concurrency of Go with the ML capabilities of Python.

Architecture

  1. Go Backend:
    • Handles HTTP requests and response generation.
    • Sends text input to the Python ML service.
    • Extracts keywords using basic text processing.
  2. Python ML Service:
    • Hosts the sentiment analysis model using the Hugging Face transformers library.
    • Processes text input and returns sentiment predictions to the Go backend.

Prerequisites

  • Go: Version 1.18 or later.
  • Python: Version 3.7 or later.
  • Python Libraries:
    • flask
    • transformers

Set Up the Python ML Service

  1. Navigate to the python_service directory:
    cd python_service
  2. Install the required Python libraries:
    pip install -r requirements.txt
  3. Start the ML service:
    python ml_service.py
    The service will run on port 5000.

Set Up the Go Backend

  1. Navigate to the go_app directory:
    cd ../go_app
  2. Run the Go application:
    go run main.go
    The server will start on port 8080.

API Endpoints

POST /predict

Analyzes the sentiment of the input text.

Request

  • URL: http://localhost:8080/predict
  • Method: POST
  • Headers: Content-Type: application/json
  • Body:
    {
      "text": "I love coding with Go and Python!"
    }

Response

  • Example:
    {
      "text": "I love coding with Go and Python!",
      "sentiment": "POSITIVE",
      "confidence": 0.99,
      "keywords": ["love", "coding", "with", "Python"]
    }

How It Works

  1. Python ML Service:
    • Receives the input text.
    • Processes the text using the DistilBERT sentiment analysis model.
    • Returns the sentiment and confidence levels.
  2. Go Backend:
    • Sends the text to the Python ML service.
    • Extracts significant keywords from the text.
    • Combines results and returns them to the client.

Testing

Using curl

Send a POST request:

curl -X POST -H "Content-Type: application/json" -d '{"text": "I love this advanced AI app!"}' http://localhost:8080/predict

Using Postman

  1. Create a new POST request.
  2. Set the URL to http://localhost:8080/predict.
  3. Add a JSON body with the text field.
  4. Send the request and view the response.

Future Enhancements

  1. Docker Integration:
    • Containerize both the Go and Python services for easier deployment.
  2. Batch Processing:
    • Allow analysis of multiple text inputs in a single request.
  3. Advanced NLP:
    • Use libraries like spaCy for sophisticated keyword extraction.
  4. Multilingual Support:
    • Add models for other languages to expand the app's capabilities.

License

This project is licensed under the MIT License.


Contributions

Contributions are welcome! Feel free to open issues or submit pull requests to improve the application.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published