LogBERT: Log Anomaly Detection via BERT

Haixuan Guo, Shuhan Yuan, Xintao Wu

TL;DR

This paper introduces LogBERT, a novel approach for detecting anomalous events in system logs by leveraging the power of BERT. By employing two self-supervised training tasks, LogBERT effectively learns normal log patterns and achieves state-of-the-art performance in identifying deviations that signal potential security threats or system malfunctions.

What Problem Does This Paper Address?

Online computer systems are constantly under threat from malicious attacks and unexpected malfunctions. A critical defense mechanism is the ability to detect these anomalous events in a timely manner. System logs, which meticulously record the details of computational events, are a rich source of information for understanding system behavior. However, analyzing these logs to pinpoint anomalies is challenging due to the sheer volume of data and the subtle nature of many attacks, where individual log entries might appear normal but their sequence is indicative of a problem. Traditional machine learning methods often struggle to capture the temporal dependencies within log sequences, and deep learning models like RNNs, while better, have limitations in fully encoding the context of each log entry.

Methods

The core innovation of this paper is LogBERT, a framework that adapts the Bidirectional Encoder Representations from Transformers (BERT) architecture for log anomaly detection. Unlike previous methods that might rely on supervised learning or simpler unsupervised techniques, LogBERT is trained using self-supervised learning on normal log sequences. This allows it to learn the intricate patterns of expected behavior without requiring labeled anomalous data during training.

LogBERT employs two novel self-supervised training tasks:

  1. Masked Log Key Prediction (MLKP): This task is inspired by BERT's masked language model objective. Log keys (structured templates extracted from raw log messages) within a normal log sequence are randomly masked, and LogBERT is trained to predict these masked keys based on their surrounding context. This forces the model to learn the bidirectional relationships and dependencies between log entries.
  2. Volume of Hypersphere Minimization (VHM): This task aims to cluster the representations of normal log sequences in an embedding space. By minimizing the volume of a hypersphere that encloses these representations, LogBERT encourages normal sequences to be close to each other, making it easier to identify sequences that fall outside this cluster as anomalous.

The combined objective function, a weighted sum of the losses from MLKP and VHM, allows LogBERT to learn a comprehensive understanding of normal log behavior.

Datasets

The proposed LogBERT framework was evaluated on three real-world log datasets:

  • HDFS: Generated from Hadoop MapReduce jobs on Amazon EC2 nodes, manually labeled for anomalies. Log sequences are formed by grouping log keys based on session IDs.
  • BGL (BlueGene/L): Collected from a supercomputer system at Lawrence Livermore National Labs. Logs contain alert and non-alert messages, with alerts considered anomalous. Log sequences are generated using a time sliding window.
  • Thunderbird-mini: A subset of a large log dataset from a supercomputer system. Log sequences are generated using a time sliding window.

The paper provides statistics on the number of log messages, anomalies, and unique log keys for each dataset, along with the number of normal and anomalous log sequences in the test set.

Key Insights and Ideas

  • BERT for Log Analysis: Adapting BERT, a powerful language model, to the domain of log anomaly detection proves highly effective, outperforming traditional and other deep learning methods.
  • Self-Supervised Learning is Key: The ability to learn from unlabeled normal log data is crucial for anomaly detection, where anomalous samples are often scarce and imbalanced.
  • Complementary Training Tasks: The combination of predicting masked log keys (capturing local dependencies) and minimizing the hypersphere volume (capturing global sequence similarity) provides a more robust representation of normal log behavior than either task alone.
  • Temporal Context Matters: LogBERT's success highlights the importance of capturing the full bidirectional context of log sequences, a strength of the Transformer architecture.

Key Results

LogBERT consistently outperformed several state-of-the-art baselines, including PCA, Isolation Forest, OCSVM, LogCluster, DeepLog, and LogAnomaly, across all three datasets. Notably, LogBERT achieved the highest F1 scores on all datasets, indicating a strong balance between precision and recall. For instance, on the HDFS dataset, LogBERT achieved an F1 score of 82.32, significantly outperforming other methods. Ablation studies showed that while MLKP alone provided good results, the combination with VHM further improved performance, especially for shorter log sequences. Visualization of log sequence embeddings also demonstrated that VHM effectively separates normal and anomalous sequences.

Limitations and Future Work

The authors acknowledge that the performance of LogBERT can be influenced by hyper-parameters, such as the weight of the VHM task and the ratio of masked log keys. They also note that for very long log sequences, the MLKP task might dominate, and the impact of VHM might be less pronounced.

Future work could explore more sophisticated methods for hyper-parameter tuning and investigate the optimal ratio of masked log keys for different types of log data. Further research could also focus on extending LogBERT to handle more complex anomaly types or to provide more detailed explanations for detected anomalies.

Summary updated

BibTeX
@inproceedings{guo2021logbert,
  author = {Haixuan Guo and Shuhan Yuan and Xintao Wu},
  title = {{LogBERT: Log Anomaly Detection via BERT}},
  booktitle = {IJCNN},
  year = {2021},
  url = {https://openreview.net/forum?id=9w-S2RlPPw},
}
Figure