nanoGentzen-v2 represents a major architectural, dataset, and tooling upgrade over v0.1, significantly improving search precision, rule classification, and natural language reasoning.
-
1. High-Accuracy Joint Policy-Value Engine:
- v2 trains the rule head, antecedent pivot head, and value estimator jointly on an expanded 400k transition dataset, boosting Top-1 action accuracy from 80.5% to 98.4%.
- The search engine now prunes branches whose value score indicates provable falsehood before expanding child nodes.
-
2. Natural Language Deductive Reasoning (parser.py):
- Added recursive parsing for English syllogisms, implication chains, negations, and compound connectives (
and, or, if...then, assuming).
- Normalizes non-standard modal verbs, question patterns, and Unicode logic symbols (
⊢, →, ⇒, ∧, ∨, ¬) into canonical Gentzen sequents.
-
3. Comprehensive Validation & Adversarial Suite:
- Variable Invariance (100%): Fully invariant to unseen proposition tokens (
Alpha, Beta, Gamma).
- Out-of-Distribution Depth (100%): Zero-shot extrapolation to 4–6 step implication chains.
- Adversarial Fallacy Rejection (100%): Rejects single-token corrupted near-miss fallacies (Affirming the Consequent, Broken Links) and classical non-constructive axioms (Peirce's Law, Law of Excluded Middle).
-
4. Complete Standalone Tooling:
example_usage.py: Self-contained script demonstrating programmatic loading via AutoModel and AutoTokenizer for both symbolic and natural language inputs.
cli.py: Interactive terminal REPL and batch file evaluator supporting single-line queries (-q) and test files (-f).
benchmarks.txt: 19-sample reference suite testing identity, depth chains, NLP syllogisms, classical non-theorems, and fallacies.
- Standardized 95-token vocabulary serialization (
vocab.json) and flat-namespace import resolution for Hugging Face Hub distribution.
1 [ Natural Language / Symbolic Input ]
2 │
3 ▼
4 ┌── parser.py: Propositional & Natural Language Compiler
5 │ • Compiles English syllogisms & implication chains into sequents
6 │ • Normalizes operators (Unicode symbols → ASCII turnstiles)
7 └───┬────────────────────────────────────────────────────────────
8 │ Sequent: Γ ⊢ Δ
9 ▼
10 ┌── search.py: Neural Proof Search Controller
11 │ • Queries Policy-Value Transformer for Rule, Pivot, and Value
12 │ • Prioritizes actions via Joint Policy: P(Rule) × P(Pivot)
13 │ • Prunes provably unprovable branches (Value < Threshold)
14 └───┬────────────────────────────────────────────────────────────
15 │ Candidate (Rule, Pivot)
16 ▼
17 ┌── kernel.py: Deterministic Gentzen LI Kernel
18 │ • apply_rule(seq, rule, idx): Decomposes goal into subgoals
19 │ • is_axiom(seq): Checks Identity (A ⊢ A) or Ex Falso (0 ⊢ Δ)
20 │ • verify_proof_tree(tree): Recursively certifies 100% soundness
21 └────────────────────────────────────────────────────────────────
To rigorously verify that the network learned genuine deduction rather than memorizing surface character patterns, the model is evaluated across four validation dimensions (implemented in validate_random and eval_bench):
1pip install torch safetensors huggingface_hub transformers
2
1import torch
2from transformers import AutoModel, AutoTokenizer
3from kernel import Sequent, Imp, Var, verify_proof_tree
4from search import NeuralProofSearch
5from parser import parse_natural_language
6
7device = "cuda" if torch.cuda.is_available() else "cpu"
8
9# 1. Load Model & Tokenizer
10model = AutoModel.from_pretrained("Sagicc/nanoGentzen-v2", trust_remote_code=True).to(device)
11tokenizer = AutoTokenizer.from_pretrained("Sagicc/nanoGentzen-v2", trust_remote_code=True)
12searcher = NeuralProofSearch(model, tokenizer, device=device)
13
14# 2. Example 1: Symbolic Transitivity [(P => Q), (Q => R) |- (P => R)]
15P, Q, R = Var("P"), Var("Q"), Var("R")
16seq1 = Sequent((Imp(P, Q), Imp(Q, R)), (Imp(P, R),))
17proof1 = searcher.prove(seq1, max_depth=8)
18print(f"Proof 1 Sound: {verify_proof_tree(proof1)}")
19
20# 3. Example 2: Natural Language Syllogism
21nl_prompt = "If it rains and it is windy, then power goes out. It rains. It is windy. Does power go out?"
22seq2, _ = parse_natural_language(nl_prompt)
23proof2 = searcher.prove(seq2, max_depth=8)
24print(f"Proof 2 Sound: {verify_proof_tree(proof2)}")
25
1# Start interactive shell
2python cli.py
3
4# Evaluate a single prompt
5python cli.py -q "Assuming A and B then C. A. B. Is C?"
6
7# Batch evaluate the included benchmark suite
8python cli.py -f benchmarks.txt
9