HumanPromptは、迅速な方法と迅速な方法の人間の設計、管理、共有、および使用を容易にするためのフレームワークです。研究者向けに特別に設計されています。まだ進行中ですか?メソッドとモジュールに関する新しい貢献を大いに歓迎します。ここで提案をご覧ください。
まず、このリポジトリをクローンし、次に実行します。
pip install -e .これにより、HumanPromptパッケージをインストールし、ソフトリンクハブを./humanprompt/artifacts/hubに追加します。
次に、Openai APIキーなどの環境変数を設定する必要があります。
export OPENAI_API_KEY = " YOUR_OPENAI_API_KEY "次に、このレポを使用する方法に依存します。今のところ、このリポジトリの使命は、研究者が自分のアイデアを検証するのを支援することです。したがって、拡張と使用を非常に柔軟にします。
メソッドを実行する最小限の例は次のとおりです。
私たちの使用法は非常に簡単です。以前にハギングフェイストランスを使用したことがある場合は、ほとんど似ています。
たとえば、CommonsenseQaで考えられたチェーンを使用してください。
from humanprompt . methods . auto . method_auto import AutoMethod
from humanprompt . tasks . dataset_loader import DatasetLoader
# Get one built-in method
method = AutoMethod . from_config ( method_name = "cot" )
# Get one dataset, select one example for demo
data = DatasetLoader . load_dataset ( dataset_name = "commonsense_qa" , dataset_split = "test" )
data_item = data [ 0 ]
# Adapt the raw data to the method's input format, (we will improve this part later)
data_item [ "context" ] = "Answer choices: {}" . format (
" " . join (
[
"({}) {}" . format ( label . lower (), text . lower ())
for label , text in zip (
data_item [ "choices" ][ "label" ], data_item [ "choices" ][ "text" ]
)
]
)
)
# Run the method
result = method . run ( data_item )
print ( result )
print ( data_item )ゼロショットtext2sql:
import os
from humanprompt . methods . auto . method_auto import AutoMethod
from humanprompt . tasks . dataset_loader import DatasetLoader
method = AutoMethod . from_config ( "db_text2sql" )
data = DatasetLoader . load_dataset ( dataset_name = "spider" , dataset_split = "validation" )
data_item = data [ 0 ]
data_item [ "db" ] = os . path . join (
data_item [ "db_path" ], data_item [ "db_id" ], data_item [ "db_id" ] + ".sqlite"
)
result = method . run ( data_item )
print ( result )
print ( data_item )特にさまざまなプロンプト方法をベンチマークする場合、研究を促進するために「1つの構成、1つの実験」パラダイムを採用します。 examples/configs/の下の各実験の構成ファイル(.yaml)で、データセット、プロンプトメソッド、およびメトリックを構成できます。
以下は、GSM8Kのチェーンオブテア検定方法の構成ファイルの例です。
---
dataset :
dataset_name : " gsm8k " # dataset name, aligned with huggingface dataset if loaded from it
dataset_split : " test " # dataset split
dataset_subset_name : " main " # dataset subset name, null if not used
dataset_key_map : # mapping original dataset keys to humanprompt task keys to unify the interface
question : " question "
answer : " answer "
method :
method_name : " cot " # method name to initialize the prompting method class
method_config_file_path : null # method config file path, null if not used(will be overriden by method_args).
method_args :
client_name : " openai " # LLM API client name, adopted from github.com/HazyResearch/manifest
transform : " cot.gsm8k.transform_cot_gsm8k.CoTGSM8KTransform " # user-defined transform class to build the prompts
extract : " cot.gsm8k.extract_cot_gsm8k.CoTGSM8KExtract " # user-defined extract class to extract the answers from output
extraction_regex : " .*The answer is (.*). n ? " # user-defined regex to extract the answer from output
prompt_file_path : " cot/gsm8k/prompt.txt " # prompt file path
max_tokens : 512 # max generated tokens
temperature : 0 # temperature for generated tokens
engine : code-davinci-002 # LLM engine
stop_sequence : " nn " # stop sequence for generation
metrics :
- " exact_match " # metrics to evaluate the resultsユーザーは、 transformクラスを作成してextract 、プロンプトの生成と回答抽出プロセスをカスタマイズできます。プロンプトファイルは、ユーザーのニーズに応じて交換または指定できます。
実験を実行するには、 examples/ディレクトリの下でコマンドラインで実験名とその他のメタ構成を指定できます。
たとえば、次のコマンドを実行して、GSM8Kでチェーンオブサベートを実行します。
python run_experiment.py
--exp_name cot-gsm8k
--num_test_samples 300メソッドとタスクの新しい組み合わせの場合、 examples/configs/の下に新しい構成ファイルを追加してコマンドを実行するだけです。
.
├── examples
│ ├── configs # config files for experiments
│ ├── main.py # one sample demo script
│ └── run_experiment.py # experiment script
├── hub # hub contains static files for methods and tasks
│ ├── cot # method Chain-of-Thought
│ │ ├── gsm8k # task GSM8K, containing prompt file and transform/extract classes, etc.
│ │ └── ...
│ ├── ama_prompting # method Ask Me Anything
│ ├── binder # method Binder
│ ├── db_text2sql # method text2sql
│ ├── react # method ReAct
│ ├── standard # method standard prompting
│ └── zero_shot_cot # method zero-shot Chain-of-Thought
├── humanprompt # humanprompt package, containing building blocks for the complete prompting pipeline
│ ├── artifacts
│ │ ├── artifact.py
│ │ └── hub
│ ├── components # key components for the prompting pipeline
│ │ ├── aggregate # aggregate classes to aggregate the answers
│ │ ├── extract # extract classes to extract the answers from output
│ │ ├── post_hoc.py # post-hoc processing
│ │ ├── prompt.py # prompt classes to build the prompts
│ │ ├── retrieve # retrieve classes to retrieve in-context examples
│ │ └── transform # transform classes to transform the raw data to the method's input format
│ ├── evaluators # evaluators
│ │ └── evaluator.py # evaluator class to evaluate the dataset results
│ ├── methods # prompting methods, usually one method is related to one paper
│ │ ├── ama_prompting # Ask Me Anything(https://arxiv.org/pdf/2210.02441.pdf)
│ │ ├── binder # Binder(https://arxiv.org/pdf/2210.02875.pdf)
│ │ └── ...
│ ├── tasks # dataset loading and preprocessing
│ │ ├── add_sub.py # AddSub dataset
│ │ ├── wikitq.py # WikiTableQuestions dataset
│ │ └── ...
│ ├── third_party # third party packages
│ └── utils # utils
│ ├── config_utils.py
│ └── integrations.py
└── tests # test scripts
├── conftest.py
├── test_datasetloader.py
└── test_method.py
このリポジトリは、研究者がさまざまな迅速な方法を簡単に使用し、簡単に操作できるように設計されています。拡張と使用を容易にするために多くの時間を費やしたので、このレポに貢献できることを願っています。
このフレームワークに方法を提供することに興味がある場合は、次のことができます。
humanprompt/methodsフォルダーに自分で追加します。そのためには、次の手順に従う必要があります。mainブランチからブランチを作成します。./humanprompt/methodsにコードを追加し、 ./humanprompt/methods/your_method_name methods/your_method_nameフォルダーにメソッドを追加します。./hub/your_method_nameでメソッドのハブを作成します。./hub/your_method_nameに./examplesフォルダーがあることを確認してください。./examplesの最小限のデモ。mainブランチにマージするには、PRが必要です。事前コミットを使用して、コードの品質を制御します。コミットする前に、以下のコードを実行してコードを確認し、問題を修正してください。
pip install pre-commit
pre-commit install # install all hooks
pre-commit run --all-files # trigger all hooks
git commit --no-verifyを使用してスキップし、後でそれを処理できるようにすることができます。
このリポジトリが役立つ場合は、プロジェクトを引用してマニフェストしてください。
@software { humanprompt ,
author = { Tianbao Xie and
Zhoujun Cheng and
Yiheng Xu and
Peng Shi and
Tao Yu } ,
title = { A framework for human-readable prompt-based method with large language models } ,
howpublished = { url{https://github.com/hkunlp/humanprompt} } ,
year = 2022 ,
month = October
} @misc { orr2022manifest ,
author = { Orr, Laurel } ,
title = { Manifest } ,
year = { 2022 } ,
publisher = { GitHub } ,
howpublished = { url{https://github.com/HazyResearch/manifest} } ,
}