Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 6: Neuro-Symbolic AI — Implementation

Open in Colab

A small neuro-symbolic system: a Sudoku whose clues are handwritten digits. Perception (a classifier, Chapter 8) reads the clues; constraints (Chapter 1’s search over valid grids) solve the puzzle. We compare reading first and reasoning second with deciding both jointly.

A Sudoku with Handwritten Clues

A 4×4 Sudoku uses the digits 1–4: each row, column and 2×2 box contains each digit once. Its clues are images of handwritten digits, slightly noisy, as if photographed. A classifier reads them; then we solve.

288 valid 4x4 Sudoku grids

Two ways to solve:

  • Perception, then reasoning: take the most likely digit of each clue, then find the grid consistent with those digits. One misread clue and the puzzle is wrong or impossible.

  • Joint: keep the reader’s probabilities, and choose the valid grid that maximises the product of the probabilities of its clue digits: arg⁡max⁡grid∑clueslog⁡P(digit in grid∣image)\arg\max_{\text{grid}} \sum_{\text{clues}} \log P(\text{digit in grid} \mid \text{image}). The constraints can then overrule an uncertain reading.

<Figure size 1000x150 with 8 Axes>
solution:
 [[3 2 4 1]
 [1 4 2 3]
 [4 1 3 2]
 [2 3 1 4]]
digit reading accuracy: 93.5%
clues all read correctly               59% of 300 puzzles
perception, then reasoning             59% of 300 puzzles
joint (probabilities + constraints)    95% of 300 puzzles

Each clue is read correctly about 93% of the time, but with 8 clues per puzzle about 4 puzzles in 10 contain at least one misread clue, and perception-then-reasoning fails on every one of them. Keeping the uncertainty and letting the constraints decide solves the large majority. This is the core neuro-symbolic lesson: neither part alone does as well as the two together.

Summary

  • Reading each clue on its own and then reasoning fails whenever a single clue is misread.

  • Keeping the classifier’s probabilities and choosing the valid grid that maximises them lets the constraints correct uncertain readings.