/ Модель

Характеристики

Лицензия
MIT
Архитектура
clip-fusion · dense
Базовая модель
clip-vit-base-patch32
Библиотека
transformers
Опубликована
27 дек 2025

clip-vit-base-mmhs150k-fusion

Изображение и текст → текст3 профессии

Мультимодальная модель на базе CLIP для многометочного выявления категорий языка ненависти в англоязычных публикациях и мемах.

168скачиваний за 30 дней1лайквеса обновлены27 дек 2025

Бенчмарки

Как модель справилась с задачами пользователей ailist и что о ней публикуют открытые лидерборды

Публичные оценки

Из открытых лидербордов. Сравнивайте результаты одного теста при одинаковых условиях — отсутствие оценки не значит, что модель хуже.

В подключённых источниках результатов для этой модели пока нет.

Что умеет модель

Описание составлено по карточке модели и метаданным Hugging Face

Модель Amirhossein75/clip-vit-base-mmhs150k-fusion разработана для мультимодального выявления языка ненависти в публикациях и мемах из социальных сетей. Она объединяет изображение и текст с помощью позднего слияния признаков с gated attention; в основе — OpenAI CLIP ViT-Base-Patch32. Модель выполняет многометочную классификацию по пяти категориям языка ненависти, поэтому одна публикация может получить несколько меток.

Модель обучена на наборе MMHS150K с парами твитов и изображений. Максимальная длина текста — 77 токенов. Для тестовой выборки указаны F1 macro 0,566, F1 micro 0,635 и ROC-AUC macro 0,783. Она предназначена для поддержки модерации контента и предварительной фильтрации потенциально вредных публикаций с последующей проверкой человеком.

Модель рассчитана на английский язык и данные, похожие на Twitter; перенос на другие платформы может снизить качество. Особенно слабее распознаётся редкая категория «религия» (F1 0,283). Возможны ложные срабатывания и пропуски, поэтому результаты не следует использовать как окончательное решение о модерации. Лицензия — MIT.

Сценарии применения

  • поиск расистского содержания в мемах и публикациях
  • выявление сексистских публикаций с изображением и текстом
  • предварительная фильтрация гомофобных публикаций для проверки модератором
  • разметка публикаций по нескольким категориям языка ненависти
  • анализ мультимодального контента социальных сетей

Ограничения

Обучена только на английском контенте Twitter, поэтому может хуже работать на других языках и платформах; для редкой категории «религия» указано F1 0,283. Возможны ложные срабатывания и пропуски, поэтому результаты требуют проверки человеком.

Для каких профессий подходит3

Разделы каталога профессий, в задачах которых используется эта модель

Все профессии

Карточка модели

README от автора на Hugging Face, как он его опубликовал

Открыть на Hugging Face

CLIP-ViT-Base Fusion Model for Multi-Modal Hate Speech Detection

A PyTorch-based multi-modal (image + text) hateful content classification model using CLIP encoder with late fusion architecture, trained on the MMHS150K dataset for detecting hate speech in social media memes and posts.

🎯 Model Description

This model implements a late fusion architecture with gated attention mechanism for detecting hateful content in social media memes and posts. It combines visual and textual features using OpenAI's CLIP (ViT-Base-Patch32) as the backbone encoder.

The model performs multi-label classification across 5 hate speech categories, making it capable of detecting multiple types of hate in a single post (e.g., content that is both racist and sexist).

🏗️ Architecture

┌─────────────┐     ┌─────────────┐
│   Image     │     │    Text     │
│   Encoder   │     │   Encoder   │
│ (CLIP ViT)  │     │ (CLIP Text) │
└──────┬──────┘     └──────┬──────┘
       │                   │
       ▼                   ▼
┌─────────────┐     ┌─────────────┐
│  Projection │     │  Projection │
│   (Linear)  │     │   (Linear)  │
└──────┬──────┘     └──────┬──────┘
       │                   │
       └─────────┬─────────┘
                 │
                 ▼
         ┌─────────────┐
         │ Gated Fusion│◄── Modality presence flags
         │   Module    │    (handles missing modalities)
         └──────┬──────┘
                │
                ▼
    ┌───────────────────────┐
    │  Interaction Features │
    │  • Fused embedding    │
    │  • Text embedding     │
    │  • Visual embedding   │
    │  • |text - visual|    │
    │  • text ⊙ visual      │
    └───────────┬───────────┘
                │
                ▼
         ┌─────────────┐
         │Classification│
         │  Head (MLP)  │
         │  → 5 classes │
         └─────────────┘

🔑 Key Features

FeatureDescription
Backboneopenai/clip-vit-base-patch32 - Pre-trained CLIP model
Fusion Dimension512
Max Text Length77 tokens
Multi-label Output5 hate speech categories
Gated AttentionModality-aware fusion with learnable gates
Interaction FeaturesRich feature interactions (concatenation, element-wise product, absolute difference)
Missing Modality HandlingCan handle text-only or image-only inputs

🏷️ Output Classes

Class IDCategoryDescriptionPrior Probability
0RacistRacist content targeting race/ethnicity32.6%
1SexistSexist content targeting gender12.0%
2HomophobeHomophobic content targeting sexual orientation7.6%
3ReligionReligion-based hate speech1.5%
4OtherHateOther types of hate speech15.6%

📊 Evaluation Results

Test Set Performance

MetricValue
F1 Macro0.566
F1 Micro0.635
ROC-AUC Macro0.783
Test Loss1.516
Throughput381.5 samples/sec

Per-Class Performance (Validation Set)

ClassPrecisionRecallF1-ScoreSupport
Racist0.5760.8430.6841,994
Sexist0.5870.6460.615875
Homophobe0.8040.7090.753612
Religion0.4350.2090.283129
OtherHate0.5410.7000.6111,195
Micro Avg0.5880.7370.6544,805
Macro Avg0.5890.6210.5894,805

⚙️ Optimized Thresholds

The model uses per-class calibrated thresholds for optimal performance (instead of default 0.5):

ClassThreshold
Racist0.35
Sexist0.70
Homophobe0.75
Religion0.30
OtherHate0.60

📈 Model Comparison

ModelF1 MacroF1 MicroROC-AUC MacroThroughput
CLIP Fusion (this model)0.5660.6350.783381.5
CLIP MTL0.5690.6440.783390.9
SigLIP Fusion0.5070.6100.774236.3
CLIP Fusion (Weighted Sampling)0.5570.6360.772266.4
CLIP Fusion (Bigger Batch)0.5150.5170.804400.9

🎓 Training Data

MMHS150K Dataset

The model was trained on the MMHS150K (Multi-Modal Hate Speech) dataset, a large-scale multi-modal hate speech dataset collected from Twitter containing 150,000 tweet-image pairs annotated for hate speech detection.

PropertyValue
SourceTwitter
Total Samples~150,000
ModalitiesImage + Text
AnnotationMulti-label (5 hate categories)
LanguageEnglish

Dataset Splits

SplitSamples
Train~112,500
Validation~15,000
Test~22,500

Dataset Reference

Paper: "Exploring Hate Speech Detection in Multimodal Publications" (WACV 2020)
Authors: Raul Gomez, Jaume Gibert, Lluis Gomez, Dimosthenis Karatzas


🔧 Training Procedure

Training Configuration

# Model Configuration
backend: clip
head: fusion
encoder_name: openai/clip-vit-base-patch32
fusion_dim: 512
max_text_length: 77
freeze_text: false
freeze_image: false

# Training Configuration
num_train_epochs: 6
per_device_train_batch_size: 32
per_device_eval_batch_size: 64
gradient_accumulation_steps: 2

# Learning Rates (Differential)
lr_encoder: 1.0e-5
lr_head: 5.0e-4

# Regularization
weight_decay: 0.02
max_grad_norm: 1.0

# Scheduler
warmup_ratio: 0.05
lr_scheduler_type: cosine

# Loss
loss_type: bce
use_logit_adjustment: false

# Precision
precision: fp16

# Data Augmentation
augment: true
aug_scale_min: 0.8
aug_scale_max: 1.0
horizontal_flip: true
color_jitter: true

# Early Stopping
early_stopping_patience: 3
metric_for_best_model: roc_macro

Training Highlights

  • Differential Learning Rates: Encoder (1e-5) vs Classification Head (5e-4)
  • Mixed Precision: FP16 training for efficiency
  • Data Augmentation: Random scaling, horizontal flip, color jitter
  • Threshold Calibration: Per-class threshold optimization on validation set
  • Early Stopping: Patience of 3 epochs based on ROC-AUC macro
  • Best Checkpoint: Selected based on validation ROC-AUC macro score

Computational Resources

  • Training Time: ~6 epochs
  • Best Checkpoint: Step 33,708
  • Hardware: GPU with FP16 support

🚀 How to Use

Quick Start (Recommended)

import torch
from PIL import Image
from transformers import AutoModel, CLIPProcessor

# Load model with trust_remote_code=True
model = AutoModel.from_pretrained(
    "Amirhossein75/clip-vit-base-mmhs150k-fusion",
    trust_remote_code=True
)
model.eval()

# Load CLIP processor
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")

# Prepare inputs
image = Image.open("path/to/image.jpg").convert("RGB")
text = "sample text from the meme"

inputs = processor(
    text=[text],
    images=[image],
    return_tensors="pt",
    padding=True,
    truncation=True,
    max_length=77
)

# Run inference
with torch.no_grad():
    result = model.predict(
        input_ids=inputs["input_ids"],
        attention_mask=inputs["attention_mask"],
        pixel_values=inputs["pixel_values"]
    )

print(result)
# {'predictions': {'racist': False, 'sexist': True, 'homophobe': False, 'religion': False, 'otherhate': False},
#  'probabilities': {'racist': 0.12, 'sexist': 0.78, 'homophobe': 0.05, 'religion': 0.02, 'otherhate': 0.15}}

Batch Inference

import torch
from PIL import Image
from transformers import AutoModel, CLIPProcessor

# Load model
model = AutoModel.from_pretrained(
    "Amirhossein75/clip-vit-base-mmhs150k-fusion",
    trust_remote_code=True
)
model.eval()

processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")

# Prepare batch
images = [Image.open("image1.jpg").convert("RGB"), Image.open("image2.jpg").convert("RGB")]
texts = ["text for image 1", "text for image 2"]

inputs = processor(
    text=texts,
    images=images,
    return_tensors="pt",
    padding=True,
    truncation=True,
    max_length=77
)

# Get raw logits and probabilities
with torch.no_grad():
    outputs = model(
        input_ids=inputs["input_ids"],
        attention_mask=inputs["attention_mask"],
        pixel_values=inputs["pixel_values"]
    )
    probabilities = torch.sigmoid(outputs["logits"])

# Apply optimized thresholds
thresholds = torch.tensor([0.35, 0.70, 0.75, 0.30, 0.60])
predictions = (probabilities > thresholds).int()
print(predictions)

Using with GPU

import torch
from transformers import AutoModel, CLIPProcessor

device = "cuda" if torch.cuda.is_available() else "cpu"

model = AutoModel.from_pretrained(
    "Amirhossein75/clip-vit-base-mmhs150k-fusion",
    trust_remote_code=True
).to(device)
model.eval()

processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")

# ... prepare inputs ...
inputs = {k: v.to(device) for k, v in inputs.items()}

with torch.no_grad():
    result = model.predict(**inputs)

Download Config Files Only

from huggingface_hub import hf_hub_download
import json

# Download inference config
config_path = hf_hub_download(
    repo_id="Amirhossein75/clip-vit-base-mmhs150k-fusion",
    filename="inference_config.json"
)

with open(config_path) as f:
    config = json.load(f)

print(f"Classes: {config['class_names']}")
print(f"Thresholds: {config['thresholds']}")
print(f"Encoder: {config['encoder_name']}")

📁 Model Files

FileDescription
checkpoint-33708/model.safetensorsModel weights in safetensors format (617MB)
modeling_clip_fusion.pyModel architecture code (auto-downloaded with trust_remote_code)
config.jsonModel architecture configuration
inference_config.jsonInference settings with thresholds and class names
label_map.jsonLabel name mapping
test_metrics.jsonTest set evaluation metrics
val_report.jsonDetailed validation classification report

☁️ AWS SageMaker Deployment

This model is compatible with AWS SageMaker for cloud deployment:

from sagemaker.pytorch import PyTorchModel
from sagemaker.serializers import JSONSerializer
from sagemaker.deserializers import JSONDeserializer

model = PyTorchModel(
    model_data="s3://your-bucket/model.tar.gz",
    role=role,
    entry_point='inference.py',
    source_dir='sagemaker',
    framework_version='2.1.0',
    py_version='py310',
)

predictor = model.deploy(
    instance_type='ml.g4dn.xlarge',
    initial_instance_count=1,
)

# Make prediction
import base64
with open('image.jpg', 'rb') as f:
    image_b64 = base64.b64encode(f.read()).decode('utf-8')

response = predictor.predict({
    'instances': [{
        'text': 'Sample text content',
        'image_base64': image_b64,
    }]
})

See the SageMaker documentation for full deployment guide.


⚠️ Intended Uses & Limitations

✅ Intended Uses

  • Content moderation for social media platforms
  • Detecting hateful memes and posts
  • Research in multi-modal hate speech detection
  • Building content safety systems
  • Pre-filtering potentially harmful content for human review

⚠️ Limitations

LimitationDescription
LanguageTrained only on English content
DomainTwitter-specific; may not generalize to other platforms
Class ImbalanceLower performance on rare categories (Religion: F1=0.283)
Cultural ContextMay miss culturally-specific hate speech
Sarcasm/IronyMay struggle with subtle or ironic hateful content
Image-only HateText encoder is important; purely visual hate may be missed

❌ Out-of-Scope Uses

  • NOT for making final moderation decisions without human review
  • NOT suitable for legal or compliance purposes without additional validation
  • NOT for censorship or suppression of legitimate speech
  • NOT for targeting or profiling individuals

🛡️ Ethical Considerations

  • This model should be used as a tool to assist human moderators, not replace them
  • False positives may incorrectly flag legitimate content
  • False negatives may miss harmful content
  • Regular evaluation and bias auditing is recommended
  • Consider the cultural and contextual factors in deployment

📝 Citation

If you use this model, please cite:

@misc{yousefi2024multimodal,
  title={Multi-Modal Hateful Content Classification with CLIP Fusion},
  author={Yousefi, Amirhossein},
  year={2024},
  publisher={Hugging Face},
  url={https://huggingface.co/Amirhossein75/clip-vit-base-mmhs150k-fusion}
}

Dataset Citation

@inproceedings{gomez2020exploring,
  title={Exploring Hate Speech Detection in Multimodal Publications},
  author={Gomez, Raul and Gibert, Jaume and Gomez, Lluis and Karatzas, Dimosthenis},
  booktitle={Proceedings of the IEEE/CVF Winter Conference on Applications of Computer Vision (WACV)},
  pages={1470--1478},
  year={2020}
}

CLIP Citation

@inproceedings{radford2021learning,
  title={Learning Transferable Visual Models From Natural Language Supervision},
  author={Radford, Alec and Kim, Jong Wook and Hallacy, Chris and others},
  booktitle={International Conference on Machine Learning},
  pages={8748--8763},
  year={2021}
}

🔗 Links

ResourceLink
GitHub Repositorymultimodal-content-moderation
Base Modelopenai/clip-vit-base-patch32
MMHS150K DatasetOfficial Page
CLIP PaperarXiv

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


🤝 Contributing

Contributions are welcome! Please see the GitHub repository for contribution guidelines.

Как запустить

На своей GPU в ailist. Цена — по текущим предложениям провайдеров

GPU в ailist

Универсальный рантайм · transformers

Нельзя запустить

Модели нужен код из репозитория; автор пока не в списке доверенных организаций.

Класс архитектуры
MultiModalFusionClassifier
Ревизия весов
63de6f5

0 моделей