Hugging Faceを使いこなす
Jacob H. Marquez
Lead Data Engineer
$$
$$
質問: 「第3四半期の総収益はいくらですか?」


$$
$$
$$
$$
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()
Welcome to the US Employee Policy document...
# Load the question-answering pipeline qa_pipeline = pipeline( task="question-answering", model="distilbert-base-cased-distilled-squad")question = "How many volunteer days are offered annually?"# Get the answer from the QA pipeline result = qa_pipeline(question=question, context=document_text)print(f"Answer: {result['answer']}")
Answer: 1
$$
pypdfからPdfReaderを使用してPDFファイルを読み込む.pagesと.extract_text()でテキストを抽出し、document_textへquestion-answeringパイプラインを設定するquestionとcontextを渡す

Hugging Faceを使いこなす