A classifier assigns an input to a predefined category. For text, that might mean labeling a movie review Positive or Negative, sorting an email into a custom folder, or deciding whether a comment is offensive. The categories must be clear before classification begins. section 4.2
A general-purpose language model needs more than the text alone. Give it the text to classify, the question it should answer, and the allowed labels. Relevant context and a few labeled examples can help clarify the task. Unlike a specialized classifier, an untuned model may respond with an analysis instead of a label if given only a review. section 1.3.2 section 9.10
Listing 1.1 Prompt for classifying a laptop review
We are considering product reviews for laptops. #1 For each review, output "satisfied" or "dissatisfied", depending on whether the customer is satisfied with the product or not. #2 Examples: This is a great laptop! I recommend everyone to buy it! satisfied #3 This laptop did not work. I had to return it. dissatisfied #4 The screen is too small and it takes too long to start. #5
The laptop-review prompt names the context, limits the output to “satisfied” or “dissatisfied,” shows two labeled examples, and ends with the review awaiting a label. section 1.3.2
To classify a collection of reviews with Python:
- Read a CSV file whose text column contains the reviews. section 4.2.5
- For each review, fill a prompt template and send the prompt to a language model. Treat its reply as a proposed class label. section 4.2.1 section 4.2.5
- Save the labels in a new class column, count the responses, and compare labels with known sentiments when available. section 4.2.5 section 4.2.6
Movie-review sentiment
A prompt can end with: “Is the sentiment positive or negative? Answer ("pos"/"neg"):”. Run it on each review rather than assuming every reply is correct. In a sample with known sentiments, comparing generated labels against ground truth reveals mistakes even when most labels agree. section 9.2 section 4.2.6
The same pattern can classify images: ask whether each fruit image shows a banana and retain those answered “Yes.” For text, a LangChain chain can connect the prompt template, chat model, and output parser. Fine-tuning offers another route: a model trained on review labels can classify from review text alone, though its results still need checking. section 6.2.3 section 10.2.3 section 9.10






























