SROIE / prepration.py
sizhkhy's picture
Create prepration.py
65cc1b6 verified
raw
history blame
633 Bytes
from itertools import groupby
from torch_snippets import *
from datasets import load_dataset
ds = load_dataset('darentang/sroie')
classes = ds['train'].features['ner_tags'].feature.names
def make_classes(X):
x = AD(X)
words_with_labels = wwl = [(w, classes[l]) for w,l in zip(x.words, x.ner_tags)]
wwl = [i for i in wwl if i[1] != 'O']
wwl = [(w,l.split('-')[1]) for w,l in wwl]
wwl = {cls: ' '.join(next(zip(*group))) for cls,group in groupby(wwl, key=lambda x: x[1])}
X['fields'] = wwl
return X
ds = ds.map(make_classes)
ds.push_to_hub('sizhkhy/SROIE', commit_message="add fields as a new key")