HagalazAI commited on
Commit
4fc7294
·
verified ·
1 Parent(s): 1f2e00c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +53 -21
README.md CHANGED
@@ -40,8 +40,6 @@ Detects **technical red-team / offensive security** text (English).
40
  * **Input language:** English.
41
  * **No external test set** yet → treat scores as optimistic.
42
 
43
- ---
44
-
45
  ## Training data
46
 
47
  | Label | Rows |
@@ -51,8 +49,6 @@ Detects **technical red-team / offensive security** text (English).
51
  | Other | 130 000 |
52
  | **Total** | **180 296** |
53
 
54
- ---
55
-
56
  ## Model details
57
 
58
  | Field | Value |
@@ -63,8 +59,6 @@ Detects **technical red-team / offensive security** text (English).
63
  | Hardware | 1× RTX 4090 (≈ 41 min) |
64
  | Inference dtype | FP16-safe |
65
 
66
- ---
67
-
68
  ## Training Data License
69
 
70
  - **Source**: [trendmicro-ailab/Primus-FineWeb](https://huggingface.co/datasets/trendmicro-ailab/Primus-FineWeb)
@@ -73,22 +67,60 @@ Detects **technical red-team / offensive security** text (English).
73
  - Preserve all original copyright/​license notices
74
  - Honor [Common Crawl ToU](https://commoncrawl.org/terms-of-use/)
75
 
76
- ---
77
-
78
  ## Quick start
79
 
80
  ```python
81
- from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
82
-
83
- model_id = "HagalazAI/RedSecureBERT"
84
- tok = AutoTokenizer.from_pretrained(model_id)
85
- model = AutoModelForSequenceClassification.from_pretrained(model_id)
86
-
87
- clf = pipeline("text-classification", model=model, tokenizer=tok, top_k=None)
88
-
89
- text = "Generate a ROP chain to bypass DEP on Windows 10."
90
- prob = clf(text)[0]["score"] # sigmoid prob for class 0 (Offensive)
91
- print(f"P(offensive) = {prob:.3f}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
- is_red = prob >= 0.515 # ← recommended threshold
94
- print("is_red:", is_red)
 
40
  * **Input language:** English.
41
  * **No external test set** yet → treat scores as optimistic.
42
 
 
 
43
  ## Training data
44
 
45
  | Label | Rows |
 
49
  | Other | 130 000 |
50
  | **Total** | **180 296** |
51
 
 
 
52
  ## Model details
53
 
54
  | Field | Value |
 
59
  | Hardware | 1× RTX 4090 (≈ 41 min) |
60
  | Inference dtype | FP16-safe |
61
 
 
 
62
  ## Training Data License
63
 
64
  - **Source**: [trendmicro-ailab/Primus-FineWeb](https://huggingface.co/datasets/trendmicro-ailab/Primus-FineWeb)
 
67
  - Preserve all original copyright/​license notices
68
  - Honor [Common Crawl ToU](https://commoncrawl.org/terms-of-use/)
69
 
 
 
70
  ## Quick start
71
 
72
  ```python
73
+ import torch
74
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
75
+
76
+ def classify_texts(model_name, phrases, threshold=0.515):
77
+ """
78
+ Returns a list of (probability_offensive, label) tuples for each phrase
79
+ given a model_name and threshold.
80
+ """
81
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
82
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
83
+ model.eval()
84
+
85
+ inputs = tokenizer(phrases, padding=True, truncation=True, return_tensors="pt")
86
+
87
+ with torch.no_grad():
88
+ logits = model(**inputs).logits # shape: (batch_size, 2)
89
+ probs_offensive = torch.softmax(logits, dim=1)[:, 1] # Probability of the "Offensive" class
90
+
91
+ results = []
92
+ for p_val in probs_offensive:
93
+ p_val = p_val.item()
94
+ label = "Offensive (red-team)" if p_val >= threshold else "Not Offensive"
95
+ results.append((p_val, label))
96
+ return results
97
+
98
+ def main():
99
+ # Example phrases: Offensive (red-team), Defensive (blue-team), Non-technical
100
+ phrases = [
101
+ # 1) Cybersecurity Offensive / red-team
102
+ "To exfiltrate sensitive data, launch a phishing campaign that tricks employees into revealing their VPN credentials.",
103
+ # 2) Cybersecurity Defensive / blue-team
104
+ "We should deploy an EDR solution, monitor all endpoints for intrusion attempts, and enforce strict password policies.",
105
+ # 5) Cybersecruity Marketing
106
+ "“Our marketing team will unveil the new cybersecurity branding materials at next Tuesday’s antivirus product launch",
107
+ # 5) Non Cybersecruity related
108
+ "I'm excited about the company picnic. There's no cybersecurity topic—just burgers and games."
109
+ ]
110
+
111
+ # Classify with both models
112
+ threshold = 0.515
113
+ blue_results = classify_texts("HagalazAI/BlueSecureBERT", phrases, threshold)
114
+ red_results = classify_texts("HagalazAI/RedSecureBERT", phrases, threshold)
115
+
116
+ # Print a Markdown table
117
+ print("| # | Phrase | Blue Score | Blue Label | Red Score | Red Label |")
118
+ print("|---|--------|-----------|-----------|----------|----------|")
119
+ for i, text in enumerate(phrases, start=1):
120
+ blue_score, blue_label = blue_results[i - 1]
121
+ red_score, red_label = red_results[i - 1]
122
+ print(f"| {i} | {text} | {blue_score:.3f} | {blue_label} | {red_score:.3f} | {red_label} |")
123
+
124
+ if __name__ == "__main__":
125
+ main()
126