Python中,*会把接收到的参数形成一个
元组
,**会把接收到的参数存入一个字典
。
def print_1(input_ids, attention_mask, token_type_ids, intent_label_ids, slot_labels_ids):
print("input_ids:",input_ids)
print("attention_mask:", attention_mask)
print("token_type_ids:", token_type_ids)
print("intent_label_ids:", intent_label_ids)
print("slot_labels_ids:", slot_labels_ids)
if __name__ == '__main__':
batch = [ [ [11],
[22]],
[ [33],
[44]],
[ [55],
[66]],
[ [77],
[88]],
[ [99],
[00]] ]
inputs = {'input_ids': batch[0], # 第一行
'attention_mask': batch[1], # 第二行
'token_type_ids': batch[2],
'intent_label_ids': batch[3],
'slot_labels_ids': batch[4] }
print_1(**inputs)
print(inputs)
** 的作用是把字典 inputs 变成关键字参数传递
结果如下图所示。
input_ids: [[11], [22]]
attention_mask: [[33], [44]]
token_type_ids: [[55], [66]]
intent_label_ids: [[77], [88]]
slot_labels_ids: [[99], [0]]
{'input_ids': [[11], [22]],
'attention_mask': [[33], [44]],
'token_type_ids': [[55], [66]],
'intent_label_ids': [[77], [88]],
'slot_labels_ids': [[99], [0]]}