Text Classification: Definition and Examples
Text classification is a natural language processing (NLP) technique that assigns one or more predefined categories to a given text.
Full definition
Text classification is one of the fundamental tasks of natural language processing (NLP). It involves analyzing a text — whether an email, customer review, article, or tweet — and automatically assigning it a label from a set of predefined categories. For example, classifying an email as "spam" or "not spam," or determining whether a comment expresses a positive, negative, or neutral sentiment.
Historically, text classification relied on statistical approaches such as Naive Bayes models or SVMs (support vector machines), which required significant feature engineering. With the advent of deep learning and language models like BERT, then large generative models (LLMs), text classification has undergone a revolution: it is now possible to classify texts with high precision using simply a well-crafted prompt, without training a specific model.
In the context of prompt engineering, text classification is one of the most common and accessible use cases. One can ask an LLM to classify a text by providing the desired categories directly in the prompt, using techniques such as zero-shot (without examples), few-shot (with a few examples), or chain-of-thought (by asking the model to explain its reasoning before deciding).
Practical applications are vast: content moderation, automatic routing of support tickets, sentiment analysis, document categorization, intent detection in chatbots, or automatic email sorting. The quality of classification depends heavily on the clarity of the defined categories and the precision of the instructions given in the prompt.
Etymology
The term comes from English "text" and "classification" (from Latin classificare, "to arrange by classes"). It appeared in the field of information retrieval in the 1960s-1970s, before becoming a pillar of modern NLP with the rise of machine learning in the 1990s.
Concrete examples
Sentiment analysis on customer reviews
Classify the following comment as POSITIVE, NEGATIVE, or NEUTRAL. Reply only with the label.
Comment: "The product arrived quickly but the quality really leaves something to be desired, very disappointed."
Classification:
Automatic routing of technical support tickets
You are a triage agent for customer service. Classify the following ticket into one of these categories: BILLING, TECHNICAL, DELIVERY, OTHER.
Ticket: "I can no longer log into my account since this morning's update."
Category:
Toxic content detection with multi-label classification
Analyze the following message and indicate which categories apply among: HARASSMENT, HATE_SPEECH, DISINFORMATION, NONE. Multiple categories may apply. Reply in JSON format.
Message: "These people don't deserve to live in our country."
Result:
Practical usage
In prompt engineering, text classification is implemented by clearly defining the possible categories in the prompt and asking the model to reply with the appropriate label. To improve accuracy, it is recommended to provide 2-3 examples (few-shot) and ask the model to briefly justify its choice before giving its final answer. Structuring the output in JSON format facilitates integration into automated pipelines.
Related concepts
FAQ
What is the difference between mono-label and multi-label classification?
Do I need to train a model to do text classification with an LLM?
How can I improve the accuracy of a classification by prompt?
See also
How to use this prompt
- Copy the prompt with the button above.
- Paste it into ChatGPT, Claude or your favorite AI assistant.
- Replace the bracketed variables with your details, then refine the result.
About Prompt Guide
Prompt Guide is a free library of 2500+ ready-to-use prompts for ChatGPT, Claude and other AIs, with guides to learn prompting and tools to build and optimize your own prompts.
More definitions
Thread Of Thought: Definition and Examples
Prompting technique that asks the model to unravel a continuous thread of reasoning by identifying and connecting relevant information from a long context.
Trustworthy AI: Definition and Examples
Trustworthy AI refers to artificial intelligence designed to be reliable, ethical, transparent, and respectful of fundamental rights.
Video Understanding: Definition and Examples
Ability of an AI model to analyze, interpret, and extract relevant information from video content, combining visual, temporal, and often audio understanding.
Vision RAG: Definition and Examples
Vision RAG is an extension of Retrieval-Augmented Generation that integrates visual documents (images, charts, scanned PDFs) into the search process.
World Model: Definition and Examples
A world model is an internal representation that an AI system builds of the external world, allowing it to simulate, predict, and reason about the consequences of its actions without having to execute them in reality.
Zero-Shot Prompting: Definition and Examples
Zero-shot prompting gives the AI an instruction without any examples. Discover when and how to use this technique.
Get new prompts every week
Join our newsletter.