Skip to content

Commit

Permalink
Print most likely answer in self-consistency example
Browse files Browse the repository at this point in the history
Update self_consistency.py
  • Loading branch information
7flash authored and rlouf committed Feb 5, 2024
1 parent aa13d2b commit cb7f747
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion examples/self_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def few_shots(question, examples):
model = models.openai("gpt-3.5-turbo")
generator = outlines.generate.text(model)
prompt = few_shots(question, examples)
answers = generator(prompt, samples=100)
answers = generator(prompt, samples=10)

digits = []
for answer in answers:
Expand All @@ -73,3 +73,10 @@ def few_shots(question, examples):
unique_digits, counts = np.unique(digits, return_counts=True)
results = {d: c for d, c in zip(unique_digits, counts)}
print(results)

max_count = max(results.values())
answer_value = [key for key, value in results.items() if value == max_count][0]
total_count = sum(results.values())
print(
f"The most likely answer is {answer_value} ({max_count/total_count*100}% consensus)"
)

0 comments on commit cb7f747

Please sign in to comment.