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 | |
| import torch | |
| from transformers import AutoModelForSequenceClassification, AutoTokenizer | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("model", help="Local model directory or Hugging Face repo id") | |
| parser.add_argument("text", nargs="?", default="EventID=4625 Failed logon user=administrator source_ip=203.0.113.44 count=17") | |
| 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() | |
| encoded = tokenizer( | |
| args.text, | |
| return_tensors="pt", | |
| truncation=True, | |
| max_length=96, | |
| padding=False, | |
| ) | |
| with torch.inference_mode(): | |
| logits = model(**encoded).logits | |
| probs = torch.softmax(logits, dim=-1)[0] | |
| idx = int(probs.argmax().item()) | |
| print(json.dumps({ | |
| "label": model.config.id2label[idx], | |
| "confidence": round(float(probs[idx]), 6), | |
| "text": args.text, | |
| }, indent=2)) | |
| if __name__ == "__main__": | |
| main() | |