Table of Contents
Fetching ...

LogLLaMA: Transformer-based log anomaly detection with LLaMA

Zhuoyi Yang, Ian G. Harris

TL;DR

LogLLaMA tackles log anomaly detection by adapting a transformer-based foundation model (LLaMA2) to system logs. It preprocesses logs with the Drain parser into log keys, fine-tunes on normal sequences, and applies reinforcement learning with Top-K sampling and entropy bonuses to detect anomalies. Across BGL, Thunderbird, and HDFS, it achieves state-of-the-art F1 scores, with ablation confirming the RL component strengthens performance. The approach demonstrates the value of tailoring LLMs to structured log data and integrating policy-gradient RL for robust, scalable anomaly detection in large-scale systems.

Abstract

Log anomaly detection refers to the task that distinguishes the anomalous log messages from normal log messages. Transformer-based large language models (LLMs) are becoming popular for log anomaly detection because of their superb ability to understand complex and long language patterns. In this paper, we propose LogLLaMA, a novel framework that leverages LLaMA2. LogLLaMA is first finetuned on normal log messages from three large-scale datasets to learn their patterns. After finetuning, the model is capable of generating successive log messages given previous log messages. Our generative model is further trained to identify anomalous log messages using reinforcement learning (RL). The experimental results show that LogLLaMA outperforms the state-of-the-art approaches for anomaly detection on BGL, Thunderbird, and HDFS datasets.

LogLLaMA: Transformer-based log anomaly detection with LLaMA

TL;DR

LogLLaMA tackles log anomaly detection by adapting a transformer-based foundation model (LLaMA2) to system logs. It preprocesses logs with the Drain parser into log keys, fine-tunes on normal sequences, and applies reinforcement learning with Top-K sampling and entropy bonuses to detect anomalies. Across BGL, Thunderbird, and HDFS, it achieves state-of-the-art F1 scores, with ablation confirming the RL component strengthens performance. The approach demonstrates the value of tailoring LLMs to structured log data and integrating policy-gradient RL for robust, scalable anomaly detection in large-scale systems.

Abstract

Log anomaly detection refers to the task that distinguishes the anomalous log messages from normal log messages. Transformer-based large language models (LLMs) are becoming popular for log anomaly detection because of their superb ability to understand complex and long language patterns. In this paper, we propose LogLLaMA, a novel framework that leverages LLaMA2. LogLLaMA is first finetuned on normal log messages from three large-scale datasets to learn their patterns. After finetuning, the model is capable of generating successive log messages given previous log messages. Our generative model is further trained to identify anomalous log messages using reinforcement learning (RL). The experimental results show that LogLLaMA outperforms the state-of-the-art approaches for anomaly detection on BGL, Thunderbird, and HDFS datasets.

Paper Structure

This paper contains 11 sections, 7 equations, 5 figures, 1 table.

Figures (5)

  • Figure 1: Module 1: Log message preprocessing
  • Figure 2: Module 2: Model finetuning
  • Figure 3: Module 3: Anomaly detection with RL
  • Figure 4: An example of log messages, log templates, and log keys on BGL dataset. The variants are stripped off by the log parser
  • Figure 5: Top-K Selection