This project aims to revolutionize how IT support tickets are managed by automating the categorization process. In environments with a high volume of calls, manual classification becomes a bottleneck, consuming valuable team time and being prone to inconsistencies.
We developed a robust solution based on Artificial Intelligence (AI) and Natural Language Processing (NLP) to efficiently and accurately classify IT tickets in Portuguese.
- Optimize support team time.
- Improve consistency in ticket categorization.
- Provide insights into the most frequent types of problems.
- Demonstrate the practical application of NLP techniques on real-world data.
The classification methodology is divided into key stages:
-
Exploratory Data Analysis (EDA): The journey begins with an in-depth analysis of historical ticket data. This phase is crucial for identifying patterns, common word and phrase correlations, and understanding the nuances of the language used by users to describe their problems. This "data detective" work provides the foundation for creating the category dictionary.
-
N-gram Extraction: Based on the EDA, sequences of words (N-grams) that are strong indicators of specific categories (e.g., "laptop freezing", "internet not working", "reset password") are identified. These N-grams are mapped to their respective categories.
-
Semantic Embeddings with Sentence-Transformer: To go beyond exact N-gram matching, we use a Sentence-Transformer model (specifically trained for Brazilian Portuguese -
pt-br). This model transforms entire ticket phrases into numerical "vectors" (embeddings), which capture the semantic meaning and context of the phrase. -
Similarity Calculation and Category Suggestion: The ticket text vector is compared with the vectors of predefined categories (or reference N-grams). The category with the highest semantic similarity (calculated by metrics like cosine similarity) is suggested as the classification for the ticket.
-
Data Persistence: The categorization results (ticket ID, processed words, found N-grams, maximum similarity, and suggested category) are stored in a PostgreSQL database using SQLAlchemy for ORM management in Python.
- Python: Main programming language.
- Pandas: For data manipulation and analysis (especially in EDA and ticket loading).
- Sentence-Transformers: Library for generating semantic embeddings.
- SQLAlchemy: ORM (Object-Relational Mapper) in Python for database interaction.
- PostgreSQL: Relational database management system.
tqdm: For progress bars during large data processing.jsonandos: For configuration file management (N-gram dictionary).- Sequelize (JavaScript): Used for database migration management (if you maintain the JS migration structure).
Follow the steps below to set up and run the project on your machine:
-
Clone the Repository:
git clone [https://github.com/ffcro3/ticket-categorization-nlp-ptbr.git](https://github.com/ffcro3/ticket-categorization-nlp-ptbr.git) cd ticket-categorization-nlp-ptbr -
Create and Activate a Virtual Environment (Recommended):
python -m venv venv # On Windows: .\venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
-
Install Python Dependencies:
pip install -r requirements.txt
-
Database Environment Variables (.env): To securely manage your database credentials, create a file named
.envin the root directory of your project.Add the following variables to your
.envfile, replacing the placeholder values with your actual PostgreSQL credentials:DB_USER=your_database_user DB_PASSWORD=your_database_password DB_HOST=your_database_host DB_PORT=5432 DB_NAME=your_database_nameThese variables will be loaded automatically by the
python-dotenvlibrary in your Python scripts. -
PostgreSQL Configuration:
- Ensure you have a PostgreSQL server running.
- Create a database and a user with appropriate permissions for the project.
- Update the
DATABASE_URLvariable insrc/db_operations.py(or wherever you defined it) with your PostgreSQL credentials:DATABASE_URL = "postgresql://your_user:your_password@your_host:your_port/your_database"
-
Apply Database Migrations (Sequelize - if applicable):
- If you are using Sequelize to manage tables, ensure you have
sequelize-cliconfigured. - Execute the migrations to create the
ticketsandtickets_categorized_ticketstables:npx sequelize db:migrate
- Alternative (SQLAlchemy): If you prefer SQLAlchemy to create the tables, ensure that the
Base.metadata.create_all(engine)line is present and executed in your main Python script (main.pyordb_operations.py).
- If you are using Sequelize to manage tables, ensure you have
-
Prepare the N-gram Dictionary:
- The N-gram dictionary (
ngram_categories.json) is essential for classification. Ensure this file exists in theconfig/directory. - You can create it manually or use a Python script to save it (as we discussed previously).
- The N-gram dictionary (
To execute the categorization process:
-
Load your ticket data: Ensure your ticket data is available (e.g., in a Pandas DataFrame
dataInfoin yourngrams_data.pyscript). -
Run the main script:
python ngrams_data.py
The script will load the N-gram dictionary, process your tickets, and insert the categorized results into the PostgreSQL database.
Contributions are welcome! Feel free to open issues or pull requests.
This project is licensed under the [License Name, e.g., MIT License] - see the LICENSE.md file for details.