Datasets:
Tasks:
Token Classification
Sub-tasks:
named-entity-recognition
Languages:
English
Size:
1K<n<10K
License:
Update indian_names.py
Browse files7 unmodified lines8910111213141516171 unmodified line192021222324252627286 unmodified lines35363738394041425 unmodified lines484950515253541 unmodified line56575859606162636465666768697071727374757677787980818283848586877 unmodified linesclass indian_namesConfig(datasets.BuilderConfig):"""BuilderConfig for Conll2003"""def __init__(self, **kwargs):"""BuilderConfig forConll2003.Args:**kwargs: keyword arguments forwarded to super."""1 unmodified lineclass indian_names(datasets.GeneratorBasedBuilder):"""Conll2003 dataset."""BUILDER_CONFIGS = [indian_namesConfig(name="indian_names", version=datasets.Version("1.0.0"), description="indian_names dataset"),]def _info(self):6 unmodified linesdatasets.features.ClassLabel(names=["B-PER","B-ORG",])),5 unmodified linesdef _split_generators(self, dl_manager):"""Returns SplitGenerators."""urls_to_download = {"train": f"{_URL}"}downloaded_files = dl_manager.download_and_extract(urls_to_download)1 unmodified linedatasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),]def _generate_examples(self, filepath):logger.info("⏳ Generating examples from = %s", filepath)with open(filepath, encoding="utf-8") as f:guid = 0tokens = []ner_tags = []for line in f:if line.startswith("-DOCSTART-") or line == "" or line == "\n":if tokens:yield guid, {"id": str(guid),"tokens": tokens,"ner_tags": ner_tags,}guid += 1ner_tags = []else:# conll2003 tokens are space separatedsplits = line.split(" ")tokens.append(splits[0])ner_tags.append(splits[3].rstrip())# last exampleif tokens:yield guid, {"id": str(guid),"tokens": tokens,"ner_tags": ner_tags,}7 unmodified lines8910111213141516171 unmodified line1920212223242526272829306 unmodified lines373839404142435 unmodified lines495051525354551 unmodified line575859606162636465666768697071727374757677787980818283848586878889909192939495967 unmodified linesclass indian_namesConfig(datasets.BuilderConfig):"""The WNUT 17 Emerging Entities Dataset."""def __init__(self, **kwargs):"""BuilderConfig for WNUT 17.Args:**kwargs: keyword arguments forwarded to super."""1 unmodified lineclass indian_names(datasets.GeneratorBasedBuilder):"""The WNUT 17 Emerging Entities Dataset."""BUILDER_CONFIGS = [indian_namesConfig(name="indian_names", version=datasets.Version("1.0.0"), description="The WNUT 17 Emerging Entities Dataset"),]def _info(self):6 unmodified linesdatasets.features.ClassLabel(names=["B-PER","B-ORG"])),5 unmodified linesdef _split_generators(self, dl_manager):"""Returns SplitGenerators."""urls_to_download = {"train": f"{_URL}",}downloaded_files = dl_manager.download_and_extract(urls_to_download)1 unmodified linedatasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),]def _generate_examples(self, filepath):logger.info("⏳ Generating examples from = %s", filepath)with open(filepath, encoding="utf-8") as f:current_tokens = []current_labels = []sentence_counter = 0for row in f:row = row.rstrip()if row:token, label = row.split("\t")current_tokens.append(token)current_labels.append(label)else:# New sentenceif not current_tokens:# Consecutive empty lines will cause empty sentencescontinueassert len(current_tokens) == len(current_labels), "💔 between len of tokens & labels"sentence = (sentence_counter,{"id": str(sentence_counter),"tokens": current_tokens,"ner_tags": current_labels,},)sentence_counter += 1current_tokens = []current_labels = []yield sentence# Don't forget last sentence in dataset 🧐if current_tokens:yield sentence_counter, {"id": str(sentence_counter),"tokens": current_tokens,"ner_tags": current_labels,}
indian_names.py+41-32