Datasets:
Commit ·
7f553d0
1
Parent(s): fb75482
Update multiconer_v2.py
Browse files286 unmodified lines287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338286 unmodified lineslogger.info("⏳ Generating examples from = %s", filepath)content = open(filepath, 'r', encoding="utf-8").read().strip()lines = content.split('\n')items = [(4, {'id': '5fcb44ad-c1ef-4925-be27-008a76667b3b', 'tokens': ['রাস্তায়', 'রঙিন', 'লাইট', 'এবং', 'বাদশাহী', 'মসজিদ', 'এর', 'দৃশ্য', 'রয়েছে', 'এবং', 'এটি', 'রোশনাই', 'গেট', 'এর', 'নিকটে', 'রয়েছে'], 'ner_tags': ['O', 'O', 'O', 'O', 'B-Facility', 'I-Facility', 'O', 'O', 'O', 'O', 'O', 'B-OtherPROD', 'I-OtherPROD', 'O', 'O', 'O']}),(5, {'id': '44334ba4-0ebb-4001-83a7-525473eba921', 'tokens': ['ফাইল', ':', 'একে', '৭৪', 'বোল্ট।', 'জেপিজি', '|', 'একে-৭৪', 'বোল্ট', 'এবং', 'ফায়ারিং', 'পিন।'], 'ner_tags': ['O', 'O', 'O', 'O', 'O', 'O', 'O', 'B-OtherPROD', 'O', 'O', 'O', 'O']}),(6, {'id': '8c87e2f6-cacc-43a8-bb0f-40aa3817af48', 'tokens': ['যখন', 'নিমজ্জিত', 'হয়', 'প্রতিটি', 'প্রোপেলার', 'একটি', 'বৈদ্যুতিক', 'মোটর', 'দ্বারা', 'চালিত', 'হয়েছিল।'], 'ner_tags': ['O', 'O', 'O', 'O', 'O', 'O', 'B-OtherPROD', 'I-OtherPROD', 'O', 'O', 'O']}),(7, {'id': '624ef8af-c8d6-4f28-b946-53344d721b6e', 'tokens': ['বেশ', 'কয়েকটি', 'অ্যাসকোমাইসেট', 'ছত্রাকের', 'বংশাণুসমগ্র', 'পুরোপুরি', 'ক্রমযুক্ত', 'হয়েছে।'], 'ner_tags': ['O', 'O', 'O', 'O', 'B-OtherPROD', 'O', 'O', 'O']})]items.append((6, {'id': 'asdas624ef8af-c8d6-4f28-b946-53344d721b6e', 'tokens': lines[:5], 'ner_tags': lines[5:10]} ))for it in items:yield itguid = -1s_id = Nonetokens = []ner_tags = []for line in lines:if line.startswith("# id"):s_id = line.split('\t')[0].split(' ')[-1].strip()guid += 1tokens = []ner_tags = []elif len(line.strip()) < 3:if s_id and len(tokens) >= 1 and len(tokens) == len(ner_tags):yield (guid, {"id": str(guid),"sample_id": str(s_id),"tokens": tokens,"ner_tags": ner_tags,})s_id = Nonetokens = []ner_tags = []else:continueelse:# Separator is " _ _ "splits = line.split()if len(splits) > 2:tokens.append(splits[0].strip())ner_tags.append(splits[-1].strip())if s_id:yield (guid, {"id": str(guid),"sample_id": str(s_id),"tokens": tokens,"ner_tags": ner_tags,})286 unmodified lines287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324286 unmodified lineslogger.info("⏳ Generating examples from = %s", filepath)with open(filepath) as f:guid = -1s_id = Nonetokens = []ner_tags = []for line in f:if line.strip().startswith("# id"):s_id = line.split('\t')[0].split(' ')[-1].strip()guid += 1tokens = []ner_tags = []elif '_ _' in line:# Separator is " _ _ "splits = line.split("_ _")tokens.append(splits[0].strip())ner_tags.append(splits[1].strip())elif len(line.strip()) == 0:if s_id and len(tokens) >= 1 and len(tokens) == len(ner_tags):yield guid, {"id": s_id,"tokens": tokens,"ner_tags": ner_tags,}s_id = Nonetokens = []ner_tags = []else:continueif s_id and len(tokens) >= 1 and len(tokens) == len(ner_tags):yield guid, {"id": s_id,"tokens": tokens,"ner_tags": ner_tags,}
multiconer_v2.py+32-46