CoolFace
Modelpublic

textualization/all-distilroberta-v1

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes15downloads
Model Card

This is a ONNX export of `sentence-transformers/all-distilroberta-v1`.

The export was done using HF Optimum:

python
from optimum.exporters.onnx import main_export

main_export('sentence-transformers/all-distilroberta-v1', "./output", cache_dir='./cache', optimize='O1') 

Please note, this ONNX model does not contain the mean pooling layer, it needs to be done in code afterwards or the embeddings won't work.

Code like this:

python
#Mean Pooling - Take attention mask into account for correct averaging
def mean_pooling(model_output, attention_mask):
    token_embeddings = model_output[0] #First element of model_output contains all token embeddings
    input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
    return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)

See the example code from the original model in the "Usage (HuggingFace Transformers)" section.