Hugging Face 활용하기
Jacob H. Marquez
Lead Data Engineer
$$
$$
질문: "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()
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로 로드합니다.pages, .extract_text()로 텍스트를 추출해 document_text에 저장question-answering 파이프라인 설정question과 context 전달

Hugging Face 활용하기