Text Classifier
Text Classifier learns to classify texts from examples you already have classified: emails marked as spam or not, reviews tagged as positive or negative, tickets assigned to a queue. It saves what it learned as a named model and then assigns a category to each new text, with the probability of each one.
It is useful when you have a history of texts that are already classified and you want new ones classified the same way, without writing rules. It does not need an AI model or credentials: everything happens inside NappAI.
When to use it
- Separate spam from the emails that need attention.
- Find out whether your customers’ reviews are positive, negative or neutral.
- Send each support ticket to its queue (support, sales, billing) based on how earlier tickets were assigned.
- Detect the intent of a message: buy, cancel, ask for information or complain.
- Sort documents by type: invoice, contract, CV.
How it works
The Operation field decides what the component does on each run:
- Train: learns from your classified examples and saves the classifier under the name in Model Name.
- Predict: applies a saved classifier to new texts.
- Evaluate: compares the categories a saved classifier proposes with the real categories of a set of examples and returns accuracy measures.
Trained classifiers are saved in your storage, in the Text classifiers section. From there you can download them, delete them or upload them to another environment (see Upload a trained model).
Configuration
The fields change with the chosen operation.
| Field | What it does |
|---|---|
| Operation (required) | Train, Predict or Evaluate. Default: Train. |
| Data | A list of data rows; connect it from a database query, an API call or a CSV. In Train (required), these are the examples: each row with the text and its correct category. In Evaluate (required), examples in the same format to measure accuracy. In Predict it is optional: connect it to classify many texts at once, with the same text column as in training. |
| Text | Predict only. A single text to classify, for example the body of an email that arrives through a webhook. If you fill it in, this text is used; if you leave it empty, the texts in Data are classified. |
| Model Name (required) | In Train, the name the classifier is saved under; a name with the date and time is suggested, and you can change it to something recognisable such as spam_v1. It cannot match a classifier you already have. In Predict and Evaluate, it is a dropdown with your trained classifiers; use the refresh button if you have just trained one. |
| Text Column (required in Train) | The name of the Data column that holds the text, for example body or comment. Type or drag it; it must match exactly, including upper and lower case. Predict and Evaluate use the column saved with the classifier. |
| Label Column (required in Train and Evaluate) | The name of the column that holds each row’s category, for example queue or sentiment. At least two different categories are needed. |
| Algorithm (required in Train) | The learning method: Logistic Regression (default, the balanced choice), Naive Bayes (very fast, though slightly less accurate) or Linear SVM (often more accurate with many examples, but slower to train). |
Advanced options
They only appear in Train.
| Field | What it does |
|---|---|
| Test Size | The share of the examples set aside to measure accuracy instead of being used for learning. Default: 0.2 (20%). With 0, everything is used for learning and nothing is set aside for measuring. |
| Max Vocabulary Size | The maximum number of different words the classifier takes into account. Default: 20,000. Raise it if you have many texts or texts in several languages; 0 means no limit. |
| Max N-gram Size | Whether it learns from single words or also from groups of words. With 1 (the default), single words; with 2, also pairs such as “free money”; with 3, also groups of three. Higher values can be more accurate, but training takes longer. |
Output
The Result output returns data you can connect to any component that works with data, for example a conditional router, a database or an agent.
- Train: a summary with the classifier name, the columns used, the number of examples, the categories it learned and the accuracy measures: the share of correct answers (
accuracy) and other quality measures (precision,recall,f1). - Predict: one row per text with the text (
text), the assigned category (prediction) and the probability of each category (probabilities). - Evaluate: the same accuracy measures, calculated on the examples you connected.
Example
The online shop Casa Olmo wants to route the messages from its contact form automatically:
- It exports the latest messages already handled, with the columns
messageanddepartment, and turns them into a list of data with CSV to Data List. - With Train, Text Column
message, Label Columndepartmentand Model Namecontact_v1, it trains the classifier. - In the flow that receives the form, another Text Classifier with Predict and the
contact_v1model receives the message in Text. The result gives the department and a router sends the message to the right inbox.
Good practices
- The more examples per category, the better. With few examples of a category, the classifier will recognise it less well.
- Evaluate with new examples, different from the ones you trained with, to know how accurate it really is.
- To retrain, use a new name (for example
v2) or delete the previous classifier from storage first: if the name already exists, training stops with an error so it is not overwritten. - If you do not have classified examples, use Laya, which decides from a question and the description of each answer, with no training.
Related components
- Laya: classification without previous examples, from a question.
- Predictive Model: predictions from table data.
- Data Conditional Router: to send each text down a different path depending on its category.