Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

p208p2002/bert-question-answer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BERT QA

  • 基於BERT的問答模組
  • 自動滑窗,允許超長文本輸入

Usage

  • 安裝相依套件: pip install -r requirements.txt
  • release下載預訓練模型
  • 詳細用法見example.py
# init BertQA
bertQA = BertQA(model = model, tokenizer = tokenizer, device = device)
context="大同國小有三個職員,王大明是校長,張小美是秘書,陳小玉是總務長"

question = "誰是校長"
answer_results = bertQA.ask(context,question)
# score:2.17795 start_index:11(1.07034) end_index:13(1.10761) answer:王大明

question = "陳小玉的工作是什麼"
answer_results = bertQA.ask(context,question)
# score:2.07151 start_index:29(1.84568) end_index:31(0.22583) answer:總務長

Usage

  1. 確保已經安裝pytorch1.4+
  2. 安裝相依套件: pip install -r requirements.txt
  3. release下載預訓練模型
  4. 將下載的模型放到trained_model/
  5. 詳細用法見example.py