| |
| |
| import csv |
| import datasets |
| from datasets import load_dataset |
| from datasets.tasks import TextClassification |
|
|
| _TRAIN_DOWNLOAD_URL = 'https://raw.githubusercontent.com/ZhangLe59151/goginBE/main/wolf_t.csv' |
| _TEST_DOWNLOAD_URL = 'https://raw.githubusercontent.com/ZhangLe59151/goginBE/main/wolf_v.csv' |
|
|
| _DESCRIPTION = 'My Third Dataset' |
| _HOMEPAGE = '' |
| _LICENSE = '' |
| _CITATION = '''\\n@inproceedings{Casanueva2020, |
| author = Mulin, |
| title = Second Dataset, |
| year = {2021}, |
| month = {Sep}, |
| note = {}, |
| url = {}, |
| booktitle = {} |
| }''' |
| class MulinThird(datasets.GeneratorBasedBuilder): |
| VERSION = datasets.Version('1.1.0') |
| def _info(self): |
| features = datasets.Features( |
| {'text': datasets.Value('string'), |
| 'label': datasets.features.ClassLabel( |
| names=[ |
| 'Ask for ideas', |
| 'Explain ideas', |
| 'Ask action', |
| 'Reject answer', |
| 'Ask to do', |
| 'Explain actions', |
| 'Polite', |
| 'Reject', |
| 'Encourage', |
| 'Check emotion', |
| 'Explain ideas,Encourage', |
| 'Explain ideas,Polite', |
| 'Reject answer,Reject', |
| 'Ask for ideas,Ask to do', |
| 'Explain actions,Polite', |
| 'Explain ideas,Explain actions', |
| 'Polite,Encourage', |
| 'Polite,Explain actions', |
| 'Polite,Ask to do', |
| 'Polite,Encourage,Explain ideas,Explain actions', |
| 'Explain ideas,Polite,Explain actions,Encourage'])}) |
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=features, |
| supervised_keys=None, |
| homepage=_HOMEPAGE, |
| license=_LICENSE, |
| citation=_CITATION, |
| task_templates=[TextClassification(text_column='text', label_column='label')] |
| ) |
| def _split_generators(self, dl_manager): |
| train_path = dl_manager.download_and_extract(_TRAIN_DOWNLOAD_URL) |
| test_path = dl_manager.download_and_extract(_TEST_DOWNLOAD_URL) |
| print(train_path) |
| return [ |
| datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": train_path}), |
| datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": test_path}) |
| ] |
| |
| def _generate_examples(self, filepath): |
| with open(filepath, encoding='utf-8') as f: |
| csv_reader = csv.reader(f, quotechar='"', delimiter=",", quoting=csv.QUOTE_ALL, skipinitialspace=True) |
| next(csv_reader) |
| for id_, row in enumerate(csv_reader): |
| id, label, text = row |
| yield id_, {"text": text, "label": label} |