文件問答

善用 Hugging Face

Jacob H. Marquez

Lead Data Engineer

什麼是文件問答?

$$

  • 依文件內容回答問題
  • 需要一份文件與一個問題
  • 提供直接或意譯的答案

$$

Question: "What is the total revenue of Q3?"

一份文件

善用 Hugging Face

文件問答的應用情境

法務、財務與支援情境

$$

  • 📑 法務:辨識合約條款

$$

  • 💰 財務:擷取關鍵數字

$$

  • 🤓 支援:從手冊擷取答案
善用 Hugging Face

用文件問答自動化 HR 詢問

$$

  • 📄 資訊存於 US-Employee_Policy.pdf

$$

  • 🤖 建立系統自動擷取答案

$$

  • 🕑 節省 HR 的時間與心力

$$

HR 團隊超載

善用 Hugging Face

使用 pypdf 擷取文字

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...
善用 Hugging Face

建立 Q&A pipeline

# 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
善用 Hugging Face

整合重點

$$

  • 📄 使用 pypdfPdfReader 載入並讀取 PDF 檔
  • 🔎 以 .pages.extract_text() 擷取文字到 document_text
  • 🤔 設定 question-answering pipeline
  • ❓ 將 questioncontext 傳入 pipeline
  • ⏰ 包成函式以自動化查詢

文件問答

HR 團隊打造公司文化

善用 Hugging Face

一起來練習吧!

善用 Hugging Face

Preparing Video For Download...