Skip to content

RoBERTa Classifier

A RoBERTa sequence classifier (AutoModelForSequenceClassification) assigns a priority (P1–P4) to each new log template. The model runs in-process inside the pipeline and is loaded once at startup.


Architecture

Property Value
Model class transformers.AutoModelForSequenceClassification
Tokenizer transformers.AutoTokenizer
Labels {0: P1, 1: P2, 2: P3, 3: P4}
Max sequence length 512 tokens (truncated + padded)
Inference mode model.eval() + torch.no_grad()
Precision Default (FP32; ONNX export planned)
Path /app/model/log_priority_roberta (copied by Dockerfile)

Load-once Strategy

class MLClassifier:
    def load(self) -> bool:
        self._tokenizer = AutoTokenizer.from_pretrained(self._model_path)
        self._model = AutoModelForSequenceClassification.from_pretrained(self._model_path)
        self._model.eval()
        self._loaded = True

The model is instantiated once in the pipeline process and shared across all events — no per-event model loading.


Prediction

def predict(self, text: str) -> dict | None:
    inputs = self._tokenizer(text, return_tensors="pt",
                             truncation=True, padding=True, max_length=512)
    with torch.no_grad():
        output = self._model(**inputs)
        probs = torch.softmax(output.logits, dim=1)
        confidence, idx = torch.max(probs, dim=1)
    return {
        "priority": self._labels[idx.item()],
        "confidence": round(confidence.item(), 4),
    }

The returned confidence is the softmax probability of the winning class — a human-readable trust signal stored as priority_confidence.


Classification Flow

flowchart LR
  T[NEW template text] --> TOK[Tokenize<br/>512 max]
  TOK --> INF[RoBERTa forward<br/>no_grad]
  INF --> SOFT[softmax]
  SOFT --> MAX[max class]
  MAX --> P[priority + confidence]
  P --> CACHE[template_priority + Redis]

Fallback Behavior

Condition Outcome
Model not loaded (is_loaded == False) predict() returns None
Inference exception predict() returns None
None → caller severity_to_priority(severity_rank) rule fallback

The fallback map:

severity_rank severity priority
4 CRITICAL P1
3 ERROR P2
2 WARNING P3
1 INFO P3
0 DEBUG P4

Rule fallback sets priority_source = "rule" and confidence = 1.0.


Training Data

The model is fine-tuned on labeled log templates where each template carries a human-verified priority. See Labeling Pipeline for how ground truth is collected, and Priorities for class semantics.


Efficiency

Because classification happens per new template only (cache misses), ~99% of events bypass the model entirely. A cache hit costs <1 ms; a genuine inference ~2 ms.