fix: correct ONNX inference example — TF-IDF is embedded, pass raw strings directly
Browse files
README.md
CHANGED
|
@@ -102,25 +102,21 @@ Keyword lists (WH starters, command verbs, polite modals, negation words) are lo
|
|
| 102 |
|
| 103 |
### ONNX Inference (Recommended)
|
| 104 |
|
|
|
|
|
|
|
| 105 |
```python
|
| 106 |
import onnxruntime as rt
|
| 107 |
-
import
|
| 108 |
-
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 109 |
|
| 110 |
-
# Load ONNX model
|
| 111 |
sess = rt.InferenceSession("sentence_type_EN_0.8.0.onnx")
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
#
|
| 120 |
-
text = "Could you pass the salt?"
|
| 121 |
-
vec = vectorizer.transform([text]).toarray().astype(np.float32)
|
| 122 |
-
pred = sess.run([label_name], {input_name: vec})
|
| 123 |
-
print(pred) # e.g., [2] → class index
|
| 124 |
```
|
| 125 |
|
| 126 |
## License
|
|
|
|
| 102 |
|
| 103 |
### ONNX Inference (Recommended)
|
| 104 |
|
| 105 |
+
The ONNX model is a full pipeline — TF-IDF featurisation is embedded. Pass raw text strings directly; no vectorizer setup needed.
|
| 106 |
+
|
| 107 |
```python
|
| 108 |
import onnxruntime as rt
|
| 109 |
+
import json
|
|
|
|
| 110 |
|
|
|
|
| 111 |
sess = rt.InferenceSession("sentence_type_EN_0.8.0.onnx")
|
| 112 |
+
|
| 113 |
+
# Class labels are stored in model metadata
|
| 114 |
+
classes = json.loads(sess.get_modelmeta().custom_metadata_map["classes"])
|
| 115 |
+
|
| 116 |
+
texts = ["Could you pass the salt?", "What time is it?", "Close the door."]
|
| 117 |
+
pred_indices = sess.run(None, {"input": texts})[0]
|
| 118 |
+
print([classes[i] for i in pred_indices])
|
| 119 |
+
# → ['request', 'wh_question', 'command']
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
```
|
| 121 |
|
| 122 |
## License
|