How saitejasrivilli/sentimentanalysis works
Project's Main Purpose and Type
• This is a full-stack web application focused on sentiment analysis. Its primary function is to receive user text input through an HTML interface and return a sentiment prediction using a PyTorch LSTM model (with attention and negation handling).
• The backend is built with FastAPI, and it deploys using Docker, indicating a production-ready, scalable design.
File Structure
• Top-level files: README.md (project description), main.py (likely the entry point for the FastAPI app), analyzer.py (probably contains the logic to preprocess input and run the sentiment analysis using the PyTorch models), and requirements.txt (dependency listing).
• Model Files: ‘sentiment_model_with_negations.pth’ and ‘sentiment_pytorch_model.pth’ represent the trained models.
• Templates Directory: Contains HTML files (form.html for user input and result.html to display outputs) that comprise the frontend.
Main Components to Illustrate
a. User Interface (Frontend):
• Web Browser: The client interacts with the application.
• HTML Templates: form.html and result.html serve as the input form and display page, respectively.
b. Backend Server:
• FastAPI Application (main.py): This is the primary entry point handling HTTP requests.
• Analyzer Module (analyzer.py): Contains the core sentiment analysis logic. It loads the PyTorch models from the .pth files and uses them to predict sentiment.
c. Inference Models:
• Two Model Files: Represent the underlying sentiment analysis techniques (one that handles negations explicitly).
d. (Optional) Deployment Infrastructure:
• Docker: Although not directly visible in the file tree, the README mentions Docker for deployment; include a container boundary that wraps the entire backend service.
Relationships and Interactions
• A typical flow begins when the user inputs text via the frontend form. The input is sent over HTTP (or AJAX) to an endpoint provided by the FastAPI backend.
• The FastAPI application (in main.py) then calls functions in analyzer.py to process the text, load the appropriate PyTorch LSTM models, and run inference.
• The resulting sentiment (Positive/Negative) is packaged into a response and rendered via result.html on the frontend.
• Dependencies such as PyTorch and FastAPI (as listed in requirements.txt) underpin these interactions.
Architectural Patterns and Design Principles
• Separation of their concerns is evident: the frontend (templates) is decoupled from the backend (business logic in analyzer.py and main.py).
• The structure aligns with a typical Model-View-Controller (MVC)-like pattern even if loosely implemented.
• Use of containerization via Docker ensures scalability and deployability.