How mohanasrujana/message-analyser works
Project Type and Purpose
• The Message Analyzer is a data-driven application focused on analyzing conversations to identify crime-related elements, specifically murder-related. It leverages a modified Gemma:2B model, exported to ONNX format, for efficient inference using ONNXRuntime.
• The README clarifies that the system supports both a Command Line Interface (CLI) and a Flask-ML-based web API for deploying the model.
Analyzing the File Structure
• Major directories:
• data: Contains raw and processed conversation datasets along with supplementary files (e.g., CSVs, JSON, TXT files). This indicates an important data ingestion and preprocessing layer.
• models: Houses the ONNX model(s) (gemma-2b.onnx) that are used for inference.
• scripts: Contains various scripts including:
• API related files (cli.py, server.py, and documentation server_info.md) that serve as the entry points for CLI usage and Flask-ML API deployment.
• Model export and inference scripts (export_to_onnx.py, run_onnx_inference.py) which handle conversion from PyTorch to ONNX and perform inference.
• Jupyter notebooks for experimentation and further analysis.
• questions: Storage for conversation-related question files that likely balance or guide the analysis.
• test: Includes unit and integration tests ensuring the reliability of the model’s functionalities.
• Files like requirements.txt and .gitignore help manage dependencies and version control, while the README provides comprehensive usage and export instructions.
Key Architectural Components
a. Data Layer:
• Data Ingestion & Preprocessing: Represent the storage and processing of both raw and processed conversation datasets from the “data” directory. This layer feeds into the analysis module.
b. Model and Inference Layer:
• Model Export: Highlight the export_to_onnx.py script that converts the Gemma-2B model to ONNX format (placed in the “models” directory).
• ONNX Model Inference: Illustrate the run_onnx_inference.py script and the underlying ONNXRuntime used for efficient inference.
c. Interface Layer:
• Command Line Interface (CLI): Connect the CLI (scripts/api/cli.py) for users to interact with the inference capabilities directly.
• Flask-ML API: Represent the Flask-based server (scripts/api/server.py) which offers a RESTful API for handling requests (such as image uploads or CSVs containing conversation data) and returning predictions.
d. Infrastructure & Testing:
• Testing: Use the “test” directory to denote modules that validate model performance and API functionalities.
• External Dependencies: Emphasize that technologies such as ONNXRuntime, Python (>=3.8), and Flask-ML are part of the stack.
Relationships and Interactions
• Data flow beginning with input data (raw CSVs in the “data” folder) that is either preprocessed or directly passed into the analysis modules.
• Flow from the preprocessing/import scripts to the model export script which generates the ONNX model.
• The ONNX model is then used by the inference scripts (either via CLI or API) to analyze conversation data.
• Finally, output (results or predicted categories) is stored in the “results” folder and may be further reviewed or served back to the user.
Relevant Architectural Patterns & Design Principles
• Modular and Layered Design: Segregation between data processing, model inference, and client interfacing (CLI/API) ensures clarity and maintainability.
• Separation of Concerns: Different scripts and modules for preprocessing, model export, inference, and API deployment.
• Extensibility: The use of configuration files and modular Jupyter notebooks indicates areas designed for experimentation or future enhancement (e.g., improving prediction accuracy or implementing ONNX quantization).
Specific Elements
• Clear labels on each component such as “Raw Data (CSV)”, “Preprocessed Data”, “Model Export (export_to_onnx.py)”, “ONNX Model (gemma-2b.onnx)”, “ONNX Inference (run_onnx_inference.py)”, “CLI (cli.py)”, “Flask-ML API (server.py)”, and “Results.”
• Data ingestion → Preprocessing → Model Export → ONNX Model → Inference Scripts.