in src/infer_intent.py [0:0]
def find_intent(self, sequence, verbose=False):
inputs = self.tokenizer(sequence,
return_tensors="np", # ONNX requires inputs in NumPy format
padding="max_length", # Pad to max length
truncation=True, # Truncate if the text is too long
max_length=64)
# Convert inputs to NumPy arrays
onnx_inputs = {k: v for k, v in inputs.items()}
# Run the ONNX model
logits = self.ort_session.run(None, onnx_inputs)[0]
# Get the prediction
prediction = np.argmax(logits, axis=1)[0]
probabilities = np.exp(logits) / np.sum(np.exp(logits), axis=1, keepdims=True)
rounded_probabilities = np.round(probabilities, decimals=3)
pred_result = self.id2label[prediction]
proba_result = dict(zip(self.label2id.keys(), rounded_probabilities[0].tolist()))
if verbose:
print(sequence + " -> " + pred_result)
print(proba_result, "\n")
return pred_result, proba_result