🌐 Interactive project page: ancorro.github.io/logic-expert — overview, fuzzy-logic calculator, routing simulator, and results.
A logic-augmented transformer pathway that routes token-level representations into fixed fuzzy logical operators (AND / OR / NOT) — or a straight-through estimator — so the network learns compositional structure as an architectural prior, rather than as an ensemble of expert networks.
At each backbone layer, hidden states are projected to a lower-dimensional Q / K space that a running logic state queries via cross-attention. Routed attention selects logical operators along either the intra-token (feature) axis or the inter-token (sequence) axis, and the final logic state is fused back into the backbone before classification — imposing a structured, interpretable composition over token features.
Author: Steven Cleasby-Mayeda — Oregon State University Paper (CVPR-style writeup):
logic/LaTeX_dir/latex/Logic_Expert.pdf
Result. With the rulebase in the input and 3 seeds per model, every variant reaches 0.93–0.94 on ProofWriter. The parallel branch with its fusion head beats the linear-head Baseline by +1.4 pp in every seed (SE 0.2), but the logic operators add nothing on top: routing does not beat the parameter-matched No-Gate Control (−1.3 pp for inter-token G=8). Details, per-run logs and the pre-registered protocol:
logic/docs/verification/VERIFICATION.md.
- Non-invasive logic stream — runs in parallel to a frozen / fine-tuned HuggingFace backbone (Llama 3.1 family supported); no changes to attention internals.
- Differentiable fuzzy AND / OR / NOT gates plus a straight-through-estimator (STE) variant for binary-style gating, controlled by a single config flag.
- Operator routing with dense softmax routing in training and top-k sparse routing at inference, plus a configurable temperature and a cutoff ablation mode.
- Two composition axes — intra-token (within a token's feature vector) vs. inter-token (across neighboring tokens) — each ablated under matched parameter budgets.
- Mechanistic diagnostics logged to W&B: routing entropy, fusion alpha, gate utilization, per-layer logic-state norms.
- Matched-budget baseline (
BaselineModel) so observed gains are attributable to the logic pathway rather than added capacity.
logic/
__init__.py # public re-exports (FusionMLP, LogicLayer, LogicStream, ...)
core/
logic_llama_model.py # full Llama-backed logic-augmented model
logic_stream.py # per-layer logic-state recurrence
logic_layer.py # routing + gate aggregation + state update
logic_projection.py # [B,S,H] -> [B,S,L] projection per layer
logic_cross_attn.py # layerwise cross-attention into logic space
logic_gates.py # fuzzy AND / OR / NOT + STE variants
routing.py # dense / top-k / cutoff routing module
fusion.py # residual fusion w/ learnable alpha
baseline_model.py # matched-budget baseline
no_gate_layer.py # ablation: same path, no gates
data_utils.py # ProofWriter / CoLA loaders
docs/
ARCHITECTURE.md # full design write-up
shape_flow.md # tensor shapes through the pipeline
results.md # ablation notes (gate vs. no-gate, LoRA, routing)
paper/run_configs/ # earlier single-seed YAML configs
notebooks/
V0_Eval.ipynb, V5_Eval.ipynb, V6_multi_eval.ipynb
# eval drivers used for the paper
logic_hf.ipynb # interactive walkthrough on a HF backbone
LaTeX_dir/latex/
Logic_Expert.pdf # paper
plots/ # paper figures (architecture, routing heatmap, ...)
requirements-logic.txt
Requires Python 3.10+ and a CUDA-capable GPU for the Llama 3.1 8B path.
# PyTorch matched to your CUDA version, e.g. CUDA 12.6:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu126
# Project deps:
pip install -r logic/requirements-logic.txtFor Llama 3.1 access you'll need a HuggingFace account with the gated-model agreement
accepted, and a token exposed via HF_TOKEN / huggingface_hub.login(...).
The cleanest entry point is logic/notebooks/logic_hf.ipynb,
which loads a backbone, wraps it with LogicLlamaModel, and exercises the gates,
routing, and fusion in isolation.
Programmatic use:
from logic.core.logic_llama_model import LogicLlamaModel
model = LogicLlamaModel.from_pretrained(
backbone_name="meta-llama/Llama-3.1-8B-Instruct",
num_labels=2,
logic_dim=64,
gate_mode="soft", # or "ste"
routing_train_mode="dense", # or "cutoff"
routing_temperature=1.0,
)
logits = model(input_ids, attention_mask=attention_mask).logitsThe paper's numbers come from the harness in
logic/scripts/verify/: pinned driver notebooks, a manifest built
from the W&B configs, Slurm array scripts, aggregate.py / make_tex_tables.py, which
regenerate every table from logic/docs/verification/results/raw/, and paper_figures.py,
which draws the paper's figures from the same files. See
VERIFICATION.md for the exact commands.
Earlier single-seed YAML configs under logic/docs/paper/run_configs/
contain matched base.yaml / logic.yaml pairs for the intra-token and inter-token
comparisons.
If you reference this work, please cite the paper:
@misc{cleasbymayeda2026logicexpert,
author = {Cleasby-Mayeda, Steven},
title = {Parallel Logic Expert with Operator Routing},
year = {2026},
note = {Course project, Oregon State University AI 535}
}MIT — see LICENSE.