quaeast/multimodal_sarcasm_detection
收藏资源简介:
--- language: - en --- copy of [data-of-multimodal-sarcasm-detection](https://github.com/headacheboy/data-of-multimodal-sarcasm-detection) ```python # usage from datasets import load_dataset from transformers import CLIPImageProcessor, CLIPTokenizer from torch.utils.data import DataLoader image_processor = CLIPImageProcessor.from_pretrained(clip_path) tokenizer = CLIPTokenizer.from_pretrained(clip_path) def tokenization(example): text_inputs = tokenizer(example["text"], truncation=True, padding=True, return_tensors="pt") image_inputs = image_processor(example["image"], return_tensors="pt") return {'pixel_values': image_inputs['pixel_values'], 'input_ids': text_inputs['input_ids'], 'attention_mask': text_inputs['attention_mask'], "label": example["label"]} dataset = load_dataset('quaeast/multimodal_sarcasm_detection') dataset.set_transform(tokenization) # get torch dataloader train_dl = DataLoader(dataset['train'], batch_size=256, shuffle=True) test_dl = DataLoader(dataset['test'], batch_size=256, shuffle=True) val_dl = DataLoader(dataset['validation'], batch_size=256, shuffle=True) ```
语言: - 英语 本数据集为[data-of-multimodal-sarcasm-detection](https://github.com/headacheboy/data-of-multimodal-sarcasm-detection)的副本。 以下为该数据集的使用示例代码,首次出现的专业术语均标注英文原文:CLIP图像处理器(CLIPImageProcessor)、CLIP分词器(CLIPTokenizer)以及数据加载器(DataLoader)。 python # 使用方法 from datasets import load_dataset from transformers import CLIPImageProcessor, CLIPTokenizer from torch.utils.data import DataLoader image_processor = CLIPImageProcessor.from_pretrained(clip_path) tokenizer = CLIPTokenizer.from_pretrained(clip_path) def tokenization(example): text_inputs = tokenizer(example["text"], truncation=True, padding=True, return_tensors="pt") image_inputs = image_processor(example["image"], return_tensors="pt") return {'pixel_values': image_inputs['pixel_values'], 'input_ids': text_inputs['input_ids'], 'attention_mask': text_inputs['attention_mask'], "label": example["label"]} dataset = load_dataset('quaeast/multimodal_sarcasm_detection') dataset.set_transform(tokenization) # 获取PyTorch数据加载器 train_dl = DataLoader(dataset['train'], batch_size=256, shuffle=True) test_dl = DataLoader(dataset['test'], batch_size=256, shuffle=True) val_dl = DataLoader(dataset['validation'], batch_size=256, shuffle=True)
数据集概述
数据集名称
quaeast/multimodal_sarcasm_detection
数据集加载
- 使用
datasets库中的load_dataset函数加载数据集。
数据处理
- 使用
CLIPImageProcessor和CLIPTokenizer进行图像和文本的预处理。 - 自定义
tokenization函数将文本和图像转换为模型输入格式。
数据集划分
- 数据集包含训练集、测试集和验证集。
- 使用
DataLoader加载数据,并设置批量大小为 256,进行随机洗牌。




