- AGMT v3.2 --- Elastic Recurrent English ↔ Vietnamese Translator
- Author
- What makes AGMT different?
- Architecture
- Repository files
- Requirements
-
sentencepieceLoad the embedded tokenizer and encode/decode text - Quick start
- Interactive commands
-
/qExit (/quitand/exitalso work) - Inference modes
- Trace mode
- Manual qualitative tests
- How AGMT is intended to be trained
- Design principles
- Current status
- Contact
- Author
AGMT v3.2 --- Elastic Recurrent English ↔ Vietnamese Translator
AGMT (Adaptive/Elastic Recurrent Translation Architecture) is an experimental end-to-end English ↔ Vietnamese translation model built around shared recurrent refinement and translation-value routing.
The central idea is simple:
A translation model should not always use the same amount of computation.
It should refine only while additional latent computation is expected to improve the translation.
AGMT combines established components --- shared subword tokenization, embeddings, Transformer-style encoding/decoding, residual paths and autoregressive decoding --- with an experimental architecture built around recurrent parameter sharing, adaptive HALT/REFINE routing, lexical/base shortcuts, and a stable memory bridge.
This is therefore not a claim that every component is new. AGMT is partly a new architecture and partly a composition/reworking of existing ideas into one translation system.
Author
Trần Tuấn Phi --- Vietnam
- Email:
phihhhhhhhhhh@gmail.com--- I do not check email frequently. - Facebook: https://www.facebook.com/share/1HerWkmghN
What makes AGMT different?
A conventional fixed-depth encoder executes a predetermined stack for every input. AGMT instead has a non-recurrent base encoder followed by a shared recurrent refiner:
H_base
│
▼
Shared Refiner ──► H1
▲ │
└───────────────┘
repeat
The same refiner parameters are reused at multiple refinement steps.
Therefore:
stored parameter count ≠ effective computation depth
Increasing r does not add a new set of model weights. It runs the
shared refinement transformation again on the current hidden state.
Importantly:
larger r ≠ automatically better translation
A later refinement can improve, preserve, or occasionally degrade a translation. The router exists to decide whether another refinement step is expected to have enough translation value to justify its compute cost.
Architecture
SOURCE
│
▼
Shared Byte-Safe SentencePiece Tokenizer
│
▼
Shared Embedding
│
├────────────────────────► Lexical Highway
│
▼
Prelude Encoder
│
▼
H_base
│
▼
Shared Recurrent Refiner
│
├────► Translation-Value Router
│ ├─ HALT
│ └─ REFINE
│
└──── recurrent refinement
│
▼
H_refined
│
├──────── H_base
├──────── E_lex
▼
Stable Memory Bridge
│
▼
Coda Adapter
│
▼
Shallow Autoregressive Decoder
│
▼
TRANSLATION
Shared tokenizer and embedding
AGMT uses one tokenizer and a shared representation space for both translation directions. Direction tokens select the target language.
The tokenizer is embedded directly inside translate.py as a
Base64-encoded serialized SentencePiece model. Do not delete
_SPM_B64 unless you also change the loader to obtain the exact same
tokenizer from an external file.
The embedded tokenizer keeps the release self-contained: translate.py
reconstructs the SentencePiece processor at startup before loading the
ONNX graphs.
Lexical Highway
The lexical path preserves source-surface evidence such as names, numbers, technical identifiers and other information that should not have to survive every recurrent transformation.
Prelude Encoder
The Prelude creates H_base, the contextual foundation before recurrent
refinement. H_base is also retained as a stable shortcut for the
decoder-side memory interface.
Shared Recurrent Refiner
The refiner reuses the same learned transformation at every recurrent step. A step ID tells the shared block which refinement stage it is executing.
Conceptually:
H_(r+1) = Refiner(H_r, step=r)
r is therefore the number of recurrent refinement steps actually
executed, not a confidence score and not a separate reasoning model.
Translation-Value Router
For fast and balanced inference, the router runs before the next
refiner step. If the predicted remaining value is not above the active
compute price, AGMT halts without performing speculative extra
refinement.
The runtime router features include information derived from the current state, state change, input length, recurrence step and translation direction.
Stable Memory Bridge
The decoder does not rely only on the final recurrent endpoint. It receives three information streams:
H_refined — current refined contextual state
H_base — pre-recurrence contextual state
E_lex — lexical shortcut
This is intended to reduce information loss across repeated refinement and to keep a stable decoder interface across different recurrent depths.
Decoder
AGMT uses an autoregressive decoder. The provided runtime currently performs greedy decoding.
Repository files
Keep these files in the same directory:
.
├── base.onnx
├── refine.onnx
├── router.onnx
├── decode.onnx
└── translate.py
base.onnx
Runs the base/source path and returns the lexical representation, base contextual representation and source padding mask.
refine.onnx
Runs one shared recurrent refinement step. The same ONNX graph is called repeatedly with the current hidden state and a refinement step ID.
router.onnx
Predicts the value used by the adaptive HALT/REFINE policy.
decode.onnx
Runs the target decoder from target token IDs plus H_refined,
H_base, E_lex and the source mask.
translate.py
translate.py is the complete Python inference runtime. It:
- embeds and reconstructs the SentencePiece tokenizer;
- loads all four ONNX graphs from its own directory;
- normalizes and tokenizes input;
- inserts the translation-direction token;
- rejects over-length input instead of silently truncating it;
- runs base encoding;
- builds router features;
- performs adaptive or forced recurrent refinement;
- performs greedy autoregressive decoding;
- exposes normal, forced-depth and full-depth trace inference;
- provides an interactive Vietnamese CLI.
The runtime explicitly uses ONNX Runtime's CPUExecutionProvider, with
ONNX graph optimization enabled.
Requirements
Only three third-party Python packages are required:
pip install onnxruntime numpy sentencepiece
They are used as follows:
Package Purpose
onnxruntime Execute base.onnx, refine.onnx,
router.onnx, and decode.onnx
numpy Tensor preparation, router feature
construction and runtime numerical
operations
sentencepiece Load the embedded tokenizer and
encode/decode text
The remaining imports used by translate.py come from the Python
standard library.
Quick start
Put all four .onnx files beside translate.py, install the three
dependencies, then run:
python translate.py
The interactive CLI starts with:
AGMT v3.2 — ONNX Translator
Gõ /help để xem toàn bộ lệnh tiếng Việt.
Choose a target language:
/vi
then type English text to translate into Vietnamese, or:
/en
then type Vietnamese text to translate into English.
You can also translate immediately:
/vi Hello world
/en Xin chào
Command-line one-shot usage:
python translate.py /vi "Hello world" balanced
python translate.py /en "Xin chào" balanced
python translate.py /vi "The man was sleeping." quality
Interactive commands
Command Meaning
/en Set target language to English
/en <text> Translate the supplied text
directly to English
/vi Set target language to Vietnamese
/vi <text> Translate the supplied text
directly to Vietnamese
/mode fast Use a higher effective compute
price, making earlier halting
easier
/mode balanced Default adaptive routing policy
/mode quality Force all trained recurrent
refinement steps
/depth auto Let the active mode/router choose
the depth
/depth 0 Decode directly from the base
representation
/depth 1..R_MAX Force exactly that many refinement
steps
/trace on Decode and print every depth from
r=0 through R_MAX, including
router values
/trace off Return to normal inference
/max <tokens> Change the maximum number of
generated output tokens
/price <value> Change the balanced-mode compute
price
/fastmult <value> Change the multiplier used by fast
mode
/status Show the current inference
configuration
/help Show the built-in Vietnamese help
/q Exit (/quit and /exit also
work)
What does [r=...] mean?
Example:
[r=3 | balanced]
means the model actually executed three recurrent refinement steps before decoding.
It does not mean "confidence 3", "reasoning level 3", or "three extra parameter layers".
Inference modes
Fast
/mode fast
Uses a higher effective compute price, so the router is more willing to halt early.
Balanced
/mode balanced
Uses the default adaptive HALT/REFINE policy.
Quality
/mode quality
Forces the maximum trained recurrent depth. In the current runtime,
quality ignores router halting.
Important: maximum compute does not mathematically guarantee the
best output for every sentence. AGMT can have a non-monotonic
depth-quality curve, so quality should be understood as force
maximum trained compute, not as a guarantee that r=R_MAX is always
the optimal translation.
Trace mode
Trace mode is useful for studying what recurrence is doing:
/trace on
For each input, the runtime decodes every recurrent depth and reports the router value/decision.
Conceptually:
r=0 → translation before recurrent refinement
r=1 → after one refinement
r=2 → after two refinements
...
This makes it possible to observe transitions such as:
wrong → wrong → correct → correct
or:
correct → correct → degraded
Trace mode is diagnostic only; it does not modify the model weights.
Manual qualitative tests
The following are small hand-written diagnostic examples, not a formal benchmark. They are included because they show the behavior that motivated AGMT's elastic recurrent design.
1. Simple translation
EN: The dog chased the cat.
VI: Con chó đuổi con mèo.
A subject/object reversal test also preserved the changed roles:
EN: The cat chased the dog.
VI: Con mèo đã đuổi theo con chó.
2. Recurrent refinement correcting a structural translation
Input:
The man the boy saw was sleeping.
Observed trace:
r=0 incorrect
r=1 incorrect
r=2 "Người đàn ông mà thằng bé thấy đang ngủ." ✓
r=3 same / router would halt
r=4 still correct
r=5 degraded: information about "the boy" was lost
r=6 degraded
This is an important qualitative example: additional recurrent compute first repaired the relation, but excessive refinement later degraded it. It illustrates why AGMT does not assume that the deepest recurrence is always the best recurrence.
3. Recursive semantic binding
Input:
I know that you know that I know that he knows her.
Observed behavior:
r=0 incorrect binding
r=1 incorrect binding
r=2 corrected:
"Tôi biết anh biết là tôi biết anh ta biết cô ấy."
r=3..r=6 remained stable in this test
This provides a small qualitative example where repeated application of the shared refiner corrected a semantic-role/binding error.
4. Cases that remain difficult
AGMT v3.2 is experimental and still has clear weaknesses. Manual testing found failures on phenomena such as:
idioms
counterfactual constructions
long-distance relative-clause attachment
some English tense realization
technical/code-switched text
some VI → EN grammatical constructions
For example, an idiom such as:
It's not really my cup of tea, but I can see why people like it.
was translated too literally in manual testing, and forcing deeper recurrence did not solve the underlying knowledge/translation limitation.
These examples are intentionally reported rather than hidden: adaptive routing cannot create translation capability that the translator itself has not learned.
How AGMT is intended to be trained
The architectural training concept separates translator learning from final router learning:
Static Data Sanitation
↓
Train Translator
↓
Learn useful multi-depth recurrence
↓
Freeze Translator
↓
Profile translations across valid depths
↓
Build noise-aware / ε-tolerant recurrence oracle
↓
Train source-only translation-value router
↓
Calibrate HALT/REFINE compute policy
↓
Evaluate translation + compute + semantic challenge sets
The router is intended to predict remaining useful translation value, rather than simply learning that a high-loss or long sentence must receive more compute.
At inference time the router uses source-derived state only; reference translations are not available to it.
Design principles
AGMT follows several core principles:
Translation quality is the final authority.
More recurrence is not automatically better.
Sentence length is not a depth rule.
A hard or corrupted sample should not automatically mean "refine more".
The router should allocate compute according to expected translation benefit.
Lexical and base shortcuts should protect useful information from recurrent degradation.
The deepest recurrence is a fallback/diagnostic path, not an assumption of optimality.
In one sentence:
AGMT v3.2 is a shared recurrent translator with translation-value routing, lexical/base shortcuts and a stable memory bridge, designed to spend additional latent computation only when that computation is expected to improve translation.
Current status
AGMT v3.2 should currently be treated as an experimental research model.
The examples above are qualitative tests, not standardized BLEU/chrF/COMET results. Formal evaluation should compare fixed recurrent depths, adaptive routing, compute usage, latency, and semantic challenge sets before making broader quality claims.
Contact
Trần Tuấn Phi --- Vietnam
Email: phihhhhhhhhhh@gmail.com
I do not check email frequently.