Update README.md
Browse files
README.md
CHANGED
@@ -2,4 +2,30 @@
|
|
2 |
language:
|
3 |
- en
|
4 |
---
|
5 |
-
copy of [data-of-multimodal-sarcasm-detection](https://github.com/headacheboy/data-of-multimodal-sarcasm-detection)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
language:
|
3 |
- en
|
4 |
---
|
5 |
+
copy of [data-of-multimodal-sarcasm-detection](https://github.com/headacheboy/data-of-multimodal-sarcasm-detection)
|
6 |
+
|
7 |
+
```python
|
8 |
+
# usage
|
9 |
+
from datasets import load_dataset
|
10 |
+
from transformers import CLIPImageProcessor, CLIPTokenizer
|
11 |
+
from torch.utils.data import DataLoader
|
12 |
+
|
13 |
+
image_processor = CLIPImageProcessor.from_pretrained(clip_path)
|
14 |
+
tokenizer = CLIPTokenizer.from_pretrained(clip_path)
|
15 |
+
|
16 |
+
def tokenization(example):
|
17 |
+
text_inputs = tokenizer(example["text"], truncation=True, padding=True, return_tensors="pt")
|
18 |
+
image_inputs = image_processor(example["image"], return_tensors="pt")
|
19 |
+
return {'pixel_values': image_inputs['pixel_values'],
|
20 |
+
'input_ids': text_inputs['input_ids'],
|
21 |
+
'attention_mask': text_inputs['attention_mask'],
|
22 |
+
"label": example["label"]}
|
23 |
+
|
24 |
+
dataset = load_dataset('quaeast/multimodal_sarcasm_detection')
|
25 |
+
dataset.set_transform(tokenization)
|
26 |
+
|
27 |
+
# get torch dataloader
|
28 |
+
train_dl = DataLoader(dataset['train'], batch_size=256, shuffle=True)
|
29 |
+
test_dl = DataLoader(dataset['test'], batch_size=256, shuffle=True)
|
30 |
+
val_dl = DataLoader(dataset['validation'], batch_size=256, shuffle=True)
|
31 |
+
```
|