MLQ Academy: PDF to Q&A Assistant using Embeddings & GPT-3

In this video tutorial, we'll walk through a Colab notebook that shows you how to upload a PDF document and create a factual Q&A assistant based on the text using GPT-3.

a year ago   •   7 min read

By Peter Foy

In this video tutorial, we're going to walk through a Colab notebook that shows you how to upload a PDF document and create a factual Q&A assistant based on the text using GPT-3.

Specifically, we'll be using OpenAI Embeddings API to retrieve relevant document context to the user's question, and then the Completions API to answer the question with this information. As OpenAI highlights:

OpenAI’s text embeddings measure the relatedness of text strings. The distance between two vectors measures their relatedness. Small distances suggest high relatedness and large distances suggest low relatedness.

The steps we're going to walk through include:

  1. Installs, imports, and setting up our OpenAI API constants
  2. Upload the PDF, read the text, and prepare it for the Embeddings API
  3. Compute & load the document embeddings
  4. Calculate the document & query similarity to retrieve relevant context
  5. Construct a prompt that creates a factual Q&A bot with our user's question and relevant context from the PDF
  6. Answer the user's question with the Completions API

The Colab notebook is adapted from this OpenAI Cookbook on Question Answering using Embeddings and in future videos, I'll show you how you can take out of Colab and build a simple web app using Sstreamlit that allows users to upload their own documents and create question-answering assistants.

This content is only available to subscribers

Subscribe now and have access to all our stories, enjoy exclusive content and stay up to date with constant updates.

Sign up now

Spread the word

Keep reading