from transformers import pipeline # Load sentiment-analysis model def load_model(): return pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english") # Predict anomaly for each log line def detect_anomaly(model, logs): results = model(logs) predictions = [] for result in results: # Treat negative sentiment as Anomaly, positive/neutral as Normal if result['label'] == 'NEGATIVE': predictions.append("Anomaly") else: predictions.append("Normal") return predictions