in src/infer_intent.py [0:0]
def __init__(self):
self.id2label = {0: 'information_intent',
1: 'yelp_intent',
2: 'navigation_intent',
3: 'travel_intent',
4: 'purchase_intent',
5: 'weather_intent',
6: 'translation_intent',
7: 'unknown'}
self.label2id = {label: id for id, label in self.id2label.items()}
self.tokenizer = AutoTokenizer.from_pretrained("Mozilla/mobilebert-uncased-finetuned-LoRA-intent-classifier")
model_url = "https://huggingface.co/Mozilla/mobilebert-uncased-finetuned-LoRA-intent-classifier/resolve/main/onnx/model_quantized.onnx"
model_dir_path = "models"
model_path = f"{model_dir_path}/mobilebert-uncased-finetuned-LoRA-intent-classifier_model_quantized.onnx"
if not os.path.exists(model_dir_path):
os.makedirs(model_dir_path)
if not os.path.exists(model_path):
print("Downloading ONNX model...")
response = requests.get(model_url)
with open(model_path, "wb") as f:
f.write(response.content)
print("ONNX model downloaded.")
# Load the ONNX model
self.ort_session = ort.InferenceSession(model_path)