This repository contains the ONNX and ORT formats of the model
google-bert/bert-base-german-dbmdz-uncased, along with quantized versions.
The license for this model is "mit". For details, please refer to the original model page:
google-bert/bert-base-german-dbmdz-uncased.
To use this model, install ONNX Runtime and perform inference as shown below.
1# Example code
2import onnxruntime as ort
3import numpy as np
4from transformers import AutoTokenizer
5import os
6
7# Load the tokenizer
8tokenizer = AutoTokenizer.from_pretrained('google-bert/bert-base-german-dbmdz-uncased')
9
10# Prepare inputs
11text = 'Replace this text with your input.'
12inputs = tokenizer(text, return_tensors='np')
13
14# Specify the model paths
15# Test both the ONNX model and the ORT model
16model_paths = [
17 'onnx_models/model_opt.onnx', # ONNX model
18 'ort_models/model.ort' # ORT format model
19]
20
21# Run inference with each model
22for model_path in model_paths:
23 print(f'\n===== Using model: {model_path} =====')
24 # Get the model extension
25 model_extension = os.path.splitext(model_path)[1]
26
27 # Load the model
28 if model_extension == '.ort':
29 # Load the ORT format model
30 session = ort.InferenceSession(model_path, providers=['CPUExecutionProvider'])
31 else:
32 # Load the ONNX model
33 session = ort.InferenceSession(model_path)
34
35 # Run inference
36 outputs = session.run(None, dict(inputs))
37
38 # Display the output shapes
39 for idx, output in enumerate(outputs):
40 print(f'Output {idx} shape: {output.shape}')
41
42 # Display the results (add further processing if needed)
43 print(outputs)
Please adhere to the license and usage conditions of the original model
google-bert/bert-base-german-dbmdz-uncased.
If you find any issues or have improvements, please create an issue or submit a pull request.