HumanPrompt เป็นกรอบสำหรับการออกแบบที่ง่ายขึ้นของมนุษย์ในวงจัดการจัดการการแบ่งปันและการใช้วิธีการที่รวดเร็วและรวดเร็ว มันถูกออกแบบมาเป็นพิเศษสำหรับนักวิจัย ยังอยู่ในระหว่างดำเนินการอยู่หรือไม่เรายินดีต้อนรับการมีส่วนร่วมใหม่เกี่ยวกับวิธีการและโมดูลใหม่ ตรวจสอบข้อเสนอของเราที่นี่
ประการแรกโคลน repo นี้จากนั้นเรียกใช้:
pip install -e . สิ่งนี้จะติดตั้งแพ็คเกจ HumanPrompt และเพิ่ม Soft Link Hub ไปที่ ./humanprompt/artifacts/hub humanprompt/artifacts/hub
จากนั้นคุณต้องตั้งค่าตัวแปรสภาพแวดล้อมบางอย่างเช่นคีย์ OpenAI API:
export OPENAI_API_KEY = " YOUR_OPENAI_API_KEY "จากนั้นขึ้นอยู่กับว่าคุณจะใช้ repo นี้อย่างไร สำหรับตอนนี้ภารกิจของ repo นี้คือการช่วยนักวิจัยในการตรวจสอบความคิดของพวกเขา ดังนั้นเราจึงทำให้ยืดหยุ่นและใช้งานได้จริงๆ
ตัวอย่างน้อยที่สุดในการเรียกใช้วิธีการดังนี้:
การใช้งานของเราค่อนข้างง่ายมันเกือบจะคล้ายกันถ้าคุณเคยใช้ Transformers HuggingFace มาก่อน
ตัวอย่างเช่นใช้โซ่แห่งความคิดบน PommonsenseQa:
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-shot 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 ) เราใช้กระบวนทัศน์ "One Config, One Experiment" เพื่ออำนวยความสะดวกในการวิจัยโดยเฉพาะอย่างยิ่งเมื่อทำการเปรียบเทียบวิธีการแจ้งเตือนที่แตกต่างกัน ในไฟล์กำหนดค่าของแต่ละการทดลอง (.yaml) ภายใต้ examples/configs/ คุณสามารถกำหนดค่าชุดข้อมูลวิธีการแจ้งเตือนและตัวชี้วัด
ต่อไปนี้เป็นตัวอย่างไฟล์ config สำหรับวิธีการห่วงโซ่ของ 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/ ไดเรกทอรี
ตัวอย่างเช่นรันคำสั่งต่อไปนี้เพื่อเรียกใช้ Chain-of-Though บน 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 methods และเพิ่มวิธีการของคุณลงในโฟลเดอร์ ./humanprompt/methods/your_method_name humanprompt/methods/your_method_name./hub/your_method_name your_method_name./examples ใน ./hub/your_method_name your_method_name เพื่อกำหนดค่าการใช้งานพื้นฐานวิธีนี้./examples สำหรับการทำงานและทดสอบวิธีการของคุณmainเราใช้ pre-commit เพื่อควบคุมคุณภาพของรหัส ก่อนที่คุณจะกระทำตรวจสอบให้แน่ใจว่าได้เรียกใช้รหัสด้านล่างเพื่อดูรหัสของคุณและแก้ไขปัญหา
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} } ,
}