Aan de slagGa gratis aan de slag

Building a Q&A pipeline

In the previous exercise, we extracted text from a multi-page document using PyPDF and prepared it as a single string.

Now, you’ll build a question-answering pipeline using Hugging Face to retrieve specific answers from the document.

Both the pipeline module and document_text have been preloaded for you.

Deze oefening maakt deel uit van de cursus

Working with Hugging Face

Cursus bekijken

Oefeninstructies

  • Initialize a question-answering pipeline with the correct task and model.
  • Pass the question and document_text to the pipeline.
  • Print the result to view the answer.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Load the question-answering pipeline
qa_pipeline = pipeline(task="____", model="distilbert-base-cased-distilled-squad")

question = "What is the notice period for resignation?"

# Get the answer from the QA pipeline
result = qa_pipeline(question=____, context=____)

# Print the answer
print(f"Answer: {result['____']}")
Code bewerken en uitvoeren