Datasets:
Create vihos.py
Browse files
vihos.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""ViHOS - Vietnamese Hate and Offensive Spans dataset"""
|
2 |
+
|
3 |
+
import json
|
4 |
+
import datasets
|
5 |
+
|
6 |
+
_DESCRIPTION = """\
|
7 |
+
This is a dataset of Vietnamese Hate and Offensive Spans dataset from social media texts.
|
8 |
+
"""
|
9 |
+
|
10 |
+
_HOMEPAGE = "https://huggingface.co/datasets/phusroyal/ViHOS"
|
11 |
+
|
12 |
+
_LICENSE = "mit"
|
13 |
+
|
14 |
+
_URLS = [
|
15 |
+
"https://huggingface.co/datasets/phusroyal/ViHOS/blob/main/train_span_extraction/train.csv"
|
16 |
+
]
|
17 |
+
|
18 |
+
class ViHOS(datasets.GeneratorBasedBuilder):
|
19 |
+
VERSION = datasets.Version("0.1.0")
|
20 |
+
|
21 |
+
def _info(self):
|
22 |
+
return datasets.DatasetInfo(
|
23 |
+
description=_DESCRIPTION,
|
24 |
+
features=datasets.Features(
|
25 |
+
{
|
26 |
+
"id": datasets.Value("string"),
|
27 |
+
"content": datasets.Value("string"),
|
28 |
+
"index_spans": datasets.Value("string")
|
29 |
+
}
|
30 |
+
),
|
31 |
+
homepage=_HOMEPAGE,
|
32 |
+
license=_LICENSE
|
33 |
+
)
|
34 |
+
|
35 |
+
def _split_generators(self, dl_manager):
|
36 |
+
data_dir = dl_manager.download_and_extract(_URLS)
|
37 |
+
return [
|
38 |
+
datasets.SplitGenerator(
|
39 |
+
name=datasets.Split.TRAIN,
|
40 |
+
gen_kwargs={
|
41 |
+
"filepath": data_dir[0],
|
42 |
+
"split": "test",
|
43 |
+
},
|
44 |
+
)
|
45 |
+
]
|
46 |
+
|
47 |
+
def _generate_examples(self, filepath, split):
|
48 |
+
with open(filepath, 'r', encoding="utf-8") as f:
|
49 |
+
for i, line in enumerate(f):
|
50 |
+
data = json.loads(line)
|
51 |
+
if data['description'] is None:
|
52 |
+
data['description'] = ''
|
53 |
+
yield i, data
|