Views
No views yet
maf_model_full.pth - Complete model state dict (includes all weights)clip_visual_finetuned.pth - Fine-tuned CLIP visual encoder weights onlyclip_config.pth - CLIP model configurationmodel_architecture.py - Model architecture code with lexicon support1from huggingface_hub import hf_hub_download
2import torch
3import open_clip
4from transformers import AutoTokenizer
5
6# Setup device
7device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
8
9# Download model files
10model_weights_path = hf_hub_download(repo_id="lucius-40/bengali-political-maf-v6", filename="maf_model_full.pth")
11arch_path = hf_hub_download(repo_id="lucius-40/bengali-political-maf-v6", filename="model_architecture.py")
12clip_config_path = hf_hub_download(repo_id="lucius-40/bengali-political-maf-v6", filename="clip_config.pth")
13
14# Load CLIP configuration
15clip_config = torch.load(clip_config_path, map_location=device)
16
17# Initialize CLIP model (base model)
18clip_model, _, preprocess = open_clip.create_model_and_transforms(
19 clip_config['model_name'], # 'ViT-B-16'
20 pretrained=clip_config['pretrained'], # 'laion2b_s34b_b88k'
21 device=device
22)
23
24# Extract visual encoder
25clip_model = clip_model.visual.float().to(device)
26
27# Import architecture
28import importlib.util
29spec = importlib.util.spec_from_file_location("model_architecture", arch_path)
30model_arch = importlib.util.module_from_spec(spec)
31spec.loader.exec_module(model_arch)
32MAF = model_arch.MAF
33
34# Initialize model with CLIP encoder
35model = MAF(clip_model, num_classes=2, num_heads=16, use_lexicon_boost=True)
36
37# Load fine-tuned weights (this will load the fine-tuned CLIP weights too)
38model.load_state_dict(torch.load(model_weights_path, map_location=device))
39model = model.to(device)
40model.eval()
41
42print("✓ Model loaded with fine-tuned CLIP and XLM-RoBERTa weights!")
43
44# Prepare for inference
45# ... (prepare image and text inputs)torch>=1.9.0
torchvision>=0.10.0
transformers>=4.41.2
open_clip_torch
pillow>=9.5.01@inproceedings{ahsan2024multimodal,
2 title={A Multimodal Framework to Detect Target Aware Aggression in Memes},
3 author={Ahsan, Shawly and Hossain, Eftekhar and Sharif, Omar and Das, Avishek and Hoque, Mohammed Moshiul and Dewan, M},
4 booktitle={Proceedings of the 18th Conference of the European Chapter of the Association for Computational Linguistics (Volume 1: Long Papers)},
5 pages={2487--2500},
6 year={2024}
7}