이것은 실험/연구 프로젝트에 가깝습니다. 자체 평가에 의해 안내 된 "스텝 스페이스"(예 : 빔 검색, MCT 등)를 통한 자동 디렉싱 단계 및 검색을 위해 래퍼와 결합 된 프롬프트 파이프 라인을 구현합니다.
데이터-추출/답변-추출 코드 ( utils.py
및 answer_extraction.py
) 중 일부는 https://github.com/agi-edgerunners/plan-and-solve-prompting에서 수정되었습니다.
데이터 세트 참조 :
@misc{cobbe2021training,
title={Training Verifiers to Solve Math Word Problems},
author={Karl Cobbe and Vineet Kosaraju and Mohammad Bavarian and Mark Chen and Heewoo Jun and Lukasz Kaiser and Matthias Plappert and Jerry Tworek and Jacob Hilton and Reiichiro Nakano and Christopher Hesse and John Schulman},
year={2021},
eprint={2110.14168},
archivePrefix={arXiv},
primaryClass={cs.LG}}
@inproceedings{patel-etal-2021-nlp,
title = "Are {NLP} Models really able to Solve Simple Math Word Problems?",
author = "Patel, Arkil and
Bhattamishra, Satwik and
Goyal, Navin",
booktitle = "Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies",
month = jun,
year = "2021",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2021.naacl-main.168",
doi = "10.18653/v1/2021.naacl-main.168",
pages = "2080--2094",
abstract = "The problem of designing NLP solvers for math word problems (MWP) has seen sustained research activity and steady gains in the test accuracy. Since existing solvers achieve high performance on the benchmark datasets for elementary level MWPs containing one-unknown arithmetic word problems, such problems are often considered {``}solved{''} with the bulk of research attention moving to more complex MWPs. In this paper, we restrict our attention to English MWPs taught in grades four and lower. We provide strong evidence that the existing MWP solvers rely on shallow heuristics to achieve high performance on the benchmark datasets. To this end, we show that MWP solvers that do not have access to the question asked in the MWP can still solve a large fraction of MWPs. Similarly, models that treat MWPs as bag-of-words can also achieve surprisingly high accuracy. Further, we introduce a challenge dataset, SVAMP, created by applying carefully chosen variations over examples sampled from existing datasets. The best accuracy achieved by state-of-the-art models is substantially lower on SVAMP, thus showing that much remains to be done even for the simplest of the MWPs.",
}
@inproceedings{ling-etal-2017-program,
title = "Program Induction by Rationale Generation: Learning to Solve and Explain Algebraic Word Problems",
author = "Ling, Wang and
Yogatama, Dani and
Dyer, Chris and
Blunsom, Phil",
booktitle = "Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
month = jul,
year = "2017",
address = "Vancouver, Canada",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/P17-1015",
doi = "10.18653/v1/P17-1015",
pages = "158--167",
abstract = "Solving algebraic word problems requires executing a series of arithmetic operations{---}a program{---}to obtain a final answer. However, since programs can be arbitrarily complicated, inducing them directly from question-answer pairs is a formidable challenge. To make this task more feasible, we solve these problems by generating answer rationales, sequences of natural language and human-readable mathematical expressions that derive the final answer through a series of small steps. Although rationales do not explicitly specify programs, they provide a scaffolding for their structure via intermediate milestones. To evaluate our approach, we have created a new 100,000-sample dataset of questions, answers and rationales. Experimental results show that indirect supervision of program learning via answer rationales is a promising strategy for inducing arithmetic programs.",}
@inproceedings{talmor-etal-2019-commonsenseqa,
title = "{C}ommonsense{QA}: A Question Answering Challenge Targeting Commonsense Knowledge",
author = "Talmor, Alon and
Herzig, Jonathan and
Lourie, Nicholas and
Berant, Jonathan",
booktitle = "Proceedings of the 2019 Conference of the North {A}merican Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers)",
month = jun,
year = "2019",
address = "Minneapolis, Minnesota",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/N19-1421",
doi = "10.18653/v1/N19-1421",
pages = "4149--4158",
abstract = "When answering a question, people often draw upon their rich world knowledge in addition to the particular context. Recent work has focused primarily on answering questions given some relevant document or context, and required very little general background. To investigate question answering with prior knowledge, we present CommonsenseQA: a challenging new dataset for commonsense question answering. To capture common sense beyond associations, we extract from ConceptNet (Speer et al., 2017) multiple target concepts that have the same semantic relation to a single source concept. Crowd-workers are asked to author multiple-choice questions that mention the source concept and discriminate in turn between each of the target concepts. This encourages workers to create questions with complex semantics that often require prior knowledge. We create 12,247 questions through this procedure and demonstrate the difficulty of our task with a large number of strong baselines. Our best baseline is based on BERT-large (Devlin et al., 2018) and obtains 56{%} accuracy, well below human performance, which is 89{%}.",
}
@article{geva-etal-2021-aristotle,
title = "Did Aristotle Use a Laptop? A Question Answering Benchmark with Implicit Reasoning Strategies",
author = "Geva, Mor and
Khashabi, Daniel and
Segal, Elad and
Khot, Tushar and
Roth, Dan and
Berant, Jonathan",
journal = "Transactions of the Association for Computational Linguistics",
volume = "9",
year = "2021",
address = "Cambridge, MA",
publisher = "MIT Press",
url = "https://aclanthology.org/2021.tacl-1.21",
doi = "10.1162/tacl_a_00370",
pages = "346--361",
abstract = "A key limitation in current datasets for multi-hop reasoning is that the required steps for answering the question are mentioned in it explicitly. In this work, we introduce StrategyQA, a question answering (QA) benchmark where the required reasoning steps are implicit in the question, and should be inferred using a strategy. A fundamental challenge in this setup is how to elicit such creative questions from crowdsourcing workers, while covering a broad range of potential strategies. We propose a data collection procedure that combines term-based priming to inspire annotators, careful control over the annotator population, and adversarial filtering for eliminating reasoning shortcuts. Moreover, we annotate each question with (1) a decomposition into reasoning steps for answering it, and (2) Wikipedia paragraphs that contain the answers to each step. Overall, StrategyQA includes 2,780 examples, each consisting of a strategy question, its decomposition, and evidence paragraphs. Analysis shows that questions in StrategyQA are short, topic-diverse, and cover a wide range of strategies. Empirically, we show that humans perform well (87{%}) on this task, while our best baseline reaches an accuracy of ∼ 66{%}.",
}
requirements.txt
(Main Big 3 라이브러리는 껴안는 표면 Transformers, Vllm 및 Pytorch입니다. 나머지는 대부분 종속성입니다.)코드베이스는 주로 VLLM 호환 모델과 함께 작동하도록 설정됩니다.
model.py
에서 필요에 따라 모델 가중치 경로를 변경하십시오 (Generator 클래스의 생성자 참조). 로컬로 다운로드 한 체크 포인트 경로를 사용하므로 유사한 경로에서 체크 포인트를 다운로드하거나 경로를 변경하지 않으면 상자 밖으로 작동하지 않습니다.새 모델을 추가하려면 (VLLM Compatible) 다음을 수행하십시오.
model
옵션에 대해서는 argparser.py
에서 모델 이름을 추가하십시오.prompt.py
에서 해당 모델 이름에 대한 프롬프트 템플릿을 추가하십시오 (코드 파일 끝의 예제 참조) (선택 사항; 기본 프롬프트가 있지만 최적이 아닐 수도 있음).model.py
의 체크 포인트 경로와 연결하십시오 (예제는 해당 파일의 생성기 클래스의 생성자 참조).이것은 코드 실행을위한 일반적인 템플릿입니다.
python main.py --search_style=MultiSearch --model=LLAMA30_instruct --gpu_ids="0,1" --prompt_style=cot --dataset=gsm8k --reward_types=confidence+correctness
이것은 검색 안내에 대한 보상 함수 ( confidence+correctness
-아래 설명)를 사용하여 GSM8K
에 대한 검색 전략으로 MultiSearch
(아래 설명)를 사용하여 Zero-Shot Chain-of-Thought ( cot
) 프롬프트로 LLAMA 30B를 지시합니다. . 모델 가중치는 CUDA : 0 및 CUDA : 1 ( gpu_ids="0,1"
)에 분포됩니다.
다른 두드러진 주장 :
checkpoint
이전에 저장된 체크 포인트를로드하는 경우 true 설정 (체크 포인트가 자동으로 저장됨)SC
자기 일관성을 가능하게하도록 설정하십시오 [1]. search_style=none
인 경우에만 관련이 있습니다. 각 인수 및 기본값에 사용 가능한 옵션은 argparser.py
에서 찾을 수 있습니다.
logs/
에 실행 로그를 찾을 수 있습니다.
이 프로젝트에서 우리는 추론 단계 수준에서 다양한 검색 전략을 사용합니다 (각 추론 단계는 "게임의 단일 움직임"으로 간주됩니다). 이것은 또한 세대를 일련의 단계로 분해하는 방법에 대한 의문을 제기합니다. 이를 수행하는 한 가지 방법은 명확한 구조 (구문 분석 단계에 사용할 수 있음)가있는 임의의 프롬프트 템플릿을 작성한 다음 템플릿과 함께 몇 가지 샷 예제를 사용하여 모델을 프라이밍하여 구조를 따르는 것입니다. 그러나 여기서 나는 제로 샷 정권에 관심이 있습니다. 나는 특정한 방식으로 제로 샷 프롬프트 지침을 사용하여 다양한 형태의 자동 분해 단계를 촉진합니다. 아래에서는이 프로젝트에 사용 된 모든 신속한 스타일과 해당 분해 방법론에 대해 설명합니다.
cot
( Chain-of-thoughts )-표준 Zero-Shot COT 프롬프트를 사용하여 Let's think step by step.
[2]. 스텝 분해의 경우 n
(새 선)이 사용됩니다. 빈 새 라인 등을 올바르게 무시하기위한 몇 가지 추가 설정이 있습니다. 궁극적으로, 이것은 반드시 추론 단계를 분해하는 이상적인 방법은 아니며, COT 결과의 모든 새로운 라인이 완전한 추론 단계 일지는 않지만 제로 샷 방식으로 수행 할 수있는 기본 시작점입니다.
체인의 체인 단계 ( cot_step
)-이것은 제로 샷 코트의 간단한 확장입니다. Let's think step by step. Step 1:
. 이것은 번호가 매겨진 단계로 추론 체인을 구성하기 위해 언어 모델을 자동으로 실시합니다 (1 단계 : xyz step2 : ABC ...). 그런 다음이 구조는 분해 단계에 쉽게 사용할 수 있습니다.
PS+ ( ps
) - 이것은 제로 샷 계획이며 [3]에 소개 된 프롬프트 (PS+ 버전)입니다. 새로운 라인 분해는 cot
와 유사하게 사용됩니다.
Tabular-the-thoughts ( cot_tab
)-이것은 [4]- n|step|subquestion|process|result|n
에 도입 된 제로 샷 테이블 코트 프롬프트입니다. 구조화 된 표 형식 추론 단계를 생성하는 간단한 방법입니다. 우리는 Newline을 다시 분해하기 위해 Newline을 다시 사용하지만 Newline Decomposition이 여기에서 더 의미가 있기 전과 달리.
구조 ( struct
) -이 프롬프트는 위의 많은 프롬프트의 요소를 사용합니다. 솔루션/답변을 단계 및 변전소로 분해하는 상세한 지침을 제공합니다 (하위 제한 식별, 관련 사실 및 솔루션 포함). 이것은 고도로 구조화 된 결과를 생성하며 cot
와 유사한 구조에 따라 분해 될 수 있습니다. 프롬프트의 세부 사항은 prompt.py
에서 찾을 수 있으며 분해 코드는 node_transition.py
에서 찾을 수 있습니다.
struct minimal ( struct_min
) - 하나가 적은 substep을 가진 struct와 유사합니다. prompt.py
의 세부 사항. 이 변형을 실행하지 않았습니다. 버그가있을 수 있습니다.
prompt.py
수정하여 몇 가지 샷 프롬프트를 추가 할 수 있습니다.
모든 검색 코드는 Search/
에서 찾을 수 있습니다.
none
-이 방법은 표준 자동 회귀 탐욕 디코딩 외에 특정 검색 전략을 적용하지 않습니다. 이것은 여러 샘플링과의 자기 일관성을 위해 SC=True
와 결합 할 수 있습니다.MultiSearch
이 전략은 멀티 샘플링을 사용합니다. 그런 다음 사실 후에 각 샘플에 대한 보상 (각 분해 된 단계에 대한 축적 보상)이 생성됩니다. 보상은 나중에 설명 할 수있는 다양한 방법으로 투표 답변에 사용됩니다.MultiGreedy
-이 전략은 욕심 많은 검색을 사용하지만 단계 수준 ( none
과 달리). 모든 반복에서, 추론 단계의 역사 체인을 고려할 때, 모델은 몇 가지 k의 다음 추론 단계 후보를 생성합니다. 그런 다음 각 K 후보자에게 점수가 매겨집니다 (보상 할당). 그런 다음 최대 점수 후보가 선택됩니다. 이 전략은 초기 추론 단계의 여러 샘플에 병렬로 사용되며, 이는 자기 일관성에 사용될 수있는 여러 검색 결과로 이어집니다. 이 검색 전략은 Tree of Thought [5]의 DFS와 유사하지만 역 추적없이 생각할 수 있습니다.BeamSearch
이것은 위의 빔 검색 버전입니다. 구현은 [6]에서 영감을 받았다. 더욱이,이 방법은 사고의 나무에 사용 된 BFS 방법 (잘린 프론티어 포함)과 유사하다고 생각할 수있다 [5].DivBeamSearch
이것은 빔 검색과 동일하지만 형제 자매를 제한함으로써 세대의 다양성을 더욱 장려합니다. 각 반복에서 최대 m (m << 빔 크기 (I 사용)) 형제가 허용됩니다. 이 제한에 따라 모든 후보자를 선택한 후 빔 크기에 공간이있는 경우 잔류 후보자는 보상에 따라 추가됩니다. 이 아이디어는 [7]와 비슷하지만 우리는 페널티로 점수의 방정식을 엄격히 수정하지는 않지만 설명대로 더 많은 어려운 제약을 사용합니다.MCTS
이것은 몬테 카를로 트리 검색입니다. 구현은 여기서 대략 구조를 따릅니다. [8]에서 약간의 영감이 필요합니다.SPMCTS
이 구현 (반 평행 몬테 카를로 트리 검색)은 MCT를 조금 더 병렬화합니다. 한 번에 여러 개의 잎을 선택하고 한 번에 여러 경로를 롤아웃합니다. 따라서 순차적 반복이 줄어 듭니다. 최종 결과는 MCT와 비슷한 수의 샘플입니다. 그러나 구현은 계산적으로 동일하지 않으며 의도되지 않았습니다.참고 일부 방법은 이전 작업에서 영감을 얻은 반면, 해당 논문의 충실한 구현을 시도하지는 않습니다.
[6,8]와 유사하게 각 단계에 대한 보상은 자체 평가 및 단계 생성의 신뢰 (로그 프롭에 기초)에 따라 계산됩니다. 자체 평가 기술은 LLM을 사용하여 단계의 도움/정확성에 대해 다중 선택 질문 (MCQ)을 요청하여 자체 세대를 평가합니다 (자체 평가 질문은 rewards.py
에서 찾을 수 있음).
argparse.py
의 인수로 다양한 유형의 보상 유형과 콤보를 사용할 수 있습니다.
confidence
- 자신감 만 (로그 프롭 기반) 보상으로 만 사용합니다.correctness
- 단계 정확성 관련 MCQ의 답변 확률 만 보상으로 사용합니다.helpfulness
- 보상으로 단계의 답변 확률 만 사용합니다.both
- correctness
과 helpfulness
모두 사용합니다.confidence+correctness
- confidence
와 correctness
모두 사용합니다.confidence+helpfulness
- confidence
과 helpfulness
모두 사용합니다.confidence+both
- 모든 confidence
, correctness
및 helpfulness
사용합니다. NB : 신속한 Styles struct
및 struct-min
다른 규칙을 따릅니다. 그들은 세밀한 변위 구조를 가지고 있으며 그에 적합한 보상을 사용합니다. 하위 판결 식별 Substep은 (기술적으로는 정확하고 잘못된 추론 단계가 아니기 때문에) Helpfulness 관련 보상 만 사용하며 솔루션 단계는 정확성 관련 질문만을 사용합니다 (아마도 하위 문제 도움이 도움과 관련이 있기 때문입니다. 해결책).
자체 평가를 위해 다른 프롬프트와 다른 보상 유형에 사용되는 MCQ는 reward.py
에서 찾을 수 있습니다.
여러 유형의 답변 투표 메커니즘이 main.py
에서 동시에 구현되고 자동으로 추적됩니다 ( argparse.py
옵션과 관련이 없음). 그들은 다음과 같습니다.
Voted Answer
) - 단순한 다수의 투표 [1].Reward Voted Answer
) - 다수 투표와 유사하지만 각 투표의 가치는 보상입니다 ( Top K Reward Voted Answer
) - 상위 K를 선택하십시오 (K = 5를 사용) 최고 보상 답변을 선택한 다음 보상 투표를 적용하십시오. 이를 통해 잠재적으로 "나쁜"낮은 보상 답변을 필터링하여 잠재적으로 투표에 추가 할 수 있습니다.Max Reward Answer
in Logs) - 최대 보상으로 답변을 선택하십시오.node_transition.py
의 일부 측면을 조금 더 (특히 보상 계산) 병렬화하려고했지만 경험적 시간 비용은 큰 이점을 얻지 못했습니다.none
(현재 가장 빠른) 외에 검색 전략의 속도를 크게 높일 수 있습니다. 그러나 이것은 VLLM 및 Huggingface Transformers를 수정해야 할 수도 있습니다.[1] 자기 일관성은 언어 모델의 사고 추론을 향상시킵니다.
@inproceedings{
wang2023selfconsistency,
title={Self-Consistency Improves Chain of Thought Reasoning in Language Models},
author={Xuezhi Wang and Jason Wei and Dale Schuurmans and Quoc V Le and Ed H. Chi and Sharan Narang and Aakanksha Chowdhery and Denny Zhou},
booktitle={The Eleventh International Conference on Learning Representations },
year={2023},
url={https://openreview.net/forum?id=1PL1NIMMrw}
}
[2] 대형 언어 모델은 제로 샷 추론 자입니다
@inproceedings{NEURIPS2022_8bb0d291,
author = {Kojima, Takeshi and Gu, Shixiang (Shane) and Reid, Machel and Matsuo, Yutaka and Iwasawa, Yusuke},
booktitle = {Advances in Neural Information Processing Systems},
editor = {S. Koyejo and S. Mohamed and A. Agarwal and D. Belgrave and K. Cho and A. Oh},
pages = {22199--22213},
publisher = {Curran Associates, Inc.},
title = {Large Language Models are Zero-Shot Reasoners},
url = {https://proceedings.neurips.cc/paper_files/paper/2022/file/8bb0d291acd4acf06ef112099c16f326-Paper-Conference.pdf},
volume = {35},
year = {2022}
}
[3] Plan and-Solve Prompting : 대형 언어 모델에 의한 제로 샷 체인의 추론 개선
@inproceedings{wang-etal-2023-plan,
title = "Plan-and-Solve Prompting: Improving Zero-Shot Chain-of-Thought Reasoning by Large Language Models",
author = "Wang, Lei and
Xu, Wanyu and
Lan, Yihuai and
Hu, Zhiqiang and
Lan, Yunshi and
Lee, Roy Ka-Wei and
Lim, Ee-Peng",
booktitle = "Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
month = jul,
year = "2023",
address = "Toronto, Canada",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2023.acl-long.147",
pages = "2609--2634",
abstract = "Large language models (LLMs) have recently been shown to deliver impressive performance in various NLP tasks. To tackle multi-step reasoning tasks, Few-shot chain-of-thought (CoT) prompting includes a few manually crafted step-by-step reasoning demonstrations which enable LLMs to explicitly generate reasoning steps and improve their reasoning task accuracy. To eliminate the manual efforts, Zero-shot-CoT concatenates the target problem statement with {``}textit{Let{'}s think step by step}{''} as an input prompt to LLMs. Despite the success of Zero-shot-CoT, it still suffers from three pitfalls: calculation errors, missing-step errors, and semantic misunderstanding errors. To address the missing-step errors, we propose Plan-and-Solve (PS) Prompting. It consists of two components: first, devising a plan to divide the entire task into smaller subtasks, and then carrying out the subtasks according to the plan. To address the calculation errors and improve the quality of generated reasoning steps, we extend PS prompting with more detailed instructions and derive PS+ prompting. We evaluate our proposed prompting strategy on ten datasets across three reasoning problems. The experimental results over GPT-3 show that our proposed zero-shot prompting consistently outperforms Zero-shot-CoT across all datasets by a large margin, is comparable to or exceeds Zero-shot-Program-of-Thought Prompting, and has comparable performance with 8-shot CoT prompting on the math reasoning problem. The code can be found at https://github.com/AGI-Edgerunners/Plan-and-Solve-Prompting.",
}
[4] Tab-Cot : 제로 샷 표 형사 사슬
@inproceedings{ziqi-lu-2023-tab,
title = "Tab-{C}o{T}: Zero-shot Tabular Chain of Thought",
author = "Ziqi, Jin and
Lu, Wei",
booktitle = "Findings of the Association for Computational Linguistics: ACL 2023",
month = jul,
year = "2023",
address = "Toronto, Canada",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2023.findings-acl.651",
pages = "10259--10277",
abstract = "The chain-of-though (CoT) prompting methods were successful in various natural language processing (NLP) tasks thanks to their ability to unveil the underlying complex reasoning processes.Such reasoning processes typically exhibit highly structured steps.Recent efforts also started investigating methods to encourage more structured reasoning procedures to be captured (cite least to most).In this work, we propose Tab-CoT, a novel tabular-format CoT prompting method, which allows the complex reasoning process to be explicitly modeled in a highly structured manner.Despite its simplicity, we show that our approach is capable of performing reasoning across multiple dimensions (i.e., both rows and columns).We demonstrate our approach{'}s strong zero-shot and few-shot capabilities through extensive experiments on a range of reasoning tasks.",
}
[5] 사고의 나무 : 큰 언어 모델로 고의적 인 문제 해결
@misc{yao2023tree,
title={Tree of Thoughts: Deliberate Problem Solving with Large Language Models},
author={Shunyu Yao and Dian Yu and Jeffrey Zhao and Izhak Shafran and Thomas L. Griffiths and Yuan Cao and Karthik Narasimhan},
year={2023},
eprint={2305.10601},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
[6] 분해는 자기 평가 가이드 디코딩을 통한 추론을 향상시킨다
@misc{xie2023decomposition,
title={Decomposition Enhances Reasoning via Self-Evaluation Guided Decoding},
author={Yuxi Xie and Kenji Kawaguchi and Yiran Zhao and Xu Zhao and Min-Yen Kan and Junxian He and Qizhe Xie},
year={2023},
eprint={2305.00633},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
[7] 신경 생성을위한 단순하고 빠른 다양한 디코딩 알고리즘
@misc{li2016simple,
title={A Simple, Fast Diverse Decoding Algorithm for Neural Generation},
author={Jiwei Li and Will Monroe and Dan Jurafsky},
year={2016},
eprint={1611.08562},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
[8] 언어 모델과의 추론은 세계 모델과 함께 계획하고 있습니다.
@misc{hao2023reasoning,
title={Reasoning with Language Model is Planning with World Model},
author={Shibo Hao and Yi Gu and Haodi Ma and Joshua Jiahua Hong and Zhen Wang and Daisy Zhe Wang and Zhiting Hu},
year={2023},
eprint={2305.14992},
archivePrefix={arXiv},
primaryClass={cs.CL}
}