Update multimodal_sarcasm_detection.py
Browse files
multimodal_sarcasm_detection.py
CHANGED
@@ -3,7 +3,7 @@ from datasets.features import ClassLabel, Features, Image
|
|
3 |
import copy
|
4 |
from dataclasses import dataclass, field
|
5 |
from typing import ClassVar, Dict
|
6 |
-
|
7 |
|
8 |
_DESCRIPTION = "none"
|
9 |
_NAMES = ["non-sarcastic", "sarcastic"]
|
@@ -17,36 +17,6 @@ _METADATA_URLS = {"train": "data/text/train.txt",
|
|
17 |
_IMAGES_DIR = "images/"
|
18 |
|
19 |
|
20 |
-
@dataclass(frozen=True)
|
21 |
-
class ImageTextClassification(TaskTemplate):
|
22 |
-
task: str = field(default="image-text-classification", metadata={"include_in_asdict_even_if_is_default": True})
|
23 |
-
input_schema: ClassVar[Features] = Features({"image": Image()})
|
24 |
-
text_schema: ClassVar[Features] = Features({"text": datasets.Value("string")})
|
25 |
-
label_schema: ClassVar[Features] = Features({"labels": ClassLabel})
|
26 |
-
image_column: str = "image"
|
27 |
-
text_column: str = "text"
|
28 |
-
label_column: str = "labels"
|
29 |
-
|
30 |
-
def align_with_features(self, features):
|
31 |
-
if self.label_column not in features:
|
32 |
-
raise ValueError(f"Column {self.label_column} is not present in features.")
|
33 |
-
if not isinstance(features[self.label_column], ClassLabel):
|
34 |
-
raise ValueError(f"Column {self.label_column} is not a ClassLabel.")
|
35 |
-
task_template = copy.deepcopy(self)
|
36 |
-
label_schema = self.label_schema.copy()
|
37 |
-
label_schema["labels"] = features[self.label_column]
|
38 |
-
task_template.__dict__["label_schema"] = label_schema
|
39 |
-
return task_template
|
40 |
-
|
41 |
-
@property
|
42 |
-
def column_mapping(self) -> Dict[str, str]:
|
43 |
-
return {
|
44 |
-
self.image_column: "image",
|
45 |
-
self.text_column: "text",
|
46 |
-
self.label_column: "labels",
|
47 |
-
}
|
48 |
-
|
49 |
-
|
50 |
class MultimodalSarcasmDetection(datasets.GeneratorBasedBuilder):
|
51 |
"""MultimodalSarcasmDetection Images dataset"""
|
52 |
|
@@ -63,8 +33,7 @@ class MultimodalSarcasmDetection(datasets.GeneratorBasedBuilder):
|
|
63 |
supervised_keys=(("image", "text"), "label"),
|
64 |
homepage=_HOMEPAGE,
|
65 |
citation=_CITATION,
|
66 |
-
license=_LICENSE
|
67 |
-
task_templates=[ImageTextClassification(image_column="image", text_column="text", label_column="label")],
|
68 |
)
|
69 |
|
70 |
def _split_generators(self, dl_manager):
|
|
|
3 |
import copy
|
4 |
from dataclasses import dataclass, field
|
5 |
from typing import ClassVar, Dict
|
6 |
+
|
7 |
|
8 |
_DESCRIPTION = "none"
|
9 |
_NAMES = ["non-sarcastic", "sarcastic"]
|
|
|
17 |
_IMAGES_DIR = "images/"
|
18 |
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
class MultimodalSarcasmDetection(datasets.GeneratorBasedBuilder):
|
21 |
"""MultimodalSarcasmDetection Images dataset"""
|
22 |
|
|
|
33 |
supervised_keys=(("image", "text"), "label"),
|
34 |
homepage=_HOMEPAGE,
|
35 |
citation=_CITATION,
|
36 |
+
license=_LICENSE
|
|
|
37 |
)
|
38 |
|
39 |
def _split_generators(self, dl_manager):
|