HumanPrompt ist ein Rahmen für das einfachere Design, Verwalten, Teilen und Gebrauch von schnellen und schnellen Methoden in der Regel. Es ist speziell für Forscher konzipiert. Es ist noch im Gange? Wir begrüßen neue Beiträge zu Methoden und Modulen sehr. Schauen Sie sich unseren Vorschlag hier an.
Klonen Sie zuerst dieses Repo und rennen Sie dann:
pip install -e . Dadurch wird ein HumanPrompt -Paket installiert und weiche Link -Hub zu ./humanprompt/artifacts/hub hinzugefügt.
Dann müssen Sie einige Umgebungsvariablen wie OpenAI -API -Schlüssel einstellen:
export OPENAI_API_KEY = " YOUR_OPENAI_API_KEY "Dann hängt es davon ab, wie Sie dieses Repo verwenden werden. Derzeit ist es die Mission dieses Repos, Forschern bei der Überprüfung ihrer Ideen zu helfen. Daher machen wir es wirklich flexibel, zu erweitern und zu verwenden.
Ein minimales Beispiel zum Ausführen einer Methode ist wie folgt:
Unsere Nutzung ist recht einfach, es ist fast ähnlich, wenn Sie schon einmal Harmgingface -Transformatoren verwendet haben.
Verwenden Sie beispielsweise die Kette des Gedankens auf 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 )Null-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 ) Wir übernehmen "One Config, One Experiment" -Paradigma, um die Forschung zu erleichtern, insbesondere beim Benchmarking verschiedener Aufforderungmethoden. In der Konfigurationsdatei (.YAML) jedes Experiments unter examples/configs/ können Sie den Datensatz, die Anlaufmethode und die Metriken konfigurieren.
Im Folgenden finden Sie ein Konfigurationsdateibeispiel für die durchdachte Methode der Kette auf 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 Benutzer können die transform erstellen und extract , um den Prozess der Eingabeaufforderung zu erzeugen und zu beantworten. Die Eingabedatei kann entsprechend dem Bedarf des Benutzers ersetzt oder angegeben werden.
Um Experimente auszuführen, können Sie den Namen des Experiments und andere Meta -Konfigurationen in der Befehlszeile unter examples/ Verzeichnis angeben.
Führen Sie beispielsweise den folgenden Befehl aus, um auf GSM8K die Kette des Kindes auszuführen:
python run_experiment.py
--exp_name cot-gsm8k
--num_test_samples 300 Für eine neue Kombination von Methoden und Aufgaben können Sie einfach eine neue Konfigurationsdatei unter examples/configs/ hinzufügen und den Befehl ausführen.
.
├── 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
Dieses Repository ist so konzipiert, dass Forscher schnelle Verwendungen und einfache Manipulationen verschiedener Schnellmethoden geben. Wir haben viel Zeit damit verbracht, es einfach zu erweitern und zu verwenden. Wir hoffen, dass Sie zu diesem Repo beitragen können.
Wenn Sie daran interessiert sind, Ihre Methode in dieses Framework zu beitragen, können Sie:
humanprompt/methods hinzu. Dazu sollten Sie die folgenden Schritte ausführen:main , der Sie Methoden nennt../humanprompt/methods hinzu und fügen Sie Ihre Methode in ./humanprompt/methods/your_method_name -Ordner hinzu,./hub/your_method_name ,./examples Sie ./hub/your_method_name./examples für das Ausführen und Testen Ihrer Methode.main zu verschmelzen.Wir verwenden Pre-Commit, um die Qualität des Codes zu steuern. Stellen Sie vor dem Verpflegung den folgenden Code für Ihren Code aus und beheben Sie die Probleme.
pip install pre-commit
pre-commit install # install all hooks
pre-commit run --all-files # trigger all hooks
Sie können git commit --no-verify um zu überspringen und uns später zu ermöglichen.
Wenn Sie dieses Repo nützlich finden, zitieren Sie bitte unser Projekt und manifestieren:
@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} } ,
}