Downloads · 30 days
15
37% of all-time downloads
TigreGotico/translate-eus-cat-onnx
translate-eus-cat-onnx is a translation model from TigreGotico. Use it when you need text moved from one language to another. It is set up for transformers. The card lists the license as mit.
ONNX build of softcatala/translate-eus-cat, translating Basque (eu) to Catalan (ca).
Downloads · 30 days
15
37% of all-time downloads
All-time downloads
41
Public
Parameters
70.8M
1.7 GB on disk
Likes
0
Public
Click a slice to open those files.
.onnx1.4 GB · 82%
From the Hugging Face model README
ONNX build of softcatala/translate-eus-cat, translating
Basque (eu) to Catalan (ca).
The original is published only as a CTranslate2 binary, which runs only inside
CTranslate2. This repository holds a HuggingFace PegasusForConditionalGeneration
checkpoint and an ONNX export that were reconstructed from that binary.
Nothing was retrained. The weights are the original weights.
Credit for the model belongs to Softcatalà. Licence mit, the same as
the source.
| Path | What it is |
|---|---|
model.safetensors, config.json | PyTorch PegasusForConditionalGeneration |
encoder_model.onnx, decoder_model.onnx, decoder_with_past_model.onnx | ONNX, float32 |
int8/ | the same three graphs, dynamic int8 |
tokenizer.json | fast Unigram tokenizer over the original sentencepiece model |
ct2_reader.py, ct2_to_pegasus.py, spm_tokenizer.py | the converter |
from transformers import AutoTokenizer
from optimum.onnxruntime import ORTModelForSeq2SeqLM
tok = AutoTokenizer.from_pretrained("TigreGotico/translate-eus-cat-onnx")
model = ORTModelForSeq2SeqLM.from_pretrained("TigreGotico/translate-eus-cat-onnx", use_cache=True, use_merged=False)
ids = tok('Katua sofan lo dago.', return_tensors="pt")
out = model.generate(**ids, num_beams=4, max_new_tokens=256)
print(tok.decode(out[0], skip_special_tokens=True))
# El gat dorm al sofà.
For the int8 build add subfolder="int8".
Read this before you replace the tokenizer.
with_source_eos = 0, so the encoder never saw </s> during training.
MarianTokenizer, PegasusTokenizer and T5Tokenizer all append </s>,
which puts the model off its training distribution. The tokenizer shipped here
appends nothing.shared_vocabulary order, which is not the
sentencepiece order: CT2 puts <blank> (the pad token) at id 0 and moves
<unk> to the end of the table.<s>, not from </s>.15 source sentences, greedy and beam 4, exact string match against
ctranslate2.Translator running the source model.bin:
| Comparison | greedy | beam 4 |
|---|---|---|
| reconstructed PyTorch | 100% | 93% |
| ONNX float32 | 100% | 93% |
| ONNX int8 | 100% | 87% |
Token-level agreement on the CT2 hypothesis is about 0.005 maximum absolute log-probability difference, which is kernel numeric noise. Any remaining string difference is a beam-search tie, not a weight error.
A CTranslate2 model.bin is a flat self-describing binary: binary_version,
the spec name and revision, then one record per variable (name, rank,
dimensions, dtype code, byte count, raw bytes), then a table of aliases for tied
weights. ct2_reader.py reads it and dequantizes int8 variables with their
*_scale companion. ct2_to_pegasus.py recovers the architecture from the spec
scalars and maps every variable onto a HuggingFace parameter.
This model reports:
{
"encoder_layers": 6,
"decoder_layers": 6,
"vocab_size": 50001,
"d_model": 512,
"heads": 8,
"ffn_dim": 2048,
"pre_norm": true,
"activation": "relu",
"layernorm_embedding": false,
"relative_position": false,
"scale_embeddings": true,
"output_bias": true,
"stored_positions": false,
"source_bos": false,
"source_eos": false,
"target_bos": true,
"decoder_start_token": "<s>",
"ct2_spec": "TransformerSpec rev 7, binary_version 6"
}
Three properties fix the target class:
layernorm_embedding. That rules out BART, mBART and PLBart, whose
layernorm_embedding cannot be neutralised — a LayerNorm with weight 1 and
bias 0 still normalises. It also rules out Marian, which is post-norm.decoder/projection/bias). Neither Marian nor M2M100 has
one. Pegasus does, as final_logits_bias.model.bin. CTranslate2
builds it with the OpenNMT-tf formula, spacing log(10000)/(dim/2 - 1) and
layout [sin all | cos all]. Pegasus rebuilds it on load with
10000^(2i/dim), which is a different table. The converter writes the CT2
table into embed_positions.weight, clears _keys_to_ignore_on_save so it is
actually persisted, and reloads the checkpoint to assert the table survived.
Skipping this produces a model that runs and translates plausibly but wrongly.linear_0 of shape
(3d, d) in that order. Cross-attention splits differently: linear_0 is Q
alone, linear_1 is [K; V] fused, linear_2 is the output projection.(out, in), the layout torch.nn.Linear uses, so nothing
is transposed. gamma and beta are the layer-norm weight and bias.MatMul with /lm_head/MatMul excluded.
Quantizing every operator destroys a 512-dimension NMT decoder.Model and training data: Softcatalà, licence mit.
Source repository: softcatala/translate-eus-cat.
This repository only changes the file format.