Jarbas commited on
Commit
7fbfbd3
·
1 Parent(s): 842eb14

fix: correct ONNX inference example — TF-IDF is embedded, pass raw strings directly

Browse files
Files changed (1) hide show
  1. README.md +11 -15
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 numpy as np
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
- input_name = sess.get_inputs()[0].name
113
- label_name = sess.get_outputs()[0].name
114
-
115
- # Create vectorizer (same parameters as training)
116
- vectorizer = TfidfVectorizer(analyzer="word", ngram_range=(1, 2),
117
- min_df=1, max_df=0.9, sublinear_tf=True)
118
-
119
- # Predict
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