|
"""ViHOS - Vietnamese Hate and Offensive Spans dataset""" |
|
|
|
import pandas as pd |
|
|
|
import datasets |
|
|
|
_DESCRIPTION = """\ |
|
This is a dataset of Vietnamese Hate and Offensive Spans dataset from social media texts. |
|
""" |
|
|
|
_HOMEPAGE = "https://huggingface.co/datasets/phusroyal/ViHOS" |
|
|
|
_LICENSE = "mit" |
|
|
|
_URLS = [ |
|
"https://huggingface.co/datasets/phusroyal/ViHOS/blob/main/test/test.csv" |
|
] |
|
|
|
class ViHOS(datasets.GeneratorBasedBuilder): |
|
VERSION = datasets.Version("2.0.0") |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
|
|
features=datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"content": datasets.Value("string"), |
|
"index_spans": datasets.Value("string") |
|
} |
|
), |
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
data_dir = dl_manager.download_and_extract(_URLS) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"filepath": data_dir[0], |
|
"split": "test", |
|
}, |
|
) |
|
] |
|
def load_csv(filename): |
|
data = list() |
|
|
|
file = open(filename,"r") |
|
|
|
lines = reader(file) |
|
csv_reader = reader(file) |
|
for row in csv_reader: |
|
if not row: |
|
continue |
|
data.append(row) |
|
|
|
return data |
|
|
|
def _generate_examples(self, filepath, split): |
|
colnames=['id', 'Content', 'Span ids'] |
|
|
|
with open(filepath, 'r', encoding="utf-8") as f: |
|
data = pd.read_csv(f, names=colnames, header = None) |
|
for i in range(len(data)): |
|
id = data.loc[i, 'id'] |
|
Content = data.loc[i, 'Content'] |
|
Span_ids = data.loc[i, 'Span ids'] |
|
|
|
|
|
yield id, { |
|
"Content": Content, |
|
"Span_ids": Span_ids |
|
} |
|
|
|
|
|
|