Text Classification - Instructor
This tutorial showcases how to implement text classification tasks—specifically, single-label and multi-label classifications—using the OpenAI API, Python's enum module, and Pydantic models. Motivation Text classification is a common problem in many NLP applications, such as spam detection or support ticket categorization. The goal is to provide a systematic way to handle these cases using OpenAI's GPT models in combination with Python data structures. For single-label classification, we first define an enum for possible labels and a Pydantic model for the output. The function classify will perform the single-label classification. Let's run an example to see if it correctly identifies a spam message. For multi-label classification, we introduce a new enum class and a different Pydantic model to handle multiple labels. The function multi_classify is responsible for multi-label classification. Finally, we test the multi-label classification function using a sample support ticket.
Text Classification using OpenAI and Pydantic ¶ This tutorial showcases how to implement text classification tasks-specifically, single-label and multi-label classifications-using the OpenAI API and Pydantic models. For complete examples, check out our single classification and multi-label classification examples in the cookbook. Motivation Text classification is a common problem in many NLP applications, such as spam detection or support ticket categorization. The goal is to provide a systematic way to handle these cases using OpenAI's GPT models in combination with Python data structure
related reading
- GPT in 60 Lines of NumPy | Jay Modyjaykmody.com
- GitHub - brexhq/prompt-engineering: Tips and tricks for working with Large Language Models like OpenAI's GPT-4.github.com
- microgptkarpathy.github.io
- Let's build GPT: from scratch, in code, spelled out.youtube.com
- GitHub - 567-labs/instructor: structured outputs for llmsgithub.com
- Prompt engineering | OpenAI APIplatform.openai.com
- Cookbookcookbook.openai.com
- Synthetic data generation (Part 1)cookbook.openai.com
- How to Build End-to-End LLM Observability in FastAPI with OpenTelemetryfreecodecamp.org
- GitHub - guidance-ai/guidance: A guidance language for controlling large language models.github.com
- LangChain Tutorial in Python - Crash Course - Python Engineerpython-engineer.com
- [2203.02155] Training language models to follow instructions with human feedbackarxiv.org