File size: 1,144 Bytes
bc34b87 8353141 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
---
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)
```
|