add usage example
Browse files
README.md
CHANGED
@@ -18,3 +18,31 @@ between english and English.
|
|
18 |
# Original implementation
|
19 |
|
20 |
Follow [this link](https://huggingface.co/bert-base-uncased) to see the original implementation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Original implementation
|
19 |
|
20 |
Follow [this link](https://huggingface.co/bert-base-uncased) to see the original implementation.
|
21 |
+
|
22 |
+
# How to use
|
23 |
+
|
24 |
+
Download the model by cloning the repository via `git clone https://huggingface.co/OWG/bert-base-uncased`.
|
25 |
+
|
26 |
+
Then you can use the model with the following code:
|
27 |
+
|
28 |
+
```python
|
29 |
+
from onnxruntime import InferenceSession, SessionOptions, GraphOptimizationLevel
|
30 |
+
from transformers import BertTokenizer
|
31 |
+
|
32 |
+
|
33 |
+
tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")
|
34 |
+
|
35 |
+
options = SessionOptions()
|
36 |
+
options.graph_optimization_level = GraphOptimizationLevel.ORT_ENABLE_ALL
|
37 |
+
|
38 |
+
session = InferenceSession("path/to/model.onnx", sess_options=options)
|
39 |
+
session.disable_fallback()
|
40 |
+
|
41 |
+
text = "Replace me by any text you want to encode."
|
42 |
+
input_ids = tokenizer(text, return_tensors="pt", return_attention_mask=True)
|
43 |
+
|
44 |
+
inputs = {k: v.cpu().detach().numpy() for k, v in input_ids.items()}
|
45 |
+
outputs_name = session.get_outputs()[0].name
|
46 |
+
|
47 |
+
outputs = session.run(output_names=[outputs_name], input_feed=inputs)
|
48 |
+
```
|