Download src/router_utils.py from irthayag/eva-assistant-assets: direct link, hf CLI and curl.
- Browser
- Download file 662 Bytes
-
https://huggingface.co/datasets/irthayag/eva-assistant-assets/resolve/main/src/router_utils.py
- Command line
-
hf download hf://datasets/irthayag/eva-assistant-assets/src/router_utils.py
-
curl -L -o router_utils.py https://huggingface.co/datasets/irthayag/eva-assistant-assets/resolve/main/src/router_utils.py
662 Bytes
| """ | |
| Enterprise Knowledge Assistant - Query Router | |
| Uses fine-tuned DistilBERT to classify queries into HR/Legal/Finance/IT domains. | |
| """ | |
| import torch | |
| def classify_query(query, model, tokenizer, label_encoder): | |
| inputs = tokenizer(query, return_tensors="pt", truncation=True, padding=True, max_length=64) | |
| with torch.no_grad(): | |
| outputs = model(**inputs) | |
| predicted_class = torch.argmax(outputs.logits, dim=1).item() | |
| predicted_domain = label_encoder.inverse_transform([predicted_class])[0] | |
| probs = torch.nn.functional.softmax(outputs.logits, dim=1)[0] | |
| confidence = probs[predicted_class].item() | |
| return predicted_domain, confidence | |