github yzhao062/pyod v2.1.0

7 hours ago

PyOD v2.1.0: Multi-Modal Anomaly Detection via Foundation Model Embeddings

Highlights

  • EmbeddingOD: Chain any embedding encoder (sentence-transformers, OpenAI, HuggingFace, or custom callable) with any of PyOD's 50+ detectors for text and image anomaly detection. Implements the two-step approach validated by NLP-ADBench (EMNLP 2025).

  • Benchmark-informed presets: EmbeddingOD.for_text() and EmbeddingOD.for_image() with quality tiers (fast/balanced/best) based on NLP-ADBench and AnomalyDINO results.

  • MultiModalEncoder (early fusion): Encode multiple modalities (text + image + tabular) and concatenate embeddings. Supports per-sample missing data via mean imputation from training.

  • MultiModalOD (score fusion): Run a separate detector per modality, standardize scores with training-time scalers, and combine via average/maximization/median. Missing modalities at test time are imputed with the training mean score.

  • Documentation cleanup: README and ReadTheDocs updated with EmbeddingOD examples, compacted resource links, shortened API reference (removed inherited members from 40+ model pages), and full EmbeddingOD walkthrough in docs/example.rst.

Install

pip install pyod --upgrade

# For text anomaly detection:
pip install pyod sentence-transformers

# For image anomaly detection:
pip install pyod transformers torch

Quick Start

from pyod.models.embedding import EmbeddingOD

# Text anomaly detection in 3 lines
clf = EmbeddingOD(encoder='all-MiniLM-L6-v2', detector='KNN')
clf.fit(train_texts)
labels = clf.predict(test_texts)

# Or use a preset
clf = EmbeddingOD.for_text(quality='fast')

Multi-Modal Example

from pyod.models.embedding import EmbeddingOD, MultiModalOD
from pyod.models.knn import KNN

clf = MultiModalOD(modalities={
    'text': EmbeddingOD(encoder='all-MiniLM-L6-v2', detector='KNN'),
    'tabular': KNN(),
}, combination='average')

clf.fit({'text': train_texts, 'tabular': X_train})
scores = clf.decision_function({'text': test_texts, 'tabular': X_test})

References

  • NLP-ADBench (Li et al., EMNLP 2025): Two-step approach outperforms end-to-end methods
  • TAD-Bench (Cao et al., 2025): Confirmed across 8 embeddings x 8 detectors
  • AD-LLM (Yang et al., ACL 2025): LLM-based anomaly detection benchmark
  • AnomalyDINO (WACV 2025): DINOv2 + KNN for image anomaly detection

Don't miss a new pyod release

NewReleases is sending notifications on new releases.