1/10/2023

idx2label, label2idx python code

refer to code:

...

labels = ['B-answer', 'I-answer', 'B-header', 'I-header', 'B-question', 'I-question', 'B-other', 'I-other']
idx2label = {v: k for v, k in enumerate(labels)}
label2idx = {k: v for v, k in enumerate(labels)}
print(f'{idx2label=}')
print(f'{label2idx=}')

...


idx2label={0: 'B-answer', 1: 'I-answer', 2: 'B-header', 3: 'I-header', 4: 'B-question', 5: 'I-question', 6: 'B-other', 7: 'I-other'}
label2idx={'B-answer': 0, 'I-answer': 1, 'B-header': 2, 'I-header': 3, 'B-question': 4, 'I-question': 5, 'B-other': 6, 'I-other': 7}


Thx!