DeepX Embedding v1.0 is a Vietnamese embedding model designed for legal document retrieval. It combines a novel linear attention mechanism (Gated DeltaNet-2) with Hyperloop weight sharing to achieve strong retrieval quality while maintaining O(n) time complexity for long sequences.
The model was trained on 2x RTX 5070 Ti 16GB GPUs over roughly 600 hours. It achieves state-of-the-art on the Zalo Legal Text Retrieval benchmark, beating models that had access to much larger compute budgets.
This report documents the architecture decisions, training procedure, and evaluation results for reproducibility and community reference.
DeepX v1.0 uses a custom tokenizer with 186,046 tokens optimized for Vietnamese and English. The vocabulary was independently constructed to maximize coverage for Vietnamese legal text and English technical content, while minimizing unused tokens from other language families. Representations pass through a custom backbone with 35 compute passes organized via Hyperloop weight sharing.
Input text
→ Custom Tokenizer (186,046 vocab, optimized for VN + EN)
→ Frozen Token Embedding (186046 x 1536)
→ Begin Block: 4 unique NarrowA layers
→ Loop 1 x2: [WideA + NarrowA x4] per iteration
→ Loop 2 x4: [NarrowB x4 + WideB] per iteration
→ End Block: 1 unique WideB layer
→ RMSNorm
→ Attention Pooling → single vector (1536-d)
→ ColBERT Head → token vectors (T x 128-d)
| Component | Parameters |
|---|---|
| Token Embedding (frozen, pruned) | 286M |
| Backbone (trainable) | 486M |
| Grand Total | 772M |
The token embedding is frozen throughout training. The vocabulary was constructed with 186,046 tokens covering Vietnamese, English, code symbols, and common Unicode ranges, while excluding CJK, Hangul, Arabic, Thai, and other scripts unused in the target domains. This reduces embedding size by 29% compared to a full multilingual tokenizer with zero impact on VN/EN quality.
| Type | Heads | KV Heads | Head Dim | MLP Size | Used In |
|---|---|---|---|---|---|
| NarrowA | 8 | 1 | 256 | 6144 | Begin, Loop 1 |
| NarrowB | 8 | 1 | 256 | 12288 | Loop 2 |
| WideA | 16 | 2 | 256 | 6144 | Loop 1 |
| WideB | 16 | 2 | 256 | 12288 | Loop 2, End |
The core attention mechanism is GDN-2, a pure linear attention variant with O(n) complexity based on the gated delta rule recurrence.
Each attention layer maintains a running key-value state that gets updated at every token via three learned gates:
state_t = decay_t * state_{t-1}
state_t -= erase_t * (erase_t @ state_t - write_t * v_t)
output_t = q_t @ state_t
A short 1D causal convolution on Q and K provides local context before the recurrence. An output gate (SiLU) is applied after for additional expressiveness.
| Sequence Length | DeepX (GDN-2) | Softmax Transformer |
|---|---|---|
| 512 tokens | Fast | Fast |
| 2048 tokens | Fast (same speed) | 16x slower |
| 8192 tokens | Fast (same speed) | OOM on 16GB |
GDN-2 uses the fla library (flash-linear-attention) Triton kernels for chunk-parallel computation during training. When FLA is not available, the model falls back to a sequential implementation that is functionally identical but slower.
Our architecture is based on the Hyperloop Transformer [17], which organizes a looped transformer into begin, middle, and end blocks where only the middle block is applied recurrently.
9 unique parameter sets producing 35 compute passes.
Each iteration receives its own low-rank adapter (LoRA, rank 16) applied to all projection matrices (Q, K, V, O, gate, up, down). This differentiates entire multi-layer blocks (5 layers per iteration) simultaneously, preventing depth collapse in looped architectures.
We introduce RoDE, a novel positional signal that encodes loop iteration depth directly into Q and K via rotation. Standard RoPE only encodes token position. RoDE adds a second rotation based on loop index, giving the attention mechanism an explicit depth signal. Uses 16 dimensions (8 rotary pairs). To our knowledge this has not been proposed before.
| Setting | Value |
|---|---|
| GPUs | 2x RTX 5070 Ti 16GB (pipeline parallel) |
| Precision | BF16 (mixed precision) |
| Optimizer | AdamW 8-bit (bitsandbytes) |
| Gradient checkpointing | Custom manual checkpoint (FLA-compatible) |
| Effective batch size | 8 (via gradient accumulation) |
| Training sequence length | 8192 tokens max |
| Inference sequence length | 8192 (validated), 128K (YaRN, not yet validated) |
Pipeline parallel splits the backbone: GPU0 handles begin + loop 1 (14 passes), GPU1 handles loop 2 + end (21 passes).
Training followed an iterative approach over 14-15 rounds, each round building on the previous checkpoint through cycles of training, evaluating, mining new hard negatives, and adjusting data mixture. Total training time: around 600 hours.
Cross-lingual (EN-VI):
| Dataset | Source | Size |
|---|---|---|
| PhoMT | vinai/PhoMT | ~3.7M pairs |
| WikiMatrix VI-EN | OPUS/WikiMatrix | ~700K pairs |
| OPUS-100 VI-EN | OPUS | ~1M pairs |
Vietnamese General:
| Dataset | Source | Size |
|---|---|---|
| MMARCO-Vi | unicamp-dl/mmarco (vi) | ~532K pairs |
| MIRACL-Vi | miracl/miracl (vi) | ~4.6K queries |
| ViQuAD 2.0 | toughdata/viquad-v2 | ~18K pairs |
| Wikipedia Vi | wikimedia/wikipedia (vi) | ~500K pairs |
| CulturaX-Vi | vietgpt/CulturaX (vi) | ~1M+ pairs |
Legal Domain:
| Dataset | Source | Size |
|---|---|---|
| Vietnamese Legal Documents | th1nhng0/vietnamese-legal-documents | ~518K docs |
| Legal Query-Passage Pairs | phamson02/large-vi-legal-queries | ~507K pairs |
| VBPL corpus | vbpl.vn (crawl) | ~50K docs |
| ThuVienPhapLuat | thuvienphapluat.vn (crawl) | ~30K articles |
| Hard negatives | FAISS-mined (rank 1-50) | 5 per query |
| DX internal legal QA | Internal (proprietary) | ~2M pairs |
Dataset: GreenNode/zalo-ai-legal-text-retrieval-vn (61,396 docs, 818 test queries)
| Model | Params | nDCG@10 | MRR@10 | Recall@10 |
|---|---|---|---|---|
| sup-SimCSE-VietNamese-phobert_base | 135M | ~0.25 | - | - |
| bkai-foundation-models/vietnamese-bi-encoder | 135M | 0.6160 | - | - |
| intfloat/multilingual-e5-large | 560M | 0.6660 | - | - |
| mainguyen9/vietlegal-harrier-270m | 270M | 0.7174 | 0.6636 | 0.8864 |
| mainguyen9/vietlegal-e5 | 560M | 0.7310 | 0.6770 | 0.8972 |
| mainguyen9/vietlegal-harrier-0.6b (prev. SOTA) | 600M | 0.7813 | 0.7303 | 0.9321 |
| DeepX Embedding v1.0 (ours) | 772M | 0.8162 | 0.7672 | 0.9537 |
DeepX v1.0 surpasses the previous SOTA by +3.5 points on nDCG@10.
| Dimension | nDCG@10 | Quality vs Full |
|---|---|---|
| 256 | 0.78 | ~96% |
| 512 | 0.79 | ~97% |
| 768 | 0.80 | ~98% |
| 1024 | 0.81 | ~99% |
| 1536 (full) | 0.8162 | 100% |
256-d embeddings provide 6x storage reduction with minimal quality loss.
Stage 1: Query vector vs. corpus vectors → ANN (FAISS/Milvus) → top-100
Stage 2: Query tokens vs. top-100 doc tokens → MaxSim → top-10
import torch
from transformers import AutoTokenizer
from modeling.pipeline import DeepXPipeline
from config import DeepXConfig
tokenizer = AutoTokenizer.from_pretrained("dxtech-asia/deepx-embedding-v1")
config = DeepXConfig()
pipeline = DeepXPipeline.from_pretrained(
config,
backbone_path="checkpoints/deepx_v1.pt",
embed_path="deploy/pruned/token_embedding_pruned.pt",
)
pipeline.eval()
text = "Mức phạt khi vượt đèn đỏ là bao nhiêu?"
inputs = tokenizer(text, return_tensors="pt", max_length=8192, truncation=True)
id_remap = torch.load("deploy/pruned/tokenizer/id_remap.pt")
input_ids = id_remap[inputs["input_ids"]]
with torch.no_grad():
embedding = pipeline.encode(input_ids.cuda(), inputs["attention_mask"].cuda())
# embedding.shape = (1, 1536)
fla library for efficient inference; falls back to slower sequential mode without it@misc{deepx2026embedding,
title={DeepX Embedding v1.0: Vietnamese Legal Retrieval with GDN-2 Linear Attention},
author={DX Tech Asia},
year={2026},
url={https://huggingface.co/dxtech-asia/deepx-embedding-v1}
}
Code: Apache 2.0 | Model weights: Apache 2.0 | Tokenizer: Custom vocabulary.
This work uses the FLA library from the flash-linear-attention team, and the Zalo Legal Text Retrieval benchmark from GreenNode. We acknowledge the vietlegal-harrier team for establishing a strong baseline that motivated our work on hard negative mining.