Vote on the Answer, Not the Reasoning
Self-consistency samples several chain-of-thought paths for one question and keeps the answer most of them reach. The paths differ, so the vote is over each path's final answer, read out of free text first. Implement final_answer(text), which reads one path's answer, and vote(texts), which counts them.
- A number is an optional
-right before the first digit, digits that may be grouped in threes by commas (1,200is one number,2,3,5is three), and an optional decimal part (3.5). A full stop with no digit after it ends a sentence and is not part of the number. What surrounds the number, such as$,**orapples, is ignored. - An answer statement is
answer isoranswer:, in any case. When the text has one, the answer is the first number after the last statement. - Otherwise, or when no number follows the last statement, the answer is the last number in the text. A text with no number at all has no answer:
final_answerreturnsNone. - Write the answer one way, as a string: no commas, no trailing zeros after the decimal point, and no point when nothing is left after it.
$1,200.00,1200.0and1200all come back as"1200",0.50as"0.5", and100stays"100". vote(texts)returns(answer, count): the final answer the most texts share and how many share it. Texts with no answer are left out. On a tie, the answer that appears first intextswins. With no answers at all it returns(None, 0).
The catch. The last number in a path is often working, not the answer. "The answer is 16 apples, 2 fewer than the 18 she picked." ends on 18. A path that states its answer has said where to look; the last number decides only when no number follows a statement.