# Loading script for the Telugu-English Codeswitch Transliterate dataset import datasets from conllu import parse_incr import conllu logger = datasets.logging.get_logger(__name__) _CITATION = """ """ _DESCRIPTION = """Telugu English POS Codeswitch dataset. """ _HOMEPAGE = "" _URL = "https://huggingface.co/datasets/anishka/CodeSwitching-TE-EN/resolve/main/" _TRAINING_FILE = "te_mtg-ud-train.conllu" _DEV_FILE = "te_mtg-ud-dev.conllu" _TEST_FILE = "te_mtg-ud-test.conllu" class TeEnCodeSwitchConfig(datasets.BuilderConfig): """ Builder config for the Ancora Ca NER dataset """ def __init__(self, **kwargs): """BuilderConfig for TeEnCodeSwitch. Args: **kwargs: keyword arguments forwarded to super. """ super(TeEnCodeSwitchConfig, self).__init__(**kwargs) class TeEnCodeSwitch(datasets.GeneratorBasedBuilder): """ Te-En-CodeSwitch dataset.""" BUILDER_CONFIGS = [ TeEnCodeSwitchConfig( name="Te-En-CodeSwitch", version=datasets.Version("0.0.1"), description="Te-En-CodeSwitch dataset" ), ] def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "id": datasets.Value("string"), "tokens": datasets.Sequence(datasets.Value("string")), "ner_tags": datasets.Sequence( datasets.features.ClassLabel( names=[ "NOUN", "PUNCT", "ADP", "NUM", "SYM", "SCONJ", "ADJ", "PART", "DET", "CCONJ", "PROPN", "PRON", "X", "_", "ADV", "INTJ", "VERB", "AUX", ] ) ), "xpos": datasets.Sequence(datasets.Value("string")), "feats": datasets.Sequence(datasets.Value("string")), "head": datasets.Sequence(datasets.Value("string")), "deprel": datasets.Sequence(datasets.Value("string")), "deps": datasets.Sequence(datasets.Value("string")), "misc": datasets.Sequence(datasets.Value("string")), } ), supervised_keys=None, homepage=_HOMEPAGE, citation=_CITATION, ) def _split_generators(self, dl_manager): """Returns SplitGenerators.""" urls_to_download = { "train": f"{_URL}{_TRAINING_FILE}", "dev": f"{_URL}{_DEV_FILE}", "test": f"{_URL}{_TEST_FILE}", } downloaded_files = dl_manager.download_and_extract(urls_to_download) print ("Downloading files: ") print (urls_to_download) return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}), datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}), datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}), ] def _generate_examples(self, filepath): sentence = [] with open(filepath, 'r') as file: for line in file: line = line.strip() # Skip comment lines and empty lines if line.startswith('#') or not line: continue if line == '': # If an empty line is encountered, yield the current sentence yield sentence # Reset the sentence for the next iteration sentence = [] else: # Split the line by tabs to get fields fields = line.split('\t') # Add the fields to the sentence as a dictionary sentence.append({ 'id': fields[0], 'form': fields[1], 'lemma': fields[2], 'upos': fields[3], 'xpos': fields[4], 'feats': fields[5], 'head': fields[6], 'deprel': fields[7], 'deps': fields[8], 'misc': fields[9] }) # Yield the last sentence if there is one if sentence: yield sentence