Datasets:
Tasks:
Token Classification
Sub-tasks:
named-entity-recognition
Languages:
English
Size:
1K<n<10K
License:
Update indian_names.py
Browse files1 unmodified line2345567814 unmodified lines232425262627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118363738391191201211221231241251261271281291301311321331341351361371385051139140141142143144531451465614714814915058151152153154626364656667686970717273747515515615715815916016116216316416516616716816917017117217317417577787980818283848586878889909192939495969798991761771781791801811821831841851861871881891901 unmodified line
logger = datasets.logging.get_logger(__name__)
_URL = "https://raw.githubusercontent.com/Kriyansparsana/demorepo/main/wnut17train%20(1).conll"_URL = "https://raw.githubusercontent.com/Kriyansparsana/demorepo/main/train.txt"
class indian_namesConfig(datasets.BuilderConfig): """The WNUT 17 Emerging Entities Dataset."""14 unmodified lines ), ]
def _info(self): def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "id": datasets.Value("string"), "tokens": datasets.Sequence(datasets.Value("string")), "pos_tags": datasets.Sequence( datasets.features.ClassLabel( names=[ '"', "''", "#", "$", "(", ")", ",", ".", ":", "``", "CC", "CD", "DT", "EX", "FW", "IN", "JJ", "JJR", "JJS", "LS", "MD", "NN", "NNP", "NNPS", "NNS", "NN|SYM", "PDT", "POS", "PRP", "PRP$", "RB", "RBR", "RBS", "RP", "SYM", "TO", "UH", "VB", "VBD", "VBG", "VBN", "VBP", "VBZ", "WDT", "WP", "WP$", "WRB", ] ) ), "chunk_tags": datasets.Sequence( datasets.features.ClassLabel( names=[ "O", "B-ADJP", "I-ADJP", "B-ADVP", "I-ADVP", "B-CONJP", "I-CONJP", "B-INTJ", "I-INTJ", "B-LST", "I-LST", "B-NP", "I-NP", "B-PP", "I-PP", "B-PRT", "I-PRT", "B-SBAR", "I-SBAR", "B-UCP", "I-UCP", "B-VP", "I-VP", ] ) ), "ner_tags": datasets.Sequence( datasets.features.ClassLabel( names=[ "O", "B-corporation", "I-corporation", "B-person", "I-person" "B-PER", "I-PER", "B-ORG", "I-ORG", "B-LOC", "I-LOC", "B-MISC", "I-MISC", ] ) ), } ), supervised_keys=None, homepage="https://www.aclweb.org/anthology/W03-0419/", citation=_CITATION, )
def _split_generators(self, dl_manager): """Returns SplitGenerators.""" urls_to_download = { "train": f"{_URL}", downloaded_file = dl_manager.download_and_extract(_URL) data_files = { "train": os.path.join(downloaded_file, _TRAINING_FILE), "dev": os.path.join(downloaded_file, _DEV_FILE), "test": os.path.join(downloaded_file, _TEST_FILE), } downloaded_files = dl_manager.download_and_extract(urls_to_download)
return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}), datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_files["train"]}), datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": data_files["dev"]}), datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": data_files["test"]}), ]
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 = 0 for row in f: row = row.rstrip() if row: if "\t" in row: token, label = row.split("\t") current_tokens.append(token) current_labels.append(label) else: # Handle cases where the delimiter is missing # You can choose to skip these rows or handle them differently logger.warning(f"Delimiter missing in row: {row}") guid = 0 tokens = [] pos_tags = [] chunk_tags = [] ner_tags = [] for line in f: if line.startswith("-DOCSTART-") or line == "" or line == "\n": if tokens: yield guid, { "id": str(guid), "tokens": tokens, "pos_tags": pos_tags, "chunk_tags": chunk_tags, "ner_tags": ner_tags, } guid += 1 tokens = [] pos_tags = [] chunk_tags = [] ner_tags = [] else: # New sentence if not current_tokens: # Consecutive empty lines will cause empty sentences continue assert 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 += 1 current_tokens = [] current_labels = [] yield sentence # Don't forget the last sentence in the dataset 🧐 if current_tokens: yield sentence_counter, { "id": str(sentence_counter), "tokens": current_tokens, "ner_tags": current_labels, # conll2003 tokens are space separated splits = line.split(" ") tokens.append(splits[0]) pos_tags.append(splits[1]) chunk_tags.append(splits[2]) ner_tags.append(splits[3].rstrip()) # last example if tokens: yield guid, { "id": str(guid), "tokens": tokens, "pos_tags": pos_tags, "chunk_tags": chunk_tags, "ner_tags": ner_tags, }indian_names.py+138-48