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 torch | |
| from torch import nn | |
| from transformers import PreTrainedModel | |
| from transformers.modeling_outputs import SequenceClassifierOutput | |
| from .configuration_tiny_log import TinyLogConfig | |
| class TinyLogPreTrainedModel(PreTrainedModel): | |
| config_class = TinyLogConfig | |
| base_model_prefix = "tiny_log" | |
| main_input_name = "input_ids" | |
| class TinyLogForSequenceClassification(TinyLogPreTrainedModel): | |
| def __init__(self, config): | |
| super().__init__(config) | |
| self.embedding = nn.Embedding( | |
| config.vocab_size, | |
| config.hidden_size, | |
| padding_idx=config.pad_token_id, | |
| ) | |
| self.classifier = nn.Linear(config.hidden_size, config.num_labels) | |
| self.post_init() | |
| def forward( | |
| self, | |
| input_ids=None, | |
| attention_mask=None, | |
| labels=None, | |
| return_dict=None, | |
| **kwargs, | |
| ): | |
| if input_ids is None: | |
| raise ValueError("input_ids is required") | |
| if attention_mask is None: | |
| attention_mask = input_ids.ne(self.config.pad_token_id).long() | |
| embeddings = self.embedding(input_ids) | |
| mask = attention_mask.unsqueeze(-1).to(embeddings.dtype) | |
| summed = (embeddings * mask).sum(dim=1) | |
| denom = mask.sum(dim=1).clamp(min=1.0) | |
| pooled = summed / denom | |
| logits = self.classifier(pooled) | |
| loss = None | |
| if labels is not None: | |
| loss = nn.CrossEntropyLoss()(logits, labels) | |
| if return_dict is False: | |
| output = (logits,) | |
| return ((loss,) + output) if loss is not None else output | |
| return SequenceClassifierOutput(loss=loss, logits=logits) | |