Spaces:
Sleeping
Sleeping
File size: 9,523 Bytes
abb02c0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | """
CoT Spatial Reasoning Degradation Demo
Based on: "Chain-of-Thought Degrades Visual Spatial Reasoning" (arXiv:2604.16060)
"""
import gradio as gr
from PIL import Image, ImageDraw
import random
def create_grid_puzzle():
"""Create a spatial grid puzzle"""
img = Image.new('RGB', (400, 400), color='white')
draw = ImageDraw.Draw(img)
# 3x3 grid with shapes
shapes = []
colors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA07A', '#98D8C8', '#F7DC6F']
for i in range(3):
for j in range(3):
x, y = 50 + j * 100, 50 + i * 100
color = colors[(i * 3 + j) % len(colors)]
# Draw shape
if (i + j) % 3 == 0:
draw.ellipse([x, y, x+60, y+60], fill=color, outline='black', width=2)
shape = "circle"
elif (i + j) % 3 == 1:
draw.rectangle([x, y, x+60, y+60], fill=color, outline='black', width=2)
shape = "square"
else:
draw.polygon([(x+30, y), (x+60, y+60), (x, y+60)], fill=color, outline='black', width=2)
shape = "triangle"
shapes.append({
"row": i + 1,
"col": j + 1,
"shape": shape,
"color": color
})
# Question about spatial relationship
target = shapes[4] # Center
question = f"What shape is in the center (row 2, column 2)?"
expected = target["shape"]
return img, question, expected
def create_rotation_puzzle():
"""Create mental rotation puzzle"""
img = Image.new('RGB', (500, 200), color='white')
draw = ImageDraw.Draw(img)
# Original L-shape
draw.rectangle([50, 50, 80, 110], fill='#3498DB', outline='black', width=2)
draw.rectangle([50, 80, 110, 110], fill='#3498DB', outline='black', width=2)
draw.text((60, 120), "Original", fill='black')
# Options
options = [
("90° rotation", [(150, 50, 180, 110), (150, 50, 210, 80)], 'red'),
("No rotation", [(250, 80, 280, 140), (250, 110, 310, 140)], 'green'),
("180° rotation", [(350, 90, 380, 150), (350, 120, 410, 150)], 'purple'),
]
for i, (label, rects, color) in enumerate(options):
x = 150 + i * 100
draw.rectangle([x, 50, x+30, 110], fill=color, outline='black', width=2)
draw.rectangle([x, 80, x+60, 110], fill=color, outline='black', width=2)
draw.text((x, 120), label, fill='black')
question = "Which shape shows the original rotated 90° clockwise?"
expected = "90° rotation"
return img, question, expected
def create_pattern_completion():
"""Create pattern completion puzzle"""
img = Image.new('RGB', (600, 150), color='white')
draw = ImageDraw.Draw(img)
# Pattern: circle, square, triangle repeating
pattern = [
('circle', '#E74C3C'),
('square', '#3498DB'),
('triangle', '#2ECC71'),
('circle', '#E74C3C'),
('square', '#3498DB'),
(None, 'white'), # Missing
]
for i, (shape, color) in enumerate(pattern):
x = 40 + i * 90
y = 40
if shape == 'circle':
draw.ellipse([x, y, x+50, y+50], fill=color, outline='black', width=2)
elif shape == 'square':
draw.rectangle([x, y, x+50, y+50], fill=color, outline='black', width=2)
elif shape == 'triangle':
draw.polygon([(x+25, y), (x+50, y+50), (x, y+50)], fill=color, outline='black', width=2)
else:
# Question mark
draw.rectangle([x, y, x+50, y+50], fill='#F8F9FA', outline='black', width=2)
draw.text((x+15, y+15), "?", fill='black', font=None)
question = "What shape completes the pattern?"
expected = "triangle"
return img, question, expected
def generate_cot_response(question, expected, use_cot):
"""Simulate model response with/without CoT"""
if not use_cot:
# Direct answer - often more accurate for spatial
if "center" in question and "shape" in question:
return "square"
elif "90°" in question:
return "red"
elif "pattern" in question:
return "green triangle"
else:
return expected
else:
# CoT with shortcut learning - may hallucinate
cot_thinking = """
Let me think step by step:
1. First, I need to analyze the visual elements
2. Looking at the pattern, there are geometric shapes
3. Based on common patterns in these types of puzzles...
4. The answer is likely what's most commonly seen
"""
# CoT sometimes gets confused
if random.random() < 0.3: # 30% degradation
if "center" in question:
return cot_thinking + "\nThe center shape is a **circle**"
elif "90°" in question:
return cot_thinking + "\nThe rotation is shown in **green**"
elif "pattern" in question:
return cot_thinking + "\nThe pattern completes with a **circle**"
else:
if "center" in question:
return cot_thinking + "\nThe center shape is a **square**"
elif "90°" in question:
return cot_thinking + "\nThe rotation is shown in **red**"
elif "pattern" in question:
return cot_thinking + "\nThe pattern completes with a **triangle**"
def run_comparison(puzzle_type):
"""Run CoT vs No-CoT comparison"""
if puzzle_type == "Spatial Grid":
img, question, expected = create_grid_puzzle()
elif puzzle_type == "Mental Rotation":
img, question, expected = create_rotation_puzzle()
else: # Pattern Completion
img, question, expected = create_pattern_completion()
# Get responses
no_cot_response = generate_cot_response(question, expected, False)
cot_response = generate_cot_response(question, expected, True)
# Check correctness
no_cot_correct = expected.lower() in no_cot_response.lower()
cot_correct = expected.lower() in cot_response.lower()
result = f"""
## {puzzle_type} Test Results
**Question:** {question}
**Expected Answer:** {expected}
### Without CoT (Direct):
{no_cot_response}
**Correct:** {'✅ YES' if no_cot_correct else '❌ NO'}
---
### With CoT (Step-by-step):
{cot_response}
**Correct:** {'✅ YES' if cot_correct else '❌ NO'}
---
### Analysis:
- **No-CoT Accuracy:** {'✅' if no_cot_correct else '❌'}
- **CoT Accuracy:** {'✅' if cot_correct else '❌'}
- **CoT Degradation:** {'❌ YES - CoT introduced errors' if (not cot_correct and no_cot_correct) else '✅ No degradation' if (cot_correct == no_cot_correct) else '⚠️ Mixed results'}
"""
return img, result
def show_paper_findings():
"""Display key findings from the paper"""
return """
## Key Findings from Paper (arXiv:2604.16060)
### Main Result
**"CoT prompting consistently degrades performance in visual spatial reasoning"**
### Evidence
- Evaluated **17 models** across **13 spatial benchmarks**
- Found systematic degradation with CoT prompting
- Identified shortcut learning from textual priors
### Root Cause
1. **Shortcut Learning:** Models rely on text patterns instead of visual analysis
2. **Hallucination:** Models generate visual details from text alone (No-Image++ ablation)
3. **Textual Prior Dominance:** Language priors override visual reasoning
### Implications
> "These findings challenge the efficacy of text-only CoT for spatial tasks and underscore the need for vision-centric reasoning paradigms."
### Recommendation
For spatial reasoning tasks:
- ❌ Avoid Chain-of-Thought prompting
- ✅ Use direct visual reasoning
- ✅ Develop vision-centric reasoning methods
"""
# Gradio Interface
demo = gr.Blocks(title="CoT Spatial Reasoning Degradation")
with demo:
gr.Markdown("""
# 🧠 CoT Degrades Spatial Reasoning
Interactive demonstration of findings from:
**"Chain-of-Thought Degrades Visual Spatial Reasoning Capabilities of Multimodal LLMs"**
**Core Claim:** CoT causes shortcut learning, degrading spatial reasoning performance.
""")
with gr.Tab("Live Comparison"):
with gr.Row():
with gr.Column():
puzzle_select = gr.Dropdown(
choices=["Spatial Grid", "Mental Rotation", "Pattern Completion"],
value="Spatial Grid",
label="Select Puzzle Type"
)
run_btn = gr.Button("Run Test", variant="primary")
with gr.Column():
puzzle_image = gr.Image(label="Puzzle", type="pil")
results_md = gr.Markdown()
run_btn.click(
fn=run_comparison,
inputs=[puzzle_select],
outputs=[puzzle_image, results_md]
)
with gr.Tab("Paper Findings"):
findings_btn = gr.Button("Show Findings", variant="secondary")
findings_md = gr.Markdown()
findings_btn.click(fn=show_paper_findings, outputs=[findings_md])
gr.Markdown("""
---
### 📄 Paper Reference
**Chain-of-Thought Degrades Visual Spatial Reasoning Capabilities of Multimodal LLMs**
Sai Srinivas Kancheti, Aditya Sanjiv Kanade, Vineeth N. Balasubramanian, Tanuja Ganu
*Microsoft Research*
arXiv:2604.16060
""")
if __name__ == "__main__":
demo.launch()
|