Convert bert tokenizer to onnx

I was referring to the following blog to convert bert model to onnx.

here, to take the inference of bert tokenizer, I’ll have to pass the 2d arrays.

Is there a way, where I’ll be able to pass sentence as input to the onnx tokenizer and get encodings as output, so that I’ll be able to use the model platform-independent

hi @hasak,

the tokenizer is independent of onnx / onnxruntime, so you could create a simple function that converts your string inputs into the numpy format that the onnxruntime session expects:

tokenizer = ...

def prepare_for_session(input: str):
    tokens = tokenizer(input, return_tensors="pt") 
    return {k: v.cpu().detach().numpy() for k, v in tokens.items()}

does this answer your question?