Skip to content

feat(misc): Neural net in 30 lines of K - #501

Open
jamesrziggy wants to merge 1 commit into
anthropics:mainfrom
jamesrziggy:feat/kona-array-neural-net
Open

feat(misc): Neural net in 30 lines of K#501
jamesrziggy wants to merge 1 commit into
anthropics:mainfrom
jamesrziggy:feat/kona-array-neural-net

Conversation

@jamesrziggy

Copy link
Copy Markdown

Summary

A cookbook demonstrating Claude generating, explaining, and self-repairing neural network code in Kona (K3) — Arthur Whitney's array programming language.

  • Claude writes a complete XOR neural net (forward pass + backprop + training) in ~30 lines of K
  • If the generated code errors, a self-repair loop feeds the Kona error back to Claude for iterative fixing
  • Includes a hand-tested reference implementation verified on Kona (converges to >99% accuracy on XOR)

Why this is interesting

K has virtually zero presence in LLM training data compared to Python. The notation is so dense that W1 _dot\: xi replaces what would be a nested for-loop in most languages. This is a genuine stress test of Claude's ability to reason about unfamiliar, terse array languages — not just parrot Python.

Verified on hardware

The reference K code was tested and confirmed working on Kona running on Android/Termux (ARM64). Output:

XOR predictions:
0 0.0 -> ,0.003721189
0 1.0 -> ,0.9952888
1 0.0 -> ,0.9952321
1 1.0 -> ,0.006605917

Fun fact

This PR was written entirely from an Android phone running Termux + Claude Code. The K code was debugged live in a Kona REPL on the same phone. No laptop involved.

🤙 Second PR from the phone. First one was anthropics/courses#142.

🤖 Generated with Claude Code

Demonstrates Claude generating, explaining, and self-repairing code in
Kona (K3) — an array programming language with near-zero LLM training
data. Includes a hand-tested XOR reference implementation that trains
and converges on Android/Termux.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nidhishgajjar

Copy link
Copy Markdown

Orb Code Review (powered by GLM 5.1 on Orb Cloud)

New cookbook: Neural Net Inference in 30 Lines of K. A creative exploration of Claude's ability to generate code in the K array programming language.

Observations

1. Creative and educational (Positive)
This is a unique cookbook that tests Claude's capabilities in a niche language with sparse training data. The approach — provide a reference card, generate code, explain it, validate — is well-structured.

2. The K reference card pattern (Positive)
Providing a domain-specific reference card in the prompt is a great technique for getting quality output from Claude in specialized domains. This pattern is transferable to other niche languages/frameworks.

3. Subprocess execution of generated code (Medium)

result = subprocess.run(["k", k_file], capture_output=True, text=True, timeout=30)

Running AI-generated code via subprocess has inherent risks. While K is a relatively safe language (no filesystem access by default), the notebook should note this consideration. The 30-second timeout is a good safety measure.

4. F-string syntax issue (Bug)

messages=[{{"role": "user", "content": generation_prompt}}]

Double braces {{ inside an f-string are correct for literal braces, so this is fine. Though the readability is slightly affected.

Summary

Fun and educational cookbook that demonstrates both Claude's capabilities and the reference-card prompting technique. The K language angle makes it memorable.

Assessment: approve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants