| import csv |
| import json |
| import os |
| import datasets |
| import pandas as pd |
|
|
| _CITATION = """ |
| @article{alam2021review, |
| title={A Review of Bangla Natural Language Processing Tasks and the Utility of Transformer Models}, |
| author={Alam, Firoj and Hasan, Md Arid and Alam, Tanvir and Khan, Akib and Tajrin, Janntatul and Khan, Naira and Chowdhury, Shammur Absar}, |
| journal={arXiv preprint arXiv:2107.03844}, |
| year={2021} |
| } |
| @article{alam2020bangla, |
| title={Bangla Text Classification using Transformers}, |
| author={Alam, Tanvirul and Khan, Akib and Alam, Firoj}, |
| journal={arXiv preprint arXiv:2011.04446}, |
| year={2020} |
| } |
| |
| @article{kunchukuttan2020ai4bharat, |
| author = {Anoop Kunchukuttan and Divyanshu Kakwani and Satish Golla and Gokul N.C. and Avik Bhattacharyya and Mitesh M. Khapra and Pratyush Kumar}, |
| journal = {arXiv preprint arXiv:2005.00085}, |
| title = {AI4Bharat-IndicNLP Corpus: Monolingual Corpora and Word Embeddings for Indic Languages}, |
| year = {2020} |
| } |
| """ |
|
|
| _DESCRIPTION = """ |
| The dataset contains six different class labels for news categorization task and is available with training, development, and test splits with 11,284, 1,411, and 1,411 news articles, respectively. |
| """ |
| _HOMEPAGE = "https://github.com/banglanlp/bnlp-resources" |
|
|
| _LICENCE = "https://creativecommons.org/licenses/by-nc-sa/4.0/" |
|
|
| _URLS = { |
| "https://github.com/banglanlp/bnlp-resources/tree/main/news_categorization" |
| } |
|
|
|
|
| class new_datasetConfig(datasets.BuilderConfig): |
| def __init__(self, features, data_url, citation, url, label_classes=("False", "True"), **kwargs): |
| super(new_datasetConfig, self).__init__(version=datasets.Version("0.1.1"), **kwargs) |
| self.features = features |
| self.label_classes = label_classes |
| self.data_url = data_url |
| self.citation = citation |
| self.url = url |
|
|
|
|
| class new_dataset(datasets.GeneratorBasedBuilder): |
| VERSION = datasets.Version("0.1.1") |
|
|
| BUILDER_CONFIGS = [ |
| new_datasetConfig( |
| name="new_dataset", |
| features=["text", "class_label"], |
| data_url="https://github.com/banglanlp/bnlp-resources/tree/main/news_categorization", |
| citation=_CITATION, |
| url="https://github.com/google" |
| ) |
| ] |
| print(BUILDER_CONFIGS[0].name) |
|
|
| def _info(self): |
| features = datasets.Features( |
| { |
| "text": datasets.Values("string"), |
| "class_label": datasets.Values("string"), |
|
|
| } |
| ) |
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=features, |
| supervised_keys=None, |
| homepage=_HOMEPAGE, |
| license=_LICENCE, |
| citation=_CITATION, |
|
|
| ) |
|
|
|
|
| def _Split_genertors(self, dl_manager): |
| urls = _URLS[self.config.name] |
| print(urls) |
| data_dir = "./data" |
| return [ |
| datasets._Split_genertor( |
| name=datasets.Split.TRAIN, |
| gen_kwargs={ |
| "filepath": os.path.join(data_dir, "train.tsv"), |
| "split": "train", |
| }, |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.TEST, |
| gen_kwargs={ |
| "filepath": os.path.join(data_dir, "test.tsv"), |
| "split": "test", |
| }, |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.VALIDATION, |
| gen_kwargs={ |
| "filepath": os.path.join(data_dir, "dev.tsv"), |
| "split": "dev", |
| }, |
| ), |
| ] |
|
|
|
|
| def _generate_examples(self, filepath, split): |
| with open(filepath, encoding="utf-8") as f: |
| reader = csv.reader(f, delimiter="\t") |
| next(reader) |
| for row in reader: |
| |
| yield row[0], { |
| "text": row[1], |
| "class_label": row[2], |
| } |