noether.data.pipeline.sample_processors.rename_keys¶
Classes¶
Sample processor that simply renames the dictionary keys in a batch. |
Module Contents¶
- class noether.data.pipeline.sample_processors.rename_keys.RenameKeysSampleProcessor(key_map)¶
Bases:
noether.data.pipeline.sample_processor.SampleProcessorSample processor that simply renames the dictionary keys in a batch.
Rename keys in the batch if they are in the key_map and keep old keys otherwise. Creates a new dictionary whose keys are renamed but uses references to the values of the old dict. This avoids copying the data and at the same time does not modify this function’s input.
# dummy example processor = RenameKeysSampleProcessor(key_map={"old_key1": "new_key1", "old_key2": "new_key2"}) input_sample = { "old_key1": some_tensor1, "old_key2": some_tensor2, "unchanged_key": some_tensor3, } output_sample = processor(input_sample) # output_sample will be: { # 'new_key1': some_tensor1, # 'new_key2': some_tensor2, # 'unchanged_key': some_tensor3, # }
- Parameters:
key_map (dict[str, str]) – Dict with source keys as keys and target keys as values. The source keys are renamed target keys.
- key_map¶