Implement Custom Search In GPT-3

Using General & Specific Search In GPT-3

Intent deprecation is front and center when examining GPT-3. There are four emerging approaches to the deprecation of intents. Then there is also the deprecation of the state machine. This is necessary to introduce a more flexible conversational flow.

In the general Q&A chatbot, not using any training data, you can see how GPT-3 fields questions. Notice how context is maintained vertically, and how users can ask questions referencing earlier context in the conversation.

One avenue to introduce flexibility to a call flow is a searchable knowledge base.

This is not something unique to a specific chatbot framework. NVIDIA Jarvis, which was released recently has integration examples to Wikipedia to serve as a knowledge base which can be searched. Other platforms like MindMeld, Rasa, Microsoft, IBM and more make provision for such functionality.

Obviously these systems vary in complexity and implementation complexity.

In this story we are taking a look at the ease with which GPT-3 can perform search task and to what extend it can be customized.

Custom Search Using Provided Documents

In the example below we are going to follow a two-step process where we are going to upload a data file and then have search results yielded based on this file.

{"text": "puppy A is happy", "metadata": "emotional state of puppy A"}{"text": "puppy B is sad", "metadata": "emotional state of puppy B"}

Our search file or document only has two lines, where we have a text entry, with meta data.

OpenAI is installed using pip. Python is used to mount a Google Drive and access the training file. The training process is initiated.

Next, we upload this file using the files API. After running pip install to install openai, you see the simplest possible way to upload search documents.

Perhaps only apart from cURL.

OpenAI is installed using pip.

Python is used to mount a Google Drive and access the training file.

The training process is initiated.

If something is wrong with your Python code, a 400 or 401 error will be returned.

A successful return message is shown here below.

Most importantly the file ID is given, which can be used to reference the search data.

The result of the file uploading and training process.

The result of the file uploading and training process.

Below, Python code to query the single word of “happy” while referencing our file ID.

Python code to query the single word of “happy” while referencing our file ID.

Python code to query the single word of “happy” while referencing our file ID.

You will see the result, specific to the document uploaded.

General Search With GPT-3

GPT-3 has a very powerful and simple interface for general question and answer conversations. More than that, the context of the conversation is managed exceptionally well.

As per the example at the start of this article, the questions is asked: “Who won the F1 title in 2000?

Subsequently the user can ask, “For which team did he drive?”.

And “who was his team member?”.

The context of the conversation is maintained, making the Q&A interface much more conversational than other Q&A systems. In general most Q&A solutions are focused on a single dialog turn conversation, retrieving a single dialog with relevant information.

This is not the case with GPT-3.

Below, a GPT-3 Search chatbot written in Python using 14 lines of code. Line 8 contains a string assigned to the variable called prompt, acts as the training data.

A GPT-3 Search chatbot written in Python in 14 lines of code. Line 8 with a string assigned to the variable called prompt acts as the training data

Below is the question posed to GPT-3.

Who won the F1 title in 2011?

This is the string of training data used for the chatbot. With “Q” denoting the questions and “A” the answer.

prompt="I am a highly intelligent question answering bot. If you ask me a question that is rooted in truth, I will give you the answer. If you ask me a question that is nonsense, trickery, or has no clear answer, I will respond with \"Unknown\".\n\nQ: What is human life expectancy in the United States?\nA: Human life expectancy in the United States is 78 years.\n\nQ: Who was president of the United States in 1955?\nA: Dwight D. Eisenhower was president of the United States in 1955.\n\nQ: Which party did he belong to?\nA: He belonged to the Republican Party.\n\nQ: What is the square root of banana?\nA: Unknown\n\nQ: How does a telescope work?\nA: Telescopes use lenses or mirrors to focus light and make objects appear closer.\n\nQ: Where were the 1992 Olympics held?\nA: The 1992 Olympics were held in Barcelona, Spain.\n\nQ: How many squigs are in a bonk?\nA: Unknown\n\nQ: Who won the F1 title in 2011?\nA:"

Conclusion

There are elements of GPT-3 which is mind-blowing, the text related tasks are super useful; summarization, simplification, theming, key word extraction etc.

Talking to the chatbot API is surreal. The NLG and contextual awareness are astounding. It is only once you start thinking of building a domain specific enterprise solution, and scaling, and abstraction, where the challenge start.

NLP/NLU, Chatbots, Voice, Conversational UI/UX, CX Designer, Developer, Ubiquitous User Interfaces. www.cobusgreyling.me