This project uses LLMs to analyze and classify large-scale network logs (normal/abnormal). It features an embedding-based deduplication, multi-round labeling via LLaMA 70B, and fine-tuning on a cleaned dataset.
Note:: These commands are ONLY tested on Linux Ubuntu 22.04
git clone https://github.com/tjzvbokbnft/llm-for-network-log-analysis.git
cd llm-for-network-log-analysis
You have two options for the base model and LoRA adapter:
- Base Model:
meta-llama/Llama-3.2-1B-Instruct - LoRA Adapter:
Sean073/LogAnalyzer-LLaMA-3.2-1B-Instruct-v1
- Base Model:
meta-llama/Llama-3.2-3B-Instruct - LoRA Adapter:
Sean073/LogAnalyzer-LLaMA-3.2-3B-Instruct-v1
Note before using:
There are a few config parameters you should be aware of. These are defined inconfig.pyand must be manually set before running the tool:
config = {
"checkpoint_src": "huggingface", # Choose from: local, huggingface, ollama, or None
"baseModel": "meta-llama/Llama-3.2-1B-Instruct", # Base model from Hugging Face
"loraAdapter": "Sean073/LogAnalyzer-LLaMA-3.2-1B-Instruct-v1", # LoRA adapter from Hugging Face
"modelID": "Llama-3.2-1B-Instruct-finetuned" # Name used to label the output file in the UserRET/ folder
}chmod +x setup.sh
./setup.sh
python log_tool.py #This is an interactive script, you can input the path of your own log with .log or .txt format.
chmod +x setup.sh
./setup.sh
python log_tool_cli.py \
--logPath /home/siyuan/Projects/llmFor5Gsecurity/archived/testlog.txt \
--checkpoint_src huggingface \
--baseModel meta-llama/Llama-3.2-1B-Instruct \
--loraAdapter Sean073/LogAnalyzer-LLaMA-3.2-1B-Instruct-v1 \
--modelID Llama-3.2-1B-Instruct-finetuned
chmod +x setup.sh
./setup.sh
To use as a Python module, import the function as follows:
Note: Remember to set your configuration in the config.py
from checkpoint_api import send
resp=send("Input log one by one here")
Note: Please update the model and adapter settings in
config.pybefore running. By default, the following commands will reproduce results using the 1B version of the model:
chmod +x setup.sh
./setup.sh
python validate_llama.py
flowchart TD
A["Start: Raw logs"] --> B["Deduplication"]
B --> B1["Embed logs (17M+)"]
B1 --> B2["Remove duplicates (cos > 0.95)"]
B2 --> C["Labeling"]
C --> C1["LLaMA 70B x10 voting"]
C1 --> C2["≥ 9/10 votes agree?"]
C2 -->|Yes| C3["Accept"]
C2 -->|No| C4["Hard cases → DeepSeek"]
C3 --> D["Split & Train"]
C4 --> D
D --> D1["Train/Test Split"]
D1 --> D2["Fine-tune LLaMA 3.2"]
-
Deduplication
- Process 17M+ logs with embedding model nomic-embed-text:latest
- Remove near-duplicates via cosine similarity > 0.95
- Check for more details in
deduplicate_for_original.py
-
Labeling
- Use LLaMA 70B to label each log 10 times
- Accept label if ≥9/10 votes agree
- Else → add to hard case set → handled by DeepSeek LLM
- Check for more details in
relabel_vote.py
-
Split & Train
- Split labeled data into train/test sets
- Fine-tune LLaMA 3.2 1B and 3B on the final dataset
- Check for the dataset via this path:
finetune/dataset/train_instruct.jsonandfinetune/dataset/test.json
| Model | ACC Before Finetune (Ollama) | ACC Before Finetune (Hugging Face) | ACC After Finetune (Hugging Face) | Improvement |
|---|---|---|---|---|
| LLaMA-3.1-8B | 77.90% | 96.47% | N/A | N/A |
| LLaMA-3.2-3B | 55.13% | 90.55% | 98.63% | +43.50% (vs Ollama) / +8.08% (vs HF) |
| LLaMA-3.2-1B | 13.55% | 89.29% | 96.92% | +83.37% (vs Ollama) / +7.63% (vs HF) |
Note:
- We first evaluated the models directly from Ollama and Hugging Face without any fine-tuning to compare their out-of-the-box performance.
- We then applied LoRA fine-tuning on the Hugging Face models to assess their performance improvement.
- Ollama models showed significantly lower accuracy compared to their Hugging Face counterparts before fine-tuning.
- LoRA fine-tuning further improved performance on Hugging Face models, especially for smaller parameter models like LLaMA-3.2-1B.
-
Mac Studio (Apple Silicon)
- Chip: M2 Ultra
- Unified Memory: 192 GB
- Used for: Running LLaMA 70B and Ollama related experiments
-
PC with NVIDIA GPU
- GPU: RTX 4070 Ti Super (16 GB VRAM)
- Used for: All other experiments, including LoRA training, smaller LLMs, and classification tasks
Note:
- M2 Ultra’s large unified memory enables efficient inference for extremely large models like LLaMA 70B.
- 4070 Ti Super is sufficient for medium-scale experiments and fine-tuning tasks such as LoRA.
This project is licensed under the terms of the MIT License, which permits reuse, modification, and distribution with proper attribution. Please review the LICENSE file for detailed terms and conditions.