Skip to content

Commit cc7129e

Browse files
committed
indirect reasoning
1 parent 7986b07 commit cc7129e

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2+
"indirect-reasoning": "Indirect Reasoning",
23
"physical-reasoning": "Physical Reasoning"
34
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Indirect Reasoning with LLMs
2+
3+
import { Tabs, Tab } from 'nextra/components'
4+
5+
## Background
6+
[Zhang et al. (2024)](https://arxiv.org/abs/2402.03667) recently proposed an indirect reasoning method to strengthen the reasoning power of LLMs. It employs the logic of contrapositives and contradictions to tackle IR tasks such as factual reasoning and mathematic proof. It consists of two key steps: 1) enhance the comprehensibility of LLMs by augmenting data and rules (i.e., logical equivalence of contrapositive), and 2) design prompt templates to stimulate LLMs to implement indirect reasoning based on proof by contradiction.
7+
8+
Experiments on LLMs like GPT-3.5-turbo and Gemini-pro show that the proposed method enhances the overall accuracy of factual reasoning by 27.33% and mathematic proof by 31.43% compared to traditional direct reasoning methods.
9+
10+
Below is an example of zero-shot template for proof-by-contradiction.
11+
12+
13+
## Prompt
14+
```
15+
If a+|a|=0, try to prove that a<0.
16+
17+
Step 1: List the conditions and questions in the original proposition.
18+
19+
Step 2: Merge the conditions listed in Step 1 into one. Define it as wj.
20+
21+
Step 3: Let us think it step by step. Please consider all possibilities. If the intersection between wj (defined in Step 2) and the negation of the question is not empty at least in one possibility, the original proposition is false. Otherwise, the original proposition is true.
22+
23+
Answer:
24+
```
25+
26+
## Code / API
27+
28+
<Tabs items={['GPT-4 (OpenAI)', 'Mixtral MoE 8x7B Instruct (Fireworks)']}>
29+
<Tab>
30+
31+
```python
32+
from openai import OpenAI
33+
client = OpenAI()
34+
35+
response = client.chat.completions.create(
36+
model="gpt-3.5-turbo",
37+
messages=[
38+
{
39+
"role": "user",
40+
"content": "If a+|a|=0, try to prove that a<0.\n\nStep 1: List the conditions and questions in the original proposition.\n\nStep 2: Merge the conditions listed in Step 1 into one. Define it as wj.\n\nStep 3: Let us think it step by step. Please consider all possibilities. If the intersection between wj (defined in Step 2) and the negation of the question is not empty at least in one possibility, the original proposition is false. Otherwise, the original proposition is true.\n\nAnswer:"
41+
}
42+
],
43+
temperature=0,
44+
max_tokens=1000,
45+
top_p=1,
46+
frequency_penalty=0,
47+
presence_penalty=0
48+
)
49+
```
50+
</Tab>
51+
52+
<Tab>
53+
```python
54+
import fireworks.client
55+
fireworks.client.api_key = "<FIREWORKS_API_KEY>"
56+
completion = fireworks.client.ChatCompletion.create(
57+
model="accounts/fireworks/models/mixtral-8x7b-instruct",
58+
messages=[
59+
{
60+
"role": "user",
61+
"content": "If a+|a|=0, try to prove that a<0.\n\nStep 1: List the conditions and questions in the original proposition.\n\nStep 2: Merge the conditions listed in Step 1 into one. Define it as wj.\n\nStep 3: Let us think it step by step. Please consider all possibilities. If the intersection between wj (defined in Step 2) and the negation of the question is not empty at least in one possibility, the original proposition is false. Otherwise, the original proposition is true.\n\nAnswer:",
62+
}
63+
],
64+
stop=["<|im_start|>","<|im_end|>","<|endoftext|>"],
65+
stream=True,
66+
n=1,
67+
top_p=1,
68+
top_k=40,
69+
presence_penalty=0,
70+
frequency_penalty=0,
71+
prompt_truncate_len=1024,
72+
context_length_exceeded_behavior="truncate",
73+
temperature=0.9,
74+
max_tokens=4000
75+
)
76+
```
77+
</Tab>
78+
79+
80+
</Tabs>
81+
82+
## Reference
83+
- [Large Language Models as an Indirect Reasoner: Contrapositive and Contradiction for Automated Reasoning](https://arxiv.org/abs/2402.03667) (06 February 2024)

0 commit comments

Comments
 (0)