Text Classification
Transformers
Safetensors
PyTorch
English
tiny_log_classifier
cybersecurity
blue-team
log-analysis
custom-code
custom_code
Instructions to use mozarilla/tiny-blue-log-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mozarilla/tiny-blue-log-classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="mozarilla/tiny-blue-log-classifier", trust_remote_code=True)# Load model directly from transformers import AutoModelForSequenceClassification model = AutoModelForSequenceClassification.from_pretrained("mozarilla/tiny-blue-log-classifier", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
| import argparse | |
| import json | |
| from pathlib import Path | |
| import torch | |
| from transformers import AutoModelForSequenceClassification, AutoTokenizer | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Classify a text log file one line at a time.") | |
| parser.add_argument("model", help="Local model directory or Hugging Face repo id") | |
| parser.add_argument("input", help="Input text log file") | |
| parser.add_argument("--output", default="classified.jsonl") | |
| parser.add_argument("--threshold", type=float, default=0.5) | |
| args = parser.parse_args() | |
| torch.set_num_threads(2) | |
| tokenizer = AutoTokenizer.from_pretrained(args.model, trust_remote_code=True) | |
| model = AutoModelForSequenceClassification.from_pretrained(args.model, trust_remote_code=True) | |
| model.eval() | |
| input_path = Path(args.input) | |
| output_path = Path(args.output) | |
| with input_path.open("r", encoding="utf-8", errors="replace") as src, output_path.open("w", encoding="utf-8") as dst: | |
| for line_no, raw in enumerate(src, 1): | |
| text = raw.rstrip("\r\n") | |
| if not text: | |
| continue | |
| encoded = tokenizer(text, return_tensors="pt", truncation=True, max_length=96) | |
| with torch.inference_mode(): | |
| probs = torch.softmax(model(**encoded).logits, dim=-1)[0] | |
| suspicious = float(probs[1]) | |
| label = "SUSPICIOUS" if suspicious >= args.threshold else "BENIGN" | |
| dst.write(json.dumps({ | |
| "line": line_no, | |
| "label": label, | |
| "suspicious_probability": round(suspicious, 6), | |
| "text": text, | |
| }) + "\n") | |
| print(f"Wrote {output_path}") | |
| if __name__ == "__main__": | |
| main() | |