HumanPrompt는 더 쉬운 인간-루프 디자인, 관리, 공유 및 신속하고 신속한 방법을 사용하기위한 프레임 워크입니다. 연구원을 위해 특별히 설계되었습니다. 아직 진행 중입니까?, 우리는 방법과 모듈에 대한 새로운 기여를 매우 환영합니다. 여기에서 제안서를 확인하십시오.
먼저이 리베르를 복제 한 다음 실행하십시오.
pip install -e . 이렇게하면 HumanPrompt 패키지를 설치하고 ./humanprompt/artifacts/hub 에 소프트 링크 허브를 추가합니다.
그런 다음 OpenAI API 키와 같은 환경 변수를 설정해야합니다.
export OPENAI_API_KEY = " YOUR_OPENAI_API_KEY "그런 다음이 저장소를 사용하는 방법에 따라 다릅니다. 현재로서는이 저장소의 사명이 연구원들이 아이디어를 확인하는 데 도움이되는 것입니다. 따라서 우리는 확장하고 사용하는 것이 정말 유연하게 만듭니다.
메소드를 실행하는 최소 예제는 다음과 같습니다.
우리의 사용법은 매우 간단합니다. 이전에 Huggingface Transformers를 사용한 경우 거의 비슷합니다.
예를 들어 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 )Zero-샷 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 ) 우리는 특히 다른 프롬프트 방법을 벤치마킹 할 때 연구를 용이하게하기 위해 "하나의 구성, 하나의 실험"패러다임을 채택합니다. 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 폴더에 메소드를 추가하십시오../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 사용하여 건너 뛰고 나중에 그것을 처리 할 수 있습니다.
이 repo가 유용하다고 생각되면 프로젝트를 인용하고 매니페스트하십시오.
@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} } ,
}