uuugi commited on
Commit
b984b6d
·
verified ·
1 Parent(s): bc69298

Replace fragile math with clean pseudocode and clean inline text

Browse files
Files changed (1) hide show
  1. README.md +17 -19
README.md CHANGED
@@ -20,8 +20,8 @@ pipeline_tag: text-generation
20
  [![Transformers 4.36+](https://img.shields.io/badge/Transformers-4.36+-yellow.svg)](https://huggingface.co/docs/transformers)
21
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
22
 
23
- An ultra-fast, strictly \(O(1)\) runtime **Goal-Conditioned Reachability Logit Masking Engine** for Large Language Models.
24
- GCLM mathematically guarantees that an LLM will strictly reach designated goal/accepting states within a fixed token budget (\(T_{\max}\)), **fundamentally preventing dead-end traps and truncated syntax failures**.
25
 
26
  ---
27
 
@@ -51,28 +51,26 @@ GCLM mathematically guarantees that an LLM will strictly reach designated goal/a
51
  ## 📐 Mathematical Formulation
52
 
53
  ### 1. Offline Backward BFS Table Builder
54
- Given an FSM \((S, \Sigma, \delta, s_0, S_{\mathrm{goal}})\) and maximum token budget \(T_{\max}\), we precompute a reachability tensor \(R \in \mathbb{B}^{(T_{\max} + 1) \times |S|}\) via vectorized backward BFS:
55
 
56
- $$
57
- R[0, s] = \mathbf{1}(s \in S_{\mathrm{goal}})
58
- $$
59
-
60
- For \(t = 1, \dots, T_{\max}\):
61
 
62
- $$
63
- R[t, s] = R[t-1, s] \lor \left( \exists v \in \mathcal{V} \text{ s.t. } \delta(s, v) \ge 0 \land R[t-1, \delta(s, v)] = 1 \right)
64
- $$
65
 
66
- ### 2. Strict \(O(1)\) Runtime Logits Masking
67
- At decoding step \(k\) with remaining budget \(T_{\mathrm{rem}} = T_{\max} - k\):
68
 
69
- $$
70
- \mathrm{ValidTokens}(v) = (\delta(s_{\mathrm{curr}}, v) \ge 0) \land R\big[\min(T_{\mathrm{rem}}-1, T_{\max}), \;\mathrm{clamp}(\delta(s_{\mathrm{curr}}, v), 0)\big]
71
- $$
72
 
73
- $$
74
- \mathrm{Logits}[v] = \begin{cases} \mathrm{Logits}[v] & \text{if } \mathrm{ValidTokens}(v) = 1 \\ -\infty & \text{otherwise} \end{cases}
75
- $$
76
 
77
  ---
78
 
 
20
  [![Transformers 4.36+](https://img.shields.io/badge/Transformers-4.36+-yellow.svg)](https://huggingface.co/docs/transformers)
21
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
22
 
23
+ An ultra-fast, strictly **O(1)** runtime **Goal-Conditioned Reachability Logit Masking Engine** for Large Language Models.
24
+ GCLM mathematically guarantees that an LLM will strictly reach designated goal/accepting states within a fixed token budget (`T_max`), **fundamentally preventing dead-end traps and truncated syntax failures**.
25
 
26
  ---
27
 
 
51
  ## 📐 Mathematical Formulation
52
 
53
  ### 1. Offline Backward BFS Table Builder
54
+ Given an FSM $(S, \Sigma, \delta, s_0, S_{\text{goal}})$ and maximum token budget $T_{\max}$, we precompute a reachability tensor $R \in \{0, 1\}^{(T_{\max} + 1) \times |S|}$ via vectorized backward BFS:
55
 
56
+ ```python
57
+ # Base Step (t = 0):
58
+ R[0, s] = 1 if (s in S_goal) else 0
 
 
59
 
60
+ # Vectorized Backward BFS (for t = 1 ... T_max):
61
+ R[t, s] = R[t-1, s] OR ( v V such that δ(s, v) >= 0 and R[t-1, δ(s, v)] == 1)
62
+ ```
63
 
64
+ ### 2. Strict O(1) Runtime Logits Masking
65
+ At decoding step $k$ with remaining token budget $T_{\text{rem}} = T_{\max} - k$:
66
 
67
+ ```python
68
+ # Step 1: Vectorized check for valid transitions within remaining budget
69
+ ValidTokens(v) = (δ(s_curr, v) >= 0) AND R[min(T_rem - 1, T_max), clamp(δ(s_curr, v), 0)]
70
 
71
+ # Step 2: In-place O(1) logit masking
72
+ Logits[v] = Logits[v] if ValidTokens(v) == 1 else -inf
73
+ ```
74
 
75
  ---
76