NER任务

#1
by JaheimLee - opened

Hi,千问词表会把很多中英文变成utf8编码,这种情况下还能进行tokenclassification的任务吗

实测问题不大,同样数据集上的任务表现要比 xlm-roberta 还要好一点,毕竟模型本来就是只认 token 不认字的

可以参考训练脚本中的这段代码将其还原为明文:

def print_dataset_sample(tokenizer: PreTrainedTokenizerFast, dateset: Dataset, id2label: dict) -> None:
    if len(dateset) == 0:
        return

    labels = dateset[0].get("labels")
    input_ids = dateset[0].get("input_ids")
    input_tokens = tokenizer.batch_decode(input_ids)
    attention_mask = dateset[0].get("attention_mask")
    special_tokens_mask = dateset[0].get("special_tokens_mask")

    print(f"{"tokens":<8}\t\t{"labels":<4}\t\t{"ids":<4}\t\t{"attention":<8}\t\t{"special_mask":<6}")
    for x, y, z, a, b in zip(input_tokens, labels, input_ids, attention_mask, special_tokens_mask):
        print(f"{x:<8}\t\t{id2label.get(y):<4}\t\t{z:<4}\t\t{a:<8}\t\t{b:<6}")

Sign up or log in to comment