|
from curses.ascii import isalpha |
|
import os |
|
import csv |
|
import re |
|
from typing import Sequence |
|
import json |
|
import ast |
|
import datasets |
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
Example dataset toxic |
|
""" |
|
_LABEL = "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/syllable-level/test/label" |
|
_LINES = "https://raw.githubusercontent.com/VinAIResearch/JointIDSF/main/PhoATIS/syllable-level/test/seq.in" |
|
|
|
|
|
|
|
class Config(datasets.BuilderConfig): |
|
"""BuilderConfig for GLUE.""" |
|
|
|
def __init__(self, data_url, label_url, **kwargs): |
|
"""BuilderConfig |
|
Args: |
|
data_url: `string`, url to the dataset (word or raw level) |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(Config, self).__init__( |
|
version=datasets.Version( |
|
"1.0.0", |
|
), |
|
**kwargs, |
|
) |
|
self.data_url = data_url |
|
self.label_url = label_url |
|
|
|
|
|
class Guess(datasets.GeneratorBasedBuilder): |
|
VERSION = datasets.Version("0.1.0") |
|
BUILDER_CONFIGS = [ |
|
Config( |
|
name="all", |
|
data_url=_LINES, |
|
label_url=_LABEL, |
|
description="data", |
|
) |
|
] |
|
|
|
def _info(self): |
|
|
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=datasets.Features( |
|
{ |
|
"text": datasets.Value("string"), |
|
"classes": datasets.Sequence(datasets.Value("string")), |
|
"target": datasets.Value("int8") |
|
} |
|
), |
|
|
|
|
|
|
|
supervised_keys=None, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
|
|
data_file = dl_manager.download(self.config.data_url) |
|
label_file = dl_manager.download(self.config.label_url) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={"data_file": data_file, "label_file": label_file}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, data_file, label_file): |
|
_CLASS = { |
|
"abbreviation": 0, |
|
"aircraft": 1, |
|
"airfare": 2, |
|
"airline": 3, |
|
"airport": 4, |
|
"capacity": 5, |
|
"city": 6, |
|
"distance": 7, |
|
"flight": 8, |
|
"flight_no": 19, |
|
"flight_time": 10, |
|
"ground_fare": 11, |
|
"ground_service": 12, |
|
"meal": 13, |
|
"quantity": 14, |
|
"restriction": 15 |
|
} |
|
|
|
_TEXT = ["mã", "loại máy bay", "giá vé", "hãng hàng không", |
|
"sân bay", "sức chứa máy bay", "địa điểm", "khoảng cách", "chuyến bay", |
|
"số hiệu bay", "thời gian bay", "giá dịch vụ", "dịch vụ", "suất ăn", "số lượng", "hạn chế"] |
|
|
|
with open(data_file, 'r') as f: |
|
lines = f.read().splitlines() |
|
with open(label_file, 'r') as f: |
|
labels = f.read().splitlines() |
|
data = [] |
|
for idx, (line, label) in enumerate(zip(lines, labels)): |
|
if label not in _CLASS: |
|
print(line, label) |
|
continue |
|
_classes = [] |
|
for _cl in _TEXT: |
|
_classes.append(f'Cho xin thông tin {_cl}: {line}') |
|
|
|
|
|
yield idx, { |
|
"text" : f'', |
|
"classes" : _classes, |
|
"target" : _CLASS[label] |
|
} |
|
|