-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessor_bert.py
More file actions
34 lines (27 loc) · 1.32 KB
/
Copy pathprocessor_bert.py
File metadata and controls
34 lines (27 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from sentence_transformers import SentenceTransformer
import joblib
# Loading the pre-trained SentenceTransformer model
transformer_model = SentenceTransformer('all-MiniLM-L6-v2')
# Loading the pre-trained Logistic Regression classifier from models directory
clf_model = joblib.load('clf_models/logistic_regression.joblib')
def classify_with_bert(log_message):
# Converting the input log message into a dense numerical vector (embedding)
msg_embedding = transformer_model.encode([log_message])
# Predicting the class of the log message using the embedding
probabilities = clf_model.predict_proba(msg_embedding)[0]
if max(probabilities) < 0.5:
return "Unclassified"
predicted_label = clf_model.predict(msg_embedding)[0]
return predicted_label
if __name__ == "__main__":
logs = [
"alpha.osapi_compute.wsgi.server - 12.10.11.1 - API returned 404 not found error",
"GET /v2/3454/servers/detail HTTP/1.1 RCODE 404 len: 1583 time: 0.1878400",
"System crashed due to drivers errors when restarting the server",
"Hey bro, chill ya!",
"Multiple login failures occurred on user 6454 account",
"Server A790 was restarted unexpectedly during the process of data transfer"
]
for log in logs:
label = classify_with_bert(log)
print(log, "->", label)