Package com.tnsai.reasoning
Class SelfConsistencyExecutor
java.lang.Object
com.tnsai.reasoning.SelfConsistencyExecutor
Self-Consistency reasoning executor.
Generates multiple reasoning paths for a given question and returns the consensus answer based on majority voting or other aggregation strategies.
This technique improves accuracy by sampling diverse reasoning chains and marginalizing over them to find the most consistent answer.
Research Reference
Based on "Self-Consistency Improves Chain of Thought Reasoning in Language Models" (Wang et al., 2022)
Usage
SelfConsistencyExecutor executor = SelfConsistencyExecutor.builder()
.llm(client)
.numPaths(5)
.aggregation(Aggregation.MAJORITY_VOTE)
.build();
ConsistencyResult result = executor.reason("What is 17 * 23?");
System.out.println(result.getConsensusAnswer()); // "391"
System.out.println(result.getConfidence()); // 0.8 (4/5 paths agreed)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for SelfConsistencyExecutor. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a new builder for SelfConsistencyExecutor.Executes self-consistency reasoning on the given question.
-
Method Details
-
builder
Creates a new builder for SelfConsistencyExecutor. -
reason
Executes self-consistency reasoning on the given question.- Parameters:
question- The question to reason about- Returns:
- The consistency result with consensus answer and confidence
-