Skip to main content

A set of data tools in Python

Project description

demeterchain

透過retriever檢索文章
並從文章中萃取答案

Installation

Install via PyPI

pip install demeterchain

為了避免下載過多無用套件
使用時須根據自己的需求自行安裝其他套件

流程簡介

建立retriever流程

graph TD;
讀取本地文件-->分割文件;
分割文件-->建立retriever;

檢索流程

graph TD;
使用者輸入問題-->Hyde["(可省略)使用HyDE擴增問題"];
Hyde-->檢索相關文章;
檢索相關文章-->從每篇檢索到的文章尋找答案;
從每篇檢索到的文章尋找答案-->Summary["(可省略)摘要並統整所有答案"];
Summary-->回傳結果;

使用說明

使用examples/demo.ipynb進行簡單測試
使用examples/complete_demo.ipynb進行完整測試

功能介紹

此處並不會介紹全部功能
僅針對部分功能進行介紹

TextSplitter

將文檔進行分割

  • separator : 分割文檔時只能在遇到separator才進行分割,若不設定則會以長度進行分割
  • chunk_size : 預期的分割文檔長度,當使用separator時可能會有比chunk_size長或短的結果出現
  • chunk_overlap : 分割文檔之間重疊的長度

PyseriniBM25Retriever

使用Pyserini的bm25為基底的retriever
需安裝jdk11

sudo apt-get update
sudo apt-get install openjdk-11-jdk

與Pyserini, faiss-cpu

pip install pyserini==0.22.1 faiss-cpu==1.7.4

RankBM25Retriever

使用rank_bm25的BM25Okapi為基底的retriever
需安裝rank_bm25

pip install rank_bm25

QAModelConfig

設定讀取模型時的各種參數

  • model_name_or_path : str,本地路徑或huggingface上模型的路徑,建議使用"NchuNLP/taide-qa"
  • template : 建議直接參考examples/demo.ipynb
  • device_map : str,模型要放在甚麼裝置
  • dtype : str,模型讀取的型態,可使用float32, float16, bfloat16
  • quantize : str,量化模型,提供以下兩種選擇
    • bitsandbytes : 等同於load_in_8bit
    • bitsandbytes-nf4 : 等同於load_in_4bit並使用nf4
  • use_flash_attention : bool,是否啟用flash_attention_2,安裝方式
  • noanswer_str : 建議直接參考examples/demo.ipynb
  • noanswer_ids : 建議直接參考examples/demo.ipynb

QAConfig

設定檢索及回答問題時的各種參數

  • retrieve_k : int,retriever檢索的篇數
  • batch_size : int,模型同時處理的文章數量,請依照自身顯卡vram進行調整
  • max_length : int,模型所能接受的最大長度,請依照自身顯卡vram進行調整,預設為768
  • max_new_tokens : int,模型預測的最大長度
  • num_beams : int, 生成過程中的答案數量,用來提升解碼的精準度
  • answer_strategy : 如何決定一篇文章的答案
    • best : 模型預測的最佳結果
    • longest : 模型產生的答案中最長的一個

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

demeterchain-1.0.2.tar.gz (22.3 kB view hashes)

Uploaded Source

Built Distribution

demeterchain-1.0.2-py3-none-any.whl (28.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page