Classifying text from keywords
Another common text classification task is to classify documents based on keywords. To do this, we can use GPT3 to create a list of keywords that will be related to the content of the document. However, GPT3 doesn't just extract keywords from the document. It determines keywords that are relevant based on the document content. Let's try an example.
In this example, we will use the completions endpoint to classify a document based on relevant keywords.
Node.js/JavaScript example
To create the keywords classifier example in Node.js/JavaScript
, follow these steps:
- Log in to replit.com and open your exploring-gpt3-node REPL.
- Create a new file –Â
chapter08/keywords-classifier.js
. - Add the following code to the beginning of the
keywords-classifier.js
file:const axios = require('axios'); const apiKey = process.env.OPENAI_API_KEY; const client = axios.create({ Â Â headers: { &apos...