aoiandroid commited on
Commit
a80f32d
Β·
verified Β·
1 Parent(s): 9a78db0

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +119 -0
README.md ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ tags:
4
+ - translation
5
+ - onnx
6
+ - opus-mt
7
+ - helsinki-nlp
8
+ - multilingual
9
+ datasets:
10
+ - opus
11
+ language:
12
+ - multilingual
13
+ pipeline_tag: translation
14
+ ---
15
+
16
+ # OPUS-MT ONNX Model Hub
17
+
18
+ Mirror of [VaishalBusiness/opus](https://huggingface.co/VaishalBusiness/opus) (VGT ONNX Model Hub): 1,000+ OPUS-MT translation models in ONNX format for fast inference.
19
+
20
+ ## Highlights
21
+
22
+ - 1,000+ ONNX models from Helsinki-NLP / MarianMT
23
+ - Optimized for inference with ONNX Runtime
24
+ - Compatible with Hugging Face tokenizers
25
+ - Same layout and usage as the original VGT hub
26
+
27
+ ## Repository structure
28
+
29
+ Each model is in its own folder, for example:
30
+
31
+ ```
32
+ Helsinki-NLP-opus-mt-tc-base-bat-zle/
33
+ β”œβ”€β”€ config.json
34
+ β”œβ”€β”€ decoder_model.onnx
35
+ β”œβ”€β”€ decoder_model_merged.onnx
36
+ β”œβ”€β”€ decoder_with_past_model.onnx
37
+ β”œβ”€β”€ encoder_model.onnx
38
+ β”œβ”€β”€ generation_config.json
39
+ β”œβ”€β”€ source.spm
40
+ β”œβ”€β”€ target.spm
41
+ β”œβ”€β”€ special_tokens_map.json
42
+ β”œβ”€β”€ tokenizer_config.json
43
+ └── vocab.json
44
+ ```
45
+
46
+ - **encoder_model.onnx** – encoder
47
+ - **decoder_with_past_model.onnx** – decoder with KV cache
48
+ - **decoder_model_merged.onnx** – merged decoder (recommended for speed)
49
+ - **decoder_model.onnx** – base decoder
50
+ - **source.spm / target.spm, vocab.json** – tokenizer files
51
+
52
+ ## Usage
53
+
54
+ ### Dependencies
55
+
56
+ ```bash
57
+ pip install huggingface_hub onnxruntime transformers sentencepiece
58
+ ```
59
+
60
+ ### Load and run a model
61
+
62
+ Replace `Helsinki-NLP-opus-mt-tc-base-bat-zle` with any model folder name from the repo.
63
+
64
+ ```python
65
+ from huggingface_hub import snapshot_download
66
+ import onnxruntime as ort
67
+ from transformers import MarianTokenizer
68
+ import numpy as np
69
+
70
+ # Download the model folder (use this repo id after renaming to opus-mt-onnx)
71
+ repo_id = "aoiandroid/opus-mt-onnx" # or aoiandroid/opus if not renamed yet
72
+ model_dir = snapshot_download(
73
+ repo_id=repo_id,
74
+ allow_patterns="Helsinki-NLP-opus-mt-tc-base-bat-zle/*",
75
+ )
76
+
77
+ # Load tokenizer
78
+ tokenizer = MarianTokenizer.from_pretrained(
79
+ f"{model_dir}/Helsinki-NLP-opus-mt-tc-base-bat-zle"
80
+ )
81
+
82
+ # Encode input
83
+ inputs = tokenizer("Hello, how are you?", return_tensors="np")
84
+
85
+ # Run encoder
86
+ enc = ort.InferenceSession(
87
+ f"{model_dir}/Helsinki-NLP-opus-mt-tc-base-bat-zle/encoder_model.onnx"
88
+ )
89
+ enc_out = enc.run(
90
+ None,
91
+ {
92
+ "input_ids": inputs["input_ids"],
93
+ "attention_mask": inputs["attention_mask"],
94
+ },
95
+ )
96
+
97
+ # Run merged decoder
98
+ dec = ort.InferenceSession(
99
+ f"{model_dir}/Helsinki-NLP-opus-mt-tc-base-bat-zle/decoder_model_merged.onnx"
100
+ )
101
+ decoder_input_ids = np.array([[tokenizer.pad_token_id]], dtype=np.int64)
102
+ out = dec.run(
103
+ None,
104
+ {
105
+ "input_ids": decoder_input_ids,
106
+ "encoder_hidden_states": enc_out[0],
107
+ },
108
+ )
109
+ ```
110
+
111
+ ## Attribution
112
+
113
+ - Original ONNX hub: [VaishalBusiness/opus](https://huggingface.co/VaishalBusiness/opus) (VGT ONNX Model Hub)
114
+ - Underlying models: [Helsinki-NLP](https://huggingface.co/Helsinki-NLP) OPUS-MT / MarianMT
115
+ - ONNX conversions and hosting follow the original project’s intent; licenses of each model are unchanged.
116
+
117
+ ## License
118
+
119
+ Each model keeps its original license. When using a model, cite the original authors and comply with their license and attribution requirements. This repository only provides a mirror of ONNX conversions.