Classifying texts using OpenAI models
In this recipe, we will ask an OpenAI model to provide the classification of an input text. We will use the same BBC dataset from previous recipes.
Getting ready
To run this recipe, you will need to have the openai
package installed, provided as part of the poetry
environment, and the requirements.txt
file. You will also have to have an OpenAI API key. Paste it into the provided field in the file utilities notebook (https://github.com/PacktPublishing/Python-Natural-Language-Processing-Cookbook-Second-Edition/blob/main/util/file_utils.ipynb).
The notebook is located at https://github.com/PacktPublishing/Python-Natural-Language-Processing-Cookbook-Second-Edition/blob/main/Chapter04/4.6_openai_classification.ipynb.
Note
OpenAI frequently changes and retires existing models and introduces new ones. The model we use in this recipe, gpt-3.5-turbo
, might be obsolete by the time you read this. In this case, please check the OpenAI documentation...