Views
No views yet
laituanmanh32/vietnamese-embedding-onnx is an ONNX-converted version of the original Vietnamese embedding model created by dangvantuan. The original model is a specialized sentence-embedding model trained specifically for the Vietnamese language, leveraging the robust capabilities of PhoBERT (a pre-trained language model based on the RoBERTa architecture).1pip install onnxruntime
2pip install pyvi
3pip install transformers1from transformers import AutoTokenizer
2import onnxruntime as ort
3import numpy as np
4from pyvi.ViTokenizer import tokenize
5
6# Load tokenizer and ONNX model
7tokenizer = AutoTokenizer.from_pretrained("laituanmanh32/vietnamese-embedding-onnx")
8ort_session = ort.InferenceSession("path/to/model.onnx")
9
10# Prepare input sentences
11sentences = ["Hà Nội là thủ đô của Việt Nam", "Đà Nẵng là thành phố du lịch"]
12tokenized_sentences = [tokenize(sent) for sent in sentences]
13
14# Tokenize and get embeddings
15encoded_input = tokenizer(tokenized_sentences, padding=True, truncation=True, return_tensors="np")
16inputs = {k: v for k, v in encoded_input.items()}
17
18# Run inference
19outputs = ort_session.run(None, inputs)
20embeddings = outputs[0]
21
22# Use embeddings for your downstream tasks
23print(embeddings.shape) # Should be [2, 768] for our example| Model | Inference Time (ms/sentence) | Memory Usage |
|---|---|---|
| Original PyTorch | 15-20ms | ~500MB |
| ONNX | 5-10ms | ~200MB |
| Model | [STSB] | [STS12] | [STS13] | [STS14] | [STS15] | [STS16] | [SICK] | Mean |
|---|---|---|---|---|---|---|---|---|
| dangvantuan/vietnamese-embedding | 84.87 | 87.23 | 85.39 | 82.94 | 86.91 | 79.39 | 82.77 | 84.21 |
@article{reimers2019sentence,
title={Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks},
author={Nils Reimers, Iryna Gurevych},
journal={https://arxiv.org/abs/1908.10084},
year={2019}
}