Academic rewrite: full Method section (equations + notation) + pipeline figure
Browse files
README.md
CHANGED
|
@@ -22,8 +22,10 @@ maximum likelihood** β the marginal over *all* derivation trees, computed by a
|
|
| 22 |
inside dynamic program (log-semiring DP). No noise process, no adversary, no
|
| 23 |
ELBO, no token ordering.
|
| 24 |
|
| 25 |
-
The current release is **v0.1 at 64Γ64**: a proof-of-concept for the mechanism.
|
| 26 |
-
parameters on top of a frozen T5-base caption encoder.
|
|
|
|
|
|
|
| 27 |
|
| 28 |
<p align="center"><img src="samples.jpg" width="360" alt="SPRIG v0.1 samples"></p>
|
| 29 |
|
|
@@ -40,7 +42,157 @@ Because analysis and synthesis are the *same* grammar run in two directions, the
|
|
| 40 |
model can also **parse** a real image (infer its most likely derivation) β see
|
| 41 |
`parses.png`. This is the strongest, most novel capability and it works well.
|
| 42 |
|
| 43 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
| Gate | Target | Result | |
|
| 46 |
|---|---|---|---|
|
|
@@ -54,12 +206,12 @@ model can also **parse** a real image (infer its most likely derivation) β see
|
|
| 54 |
| Compositional holdout (unseen combos) | β₯ 0.60 | 0.01 | β |
|
| 55 |
| Grammar health (S_eff / alive texels) | β₯256 / β₯50% | 968 / 43% | β οΈ texels over-pruned |
|
| 56 |
|
| 57 |
-
The architecture's structural claims prove out: it models
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
|
| 64 |
## Usage
|
| 65 |
|
|
@@ -85,6 +237,7 @@ was drawn.
|
|
| 85 |
- `config.json` β architecture config + release metadata
|
| 86 |
- `inference.py` β minimal load + sample + T5 caption encoding
|
| 87 |
- `metrics.json` β full evaluation numbers
|
|
|
|
| 88 |
- `samples.jpg`, `texel_atlas.png`, `parses.png` β qualitative outputs
|
| 89 |
- `DESIGN.md` β the concrete v0.1 architecture specification
|
| 90 |
|
|
|
|
| 22 |
inside dynamic program (log-semiring DP). No noise process, no adversary, no
|
| 23 |
ELBO, no token ordering.
|
| 24 |
|
| 25 |
+
The current release is **v0.1 at 64Γ64**: a proof-of-concept for the mechanism.
|
| 26 |
+
~16M trainable parameters on top of a frozen T5-base caption encoder.
|
| 27 |
+
|
| 28 |
+
<p align="center"><img src="figures/pipeline.png" width="820" alt="SPRIG pipeline: caption β grammar modulation β top-down derivation β texel rendering β image"></p>
|
| 29 |
|
| 30 |
<p align="center"><img src="samples.jpg" width="360" alt="SPRIG v0.1 samples"></p>
|
| 31 |
|
|
|
|
| 42 |
model can also **parse** a real image (infer its most likely derivation) β see
|
| 43 |
`parses.png`. This is the strongest, most novel capability and it works well.
|
| 44 |
|
| 45 |
+
## Method
|
| 46 |
+
|
| 47 |
+
### Formal object
|
| 48 |
+
|
| 49 |
+
SPRIG defines the conditional image distribution as a **text-modulated
|
| 50 |
+
probabilistic context-free scene grammar** $G_c = (\Sigma, N, A_0, \Pi_c)$ whose
|
| 51 |
+
derivations tile the canvas. $N$ is a set of $S$ *nonterminal* symbols (the
|
| 52 |
+
"syntactic categories of vision"), $\Sigma$ is a set of $V$ *terminal* symbols
|
| 53 |
+
(*texels*, i.e. learned material primitives), $A_0 \in N$ is the axiom, and
|
| 54 |
+
$\Pi_c$ is a caption-conditioned set of production probabilities. The conditional
|
| 55 |
+
density marginalizes over every derivation tree $\tau$:
|
| 56 |
+
|
| 57 |
+
$$
|
| 58 |
+
p(x \mid c) \;=\; \sum_{\tau \in \mathcal{T}(G_c)}\;
|
| 59 |
+
\underbrace{\prod_{(A \to \langle s, B, C\rangle,\, r)\, \in\, \tau}
|
| 60 |
+
\pi\big(A \to \langle s, B, C\rangle \mid c, r\big)}_{\text{internal productions (splits)}}
|
| 61 |
+
\;\;
|
| 62 |
+
\underbrace{\prod_{(A \to T,\, r)\, \in\, \mathrm{leaves}(\tau)}
|
| 63 |
+
\pi\big(A \to T \mid c, r\big)\; p_{\mathrm{emit}}(x_r \mid T, r, c)}_{\text{leaf productions (emission)}}
|
| 64 |
+
$$
|
| 65 |
+
|
| 66 |
+
The single latent object is the **derivation tree** $\tau$: a variable-topology
|
| 67 |
+
binary tree whose internal nodes are (nonterminal, region) pairs and whose leaves
|
| 68 |
+
are (texel, region) pairs. There is no time index, no corruption path, and no
|
| 69 |
+
fixed-dimensional state that gets revised β every generation step *creates* new
|
| 70 |
+
latent variables (a split choice $s$, two child symbols $B, C$, two child
|
| 71 |
+
regions) and never revisits old ones. Generation randomness is exactly the
|
| 72 |
+
sequence of categorical production choices.
|
| 73 |
+
|
| 74 |
+
### Derivation and the region lattice
|
| 75 |
+
|
| 76 |
+
A production $A \to \langle s, B, C\rangle$ applied at region $r$ chooses a split
|
| 77 |
+
$s$ from a finite **cut dictionary** and partitions $r$ into two child regions
|
| 78 |
+
$r_1(s), r_2(s)$, which receive child symbols $B, C$. Regions live on a fixed
|
| 79 |
+
**binary-space-partition (BSP) lattice**: at 64Γ64 on an 8-px grid, every
|
| 80 |
+
axis-aligned rectangle with grid-aligned corners is a region ($|\mathcal{R}| =
|
| 81 |
+
1296$), and each region has $14$ cut types (2 axes Γ 7 relative-offset buckets).
|
| 82 |
+
A region is summarized for conditioning by a deterministic geometry code
|
| 83 |
+
$\rho(r)$ (Fourier features of position, size, aspect) β *not* a sampled
|
| 84 |
+
quantity, so subtrees remain conditionally independent given (symbol, region) and
|
| 85 |
+
the sum over trees stays a valid sum-product.
|
| 86 |
+
|
| 87 |
+
Finiteness is deliberate: a *finite* cut dictionary is what makes the region
|
| 88 |
+
lattice finite and the marginal likelihood **exactly** computable. Continuous
|
| 89 |
+
split parameters would break tractability (they are a target for later versions).
|
| 90 |
+
|
| 91 |
+
### Text-modulated productions
|
| 92 |
+
|
| 93 |
+
The load-bearing design decision is that **text deforms the grammar itself, it
|
| 94 |
+
does not steer a sampler.** The internal production tensor is factorized in a
|
| 95 |
+
low-rank (tensor-decomposition / TN-PCFG) form with $R$ rule components:
|
| 96 |
+
|
| 97 |
+
$$
|
| 98 |
+
\pi\big(A \to \langle s, B, C\rangle \mid c\big) \;=\;
|
| 99 |
+
\sum_{k=1}^{R} \; p(k \mid A, c)\; p(s \mid k, c)\; p(B \mid k)\; p(C \mid k)
|
| 100 |
+
$$
|
| 101 |
+
|
| 102 |
+
Here $p(B \mid k), p(C \mid k)$ are static softmax rows of learned tables
|
| 103 |
+
$V, W \in \mathbb{R}^{R \times S}$; $p(s \mid k, c)$ comes from rule-component
|
| 104 |
+
embeddings that cross-attend once to the caption; and the **only** text-dependent
|
| 105 |
+
factor is the parent mixture $p(k \mid A, c)$, produced by a **Grammar-Modulation
|
| 106 |
+
Transformer (GMT)** whose *queries are the $S$ symbol embeddings* and whose
|
| 107 |
+
keys/values are the frozen caption tokens. Because $p(k\mid A,c)$ is computed once
|
| 108 |
+
per caption (a single $S \times R$ matrix), every production probability anywhere
|
| 109 |
+
in the tree is thereafter a cheap contraction β the caption reweights *which
|
| 110 |
+
rewrites are probable* rather than pushing a fixed state along a trajectory. The
|
| 111 |
+
terminal (texel) prior shares this mixture, $p(T \mid A, c) = \sum_k p(k \mid A,
|
| 112 |
+
c)\,\mathrm{softmax}(P_T[k])$.
|
| 113 |
+
|
| 114 |
+
### Area-conditioned termination
|
| 115 |
+
|
| 116 |
+
Each symbol carries a **termination head** that decides expand-vs-emit at region
|
| 117 |
+
$r$:
|
| 118 |
+
|
| 119 |
+
$$
|
| 120 |
+
\pi(\mathrm{term} \mid A, c, r) \;=\; \sigma\!\Big( f_\theta\big(E_N[A], \rho(r)\big) \;+\; \gamma \cdot \log \tfrac{a_{\min}}{\mathrm{area}(r)} \Big)
|
| 121 |
+
$$
|
| 122 |
+
|
| 123 |
+
The explicit area term (learned gain $\gamma > 0$) makes termination more likely
|
| 124 |
+
as regions shrink. Combined with a hard floor (regions $\le 8\times8$ must
|
| 125 |
+
terminate) and a leaf ceiling ($\le 16\times16$), this **guarantees almost-sure
|
| 126 |
+
termination** of every derivation at bounded depth β the grammar cannot run away,
|
| 127 |
+
unlike a general PCFG.
|
| 128 |
+
|
| 129 |
+
### Terminal emission
|
| 130 |
+
|
| 131 |
+
A leaf $(T, r)$ is rendered by a shared, deliberately **weak** decoder that maps
|
| 132 |
+
the texel embedding, geometry $\rho(r)$, and caption to per-pixel
|
| 133 |
+
discretized-logistic mixture parameters ($K = 4$ components), fully factorized
|
| 134 |
+
over pixels *given the texel*:
|
| 135 |
+
|
| 136 |
+
$$
|
| 137 |
+
p_{\mathrm{emit}}(x_r \mid T, r, c) \;=\; \prod_{p \in r} \sum_{j=1}^{4} \lambda_{p,j}\;\mathrm{DLogistic}\big(x_p; \mu_{p,j}, \sigma_{p,j}\big)
|
| 138 |
+
$$
|
| 139 |
+
|
| 140 |
+
A caption **illumination field** $\Phi(c)$ FiLM-modulates the means so global tone
|
| 141 |
+
can cross region boundaries. The decoder is kept narrow on purpose: if a leaf
|
| 142 |
+
could model arbitrary $16\times16$ crops unconditionally, maximum likelihood would
|
| 143 |
+
let the grammar collapse to a vestigial uniform splitter. Capacity starvation at
|
| 144 |
+
the leaves *forces* explanatory power up into the tree.
|
| 145 |
+
|
| 146 |
+
### Exact likelihood via the inside DP
|
| 147 |
+
|
| 148 |
+
Because the lattice and cut dictionary are finite, the marginal over all trees is
|
| 149 |
+
computed **exactly** by a CYK-style inside pass in the log-semiring, bottom-up in
|
| 150 |
+
area order over the region lattice:
|
| 151 |
+
|
| 152 |
+
$$
|
| 153 |
+
\beta(A, r) = \mathrm{logaddexp}\Big[\;
|
| 154 |
+
\underbrace{\log \pi(\mathrm{term}\mid A,c,r) + \mathrm{logsumexp}_{T}\big(\log \pi(T\mid A,c) + \log p_{\mathrm{emit}}(x_r \mid T, r, c)\big)}_{\text{terminate}},\;\;
|
| 155 |
+
\underbrace{\mathrm{logsumexp}_{s,B,C}\big(\log \pi(A{\to}\langle s,B,C\rangle\mid c) + \beta(B, r_1(s)) + \beta(C, r_2(s))\big)}_{\text{expand}}
|
| 156 |
+
\;\Big]
|
| 157 |
+
$$
|
| 158 |
+
|
| 159 |
+
The low-rank factorization turns the $S \times S \times S$ contraction at each
|
| 160 |
+
(region, split) into a pair of $S \times R$ matmuls in a numerically stabilized
|
| 161 |
+
exp domain. The training loss is the **exact** conditional negative log-likelihood
|
| 162 |
+
|
| 163 |
+
$$
|
| 164 |
+
\mathcal{L}(x, c) \;=\; -\,\beta(A_0, \text{canvas}),
|
| 165 |
+
$$
|
| 166 |
+
|
| 167 |
+
and a single smooth backward pass through the DP reaches every parameter. There is
|
| 168 |
+
no encoder, no ELBO gap, and no sampling in the training loop. The *same* DP with
|
| 169 |
+
a max-semiring yields the **Viterbi parse** of any image β this is why analysis
|
| 170 |
+
and synthesis are the same object, and why SPRIG can explain an image as well as
|
| 171 |
+
draw one.
|
| 172 |
+
|
| 173 |
+
### Configuration (v0.1)
|
| 174 |
+
|
| 175 |
+
| Symbol | Meaning | v0.1 value |
|
| 176 |
+
|---|---|---|
|
| 177 |
+
| $S$ | nonterminal symbols | 1024 |
|
| 178 |
+
| $V = T_v$ | terminal symbols (texels) | 256 |
|
| 179 |
+
| $R$ | rule-mixture components | 64 |
|
| 180 |
+
| $d$ | model width | 384 |
|
| 181 |
+
| β | canvas / grid | 64Γ64 / 8 px |
|
| 182 |
+
| $\lvert\mathcal{R}\rvert$ | BSP region lattice | 1296 |
|
| 183 |
+
| β | cut types | 14 (2 axes Γ 7 offsets) |
|
| 184 |
+
| β | leaf cap / hard-terminate | 16Γ16 / 8Γ8 |
|
| 185 |
+
| β | caption encoder (frozen) | T5-base (768-d) |
|
| 186 |
+
| β | emission | 4-comp discretized logistic |
|
| 187 |
+
| β | trainable params | ~15.9M |
|
| 188 |
+
|
| 189 |
+
Notation: $x$ image, $c$ caption, $\tau$ derivation tree, $A,B,C \in N$
|
| 190 |
+
nonterminals, $T \in \Sigma$ texel, $s$ split, $r$ region, $\rho(r)$ geometry
|
| 191 |
+
code, $\beta$ inside score, $A_0$ axiom, $E_N$ symbol embedding table.
|
| 192 |
+
|
| 193 |
+
## Results
|
| 194 |
+
|
| 195 |
+
Success criteria were fixed in advance (50k steps, held-out procedural scenes):
|
| 196 |
|
| 197 |
| Gate | Target | Result | |
|
| 198 |
|---|---|---|---|
|
|
|
|
| 206 |
| Compositional holdout (unseen combos) | β₯ 0.60 | 0.01 | β |
|
| 207 |
| Grammar health (S_eff / alive texels) | β₯256 / β₯50% | 968 / 43% | β οΈ texels over-pruned |
|
| 208 |
|
| 209 |
+
The architecture's structural claims prove out: it models data far better than a
|
| 210 |
+
no-grammar baseline, routes caption information, recovers scene structure by
|
| 211 |
+
parsing, and (after a targeted fix) paints real objects. The open problem is
|
| 212 |
+
**captionβobject binding**: the model can draw objects and binds size perfectly,
|
| 213 |
+
but does not yet reliably paint the *specific* object a prompt asks for, and places
|
| 214 |
+
too many per scene.
|
| 215 |
|
| 216 |
## Usage
|
| 217 |
|
|
|
|
| 237 |
- `config.json` β architecture config + release metadata
|
| 238 |
- `inference.py` β minimal load + sample + T5 caption encoding
|
| 239 |
- `metrics.json` β full evaluation numbers
|
| 240 |
+
- `figures/pipeline.svg`, `figures/pipeline.png` β the method schematic
|
| 241 |
- `samples.jpg`, `texel_atlas.png`, `parses.png` β qualitative outputs
|
| 242 |
- `DESIGN.md` β the concrete v0.1 architecture specification
|
| 243 |
|