Bekerja dengan Hugging Face
Jacob H. Marquez
Lead Data Engineer
$$
$$
Pertanyaan: "Berapa total pendapatan Q3?"


$$
$$
$$
$$
US-Employee_Policy.pdf$$
$$
$$

from pypdf import PdfReader# Load the PDF file reader = PdfReader("US-Employee_Policy.pdf")# Extract text from all pages document_text = "" for page in reader.pages:document_text += page.extract_text()
Selamat datang di dokumen Kebijakan Karyawan AS...
# Load the question-answering pipeline qa_pipeline = pipeline( task="question-answering", model="distilbert-base-cased-distilled-squad")question = "Berapa hari relawan yang ditawarkan setiap tahun?"# Get the answer from the QA pipeline result = qa_pipeline(question=question, context=document_text)print(f"Answer: {result['answer']}")
Answer: 1
$$
PdfReader dari pypdf untuk memuat dan membaca PDF.pages dan .extract_text() ke document_textquestion-answeringquestion dan context ke pipeline

Bekerja dengan Hugging Face