Datasets:
Tasks:
Text Classification
Modalities:
Text
Formats:
parquet
Sub-tasks:
sentiment-classification
Size:
10K - 100K
License:
Update loading script
Browse files- tamilmixsentiment.py +15 -41
tamilmixsentiment.py
CHANGED
|
@@ -16,6 +16,7 @@
|
|
| 16 |
|
| 17 |
|
| 18 |
import csv
|
|
|
|
| 19 |
|
| 20 |
import datasets
|
| 21 |
from datasets.tasks import TextClassification
|
|
@@ -47,11 +48,12 @@ The first gold standard Tamil-English code-switched, sentiment-annotated corpus
|
|
| 47 |
|
| 48 |
_LICENSE = ""
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
"
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
class Tamilmixsentiment(datasets.GeneratorBasedBuilder):
|
|
@@ -74,50 +76,22 @@ class Tamilmixsentiment(datasets.GeneratorBasedBuilder):
|
|
| 74 |
)
|
| 75 |
|
| 76 |
def _split_generators(self, dl_manager):
|
| 77 |
-
|
| 78 |
-
validation_path = dl_manager.download_and_extract(_VALIDATION_DOWNLOAD_URL)
|
| 79 |
-
test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL)
|
| 80 |
return [
|
| 81 |
datasets.SplitGenerator(
|
| 82 |
-
name=
|
| 83 |
-
gen_kwargs={
|
| 84 |
-
"filepath": train_path,
|
| 85 |
-
"split": "train",
|
| 86 |
-
},
|
| 87 |
-
),
|
| 88 |
-
datasets.SplitGenerator(
|
| 89 |
-
name=datasets.Split.VALIDATION,
|
| 90 |
gen_kwargs={
|
| 91 |
-
"filepath":
|
| 92 |
-
"split": "validation",
|
| 93 |
},
|
| 94 |
-
)
|
| 95 |
-
datasets.
|
| 96 |
-
name=datasets.Split.TEST,
|
| 97 |
-
gen_kwargs={
|
| 98 |
-
"filepath": test_path,
|
| 99 |
-
"split": "test",
|
| 100 |
-
},
|
| 101 |
-
),
|
| 102 |
]
|
| 103 |
|
| 104 |
-
def _generate_examples(self, filepath
|
| 105 |
"""Generate Tamilmixsentiment examples."""
|
| 106 |
with open(filepath, encoding="utf-8") as csv_file:
|
| 107 |
-
csv_reader = csv.
|
| 108 |
csv_file, quotechar='"', delimiter="\t", quoting=csv.QUOTE_ALL, skipinitialspace=True
|
| 109 |
)
|
| 110 |
-
# skip header
|
| 111 |
-
next(csv_reader)
|
| 112 |
-
|
| 113 |
for id_, row in enumerate(csv_reader):
|
| 114 |
-
|
| 115 |
-
# test - has a first column indicating sentence number
|
| 116 |
-
if split == "test":
|
| 117 |
-
idcol, text, label = row
|
| 118 |
-
|
| 119 |
-
# train, validation
|
| 120 |
-
else:
|
| 121 |
-
text, label = row
|
| 122 |
-
|
| 123 |
-
yield id_, {"text": text, "label": label}
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
import csv
|
| 19 |
+
import os.path
|
| 20 |
|
| 21 |
import datasets
|
| 22 |
from datasets.tasks import TextClassification
|
|
|
|
| 48 |
|
| 49 |
_LICENSE = ""
|
| 50 |
|
| 51 |
+
_URL = "data/tamil.zip"
|
| 52 |
+
_FILENAMES = {
|
| 53 |
+
"train": "tamil_train.tsv",
|
| 54 |
+
"validation": "tamil_dev.tsv",
|
| 55 |
+
"test": "tamil_test.tsv",
|
| 56 |
+
}
|
| 57 |
|
| 58 |
|
| 59 |
class Tamilmixsentiment(datasets.GeneratorBasedBuilder):
|
|
|
|
| 76 |
)
|
| 77 |
|
| 78 |
def _split_generators(self, dl_manager):
|
| 79 |
+
data_dir = dl_manager.download_and_extract(_URL)
|
|
|
|
|
|
|
| 80 |
return [
|
| 81 |
datasets.SplitGenerator(
|
| 82 |
+
name=split,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
gen_kwargs={
|
| 84 |
+
"filepath": os.path.join(data_dir, _FILENAMES[split]),
|
|
|
|
| 85 |
},
|
| 86 |
+
)
|
| 87 |
+
for split in (datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
]
|
| 89 |
|
| 90 |
+
def _generate_examples(self, filepath):
|
| 91 |
"""Generate Tamilmixsentiment examples."""
|
| 92 |
with open(filepath, encoding="utf-8") as csv_file:
|
| 93 |
+
csv_reader = csv.DictReader(
|
| 94 |
csv_file, quotechar='"', delimiter="\t", quoting=csv.QUOTE_ALL, skipinitialspace=True
|
| 95 |
)
|
|
|
|
|
|
|
|
|
|
| 96 |
for id_, row in enumerate(csv_reader):
|
| 97 |
+
yield id_, {"text": row["text"], "label": row["category"]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|