Update README.md
Browse files
README.md
CHANGED
|
@@ -3,7 +3,13 @@ library_name: transformers
|
|
| 3 |
license: apache-2.0
|
| 4 |
base_model: distilbert-base-uncased
|
| 5 |
tags:
|
| 6 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
metrics:
|
| 8 |
- accuracy
|
| 9 |
- f1
|
|
@@ -14,60 +20,120 @@ model-index:
|
|
| 14 |
results: []
|
| 15 |
---
|
| 16 |
|
| 17 |
-
|
| 18 |
-
should probably proofread and complete it, then remove this comment. -->
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
|
|
|
| 35 |
|
| 36 |
-
##
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
|
| 41 |
-
#
|
|
|
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
#
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
The model was fine-tuned using the Hugging Face Trainer API for binary text classification. It was trained for 3 epochs with a batch size of 16, using the AdamW optimizer and a linear learning rate scheduler. The dataset was tokenized with distilbert-base-uncased, and evaluation was performed on a validation split using metrics like accuracy, precision, recall, and F1-score.
|
| 48 |
|
| 49 |
-
##
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
- eval_batch_size: 16
|
| 55 |
-
- seed: 42
|
| 56 |
-
- optimizer: Use OptimizerNames.ADAMW_TORCH with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
|
| 57 |
-
- lr_scheduler_type: linear
|
| 58 |
-
- num_epochs: 3
|
| 59 |
|
| 60 |
-
#
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
| 0.0 | 3.0 | 10125 | 0.0000 | 1.0 | 1.0 | 1.0 | 1.0 |
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
| 3 |
license: apache-2.0
|
| 4 |
base_model: distilbert-base-uncased
|
| 5 |
tags:
|
| 6 |
+
- text-classification
|
| 7 |
+
- binary-classification
|
| 8 |
+
- cybersecurity
|
| 9 |
+
- wireshark
|
| 10 |
+
- distilbert
|
| 11 |
+
- transformers
|
| 12 |
+
- huggingface
|
| 13 |
metrics:
|
| 14 |
- accuracy
|
| 15 |
- f1
|
|
|
|
| 20 |
results: []
|
| 21 |
---
|
| 22 |
|
| 23 |
+
# π§ results β DistilBERT for Malicious Traffic Classification
|
|
|
|
| 24 |
|
| 25 |
+
This model is a fine-tuned version of [`distilbert-base-uncased`](https://huggingface.co/distilbert-base-uncased) for **binary classification of network traffic**, especially useful for distinguishing **malicious vs. benign** packets based on preprocessed Wireshark-style logs.
|
| 26 |
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
## π Evaluation Results
|
| 30 |
+
|
| 31 |
+
| Metric | Value |
|
| 32 |
+
|-------------|-------|
|
| 33 |
+
| Accuracy | 1.0 |
|
| 34 |
+
| Precision | 1.0 |
|
| 35 |
+
| Recall | 1.0 |
|
| 36 |
+
| F1 Score | 1.0 |
|
| 37 |
+
| Eval Loss | 0.0000 |
|
| 38 |
+
|
| 39 |
+
> β οΈ These perfect results are on the validation set and may not generalize to unseen or noisy real-world data. Be sure to test on diverse inputs.
|
| 40 |
+
|
| 41 |
+
---
|
| 42 |
+
|
| 43 |
+
## π§© Model Description
|
| 44 |
+
|
| 45 |
+
This model uses the lightweight and efficient **DistilBERT** transformer, fine-tuned for binary classification. Input data should be short text sequences (e.g., protocol descriptions, IP headers, or Wireshark logs).
|
| 46 |
+
|
| 47 |
+
---
|
| 48 |
+
|
| 49 |
+
## π‘ Intended Use & Limitations
|
| 50 |
+
|
| 51 |
+
### β
Intended Uses
|
| 52 |
|
| 53 |
+
- **Malicious traffic detection** (from packet text)
|
| 54 |
+
- **Intrusion detection system (IDS)** aid
|
| 55 |
+
- Sentiment analysis or spam detection (if retrained)
|
| 56 |
|
| 57 |
+
### β Limitations
|
| 58 |
|
| 59 |
+
- English and network-related text only
|
| 60 |
+
- Binary classification (0 = benign, 1 = malicious)
|
| 61 |
+
- Not trained on raw PCAPs β requires preprocessing
|
| 62 |
+
|
| 63 |
+
---
|
| 64 |
+
|
| 65 |
+
## ποΈ Training Procedure
|
| 66 |
+
|
| 67 |
+
- Model: `distilbert-base-uncased`
|
| 68 |
+
- Framework: `Transformers` Trainer API
|
| 69 |
+
- Optimizer: AdamW
|
| 70 |
+
- Scheduler: Linear LR decay
|
| 71 |
+
- Epochs: 3
|
| 72 |
+
- Batch Size: 16
|
| 73 |
+
- Seed: 42
|
| 74 |
+
|
| 75 |
+
---
|
| 76 |
+
|
| 77 |
+
## π Training and Evaluation Data
|
| 78 |
+
|
| 79 |
+
The model was trained on a custom dataset with binary labels:
|
| 80 |
+
- `input`: stringified packet details (e.g., IPs, protocol, flags)
|
| 81 |
+
- `BinaryLabel`: `0` = benign, `1` = malicious
|
| 82 |
+
|
| 83 |
+
Text was tokenized using the DistilBERT tokenizer with truncation and padding.
|
| 84 |
+
|
| 85 |
+
---
|
| 86 |
|
| 87 |
+
## π§ͺ Example Usage
|
| 88 |
|
| 89 |
+
### π Hugging Face Pipeline (Single Prediction)
|
| 90 |
|
| 91 |
+
```python
|
| 92 |
+
from transformers import pipeline
|
| 93 |
|
| 94 |
+
# Load from Hugging Face Hub
|
| 95 |
+
classifier = pipeline("text-classification", model="TanmaySK/results")
|
| 96 |
|
| 97 |
+
# Predict
|
| 98 |
+
text = "SrcIP:10.0.0.1 DstIP:192.168.1.1 Protocol:TCP Flags:SYN"
|
| 99 |
+
result = classifier(text)
|
| 100 |
|
| 101 |
+
# Interpret label
|
| 102 |
+
label_map = {"LABEL_0": "Benign", "LABEL_1": "Malicious"}
|
| 103 |
+
print(f"Prediction: {label_map[result[0]['label']]} (Confidence: {result[0]['score']:.4f})")
|
| 104 |
|
|
|
|
| 105 |
|
| 106 |
+
## π CSV Batch Prediction (Local Wireshark Data)
|
| 107 |
+
import pandas as pd
|
| 108 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 109 |
+
import torch
|
| 110 |
|
| 111 |
+
# Load model
|
| 112 |
+
model = AutoModelForSequenceClassification.from_pretrained("TanmaySK/results")
|
| 113 |
+
tokenizer = AutoTokenizer.from_pretrained("TanmaySK/results")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
+
# Device setup
|
| 116 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 117 |
+
model.to(device)
|
| 118 |
+
model.eval()
|
| 119 |
|
| 120 |
+
# Load CSV
|
| 121 |
+
df = pd.read_csv("wireshark_unlabeled.csv") # Must have 'input' column
|
| 122 |
+
label_map = {0: "Benign", 1: "Malicious"}
|
| 123 |
+
predictions = []
|
|
|
|
| 124 |
|
| 125 |
+
# Predict each row
|
| 126 |
+
for text in df["input"]:
|
| 127 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
|
| 128 |
+
inputs = {k: v.to(device) for k, v in inputs.items() if k != "token_type_ids"}
|
| 129 |
|
| 130 |
+
with torch.no_grad():
|
| 131 |
+
logits = model(**inputs).logits
|
| 132 |
+
pred = torch.argmax(logits, dim=1).item()
|
| 133 |
+
predictions.append(pred)
|
| 134 |
|
| 135 |
+
# Save results
|
| 136 |
+
df["PredictedLabel"] = predictions
|
| 137 |
+
df["PredictionText"] = [label_map[p] for p in predictions]
|
| 138 |
+
df.to_csv("wireshark_predictions.csv", index=False)
|
| 139 |
+
print("β
Saved to wireshark_predictions.csv")
|