【发布时间】:2021-06-22 21:54:02
【问题描述】:
我有一个字典,其中每个键都映射到一个数组列表,除了键“引用”,它只是一个整数数组。
cls["input_ids"], cls["attention_masks"], cls["labels"], cls["reference"]
一个键的每一行都链接到其他键的行(这是一个 Bert 分词器的修改输出)
我想通过参考值过滤掉一些行并保持输出相同的字典结构,现在我设法做到这一点的唯一方法是这样的: 我放了一些随机数据来给出一个想法
cls= {"input_ids":[[22,22,22],[33,33,33]], "attention_masks":[[22,22,22],[33,33,33]], "reference":[1,0], "labels":[[[22,22,22],[33,33,33]]]}
mcp = {"input_ids":[], "attention_masks":[], "reference":[], "labels":[]}
for el in zip(cls["input_ids"], cls["attention_masks"], cls["reference"], cls["labels"]):
if el[2] == 1:
mcp["input_ids"].append(el[0])
mcp["attention_masks"].append(el[1])
mcp["reference"].append(el[2])
mcp["labels"].append(el[3])
但我真的不喜欢这段代码,我想知道是否有更漂亮的方法来做到这一点。
【问题讨论】:
-
你的 sn-p 没有编译。
-
每个键都是一个数组列表?你能举例说明
cls可能是什么吗? -
更改了代码以给出一个想法,添加了一些随机数据。现在编译。
标签: python dictionary bert-language-model