# batch_get#

composer.utils.batch_get(batch, key)[source]#

Indexes into the batch given the key.

>>> from composer.utils.batch_helpers import batch_get
>>> batch_get([1,2,3], 1)
2
>>> batch_get({'a':1, 'b':7}, 'b')
7
>>> batch_get([{'a':1, 'b':7},{'c':5}], lambda x: x[1]['c'])
5
>>> batch_get([{'a':1, 'b':7},{'c':5}], (lambda x: x[1]['c'], lambda x: 10))
5

Parameters
• batch (Any) – An object that contains the input and label of the items in the batch. Can be any abritrary type that user creates, but we assume some sort of sequence (list, tuple, tensor, array), mapping (dictionary), or attribute store (object with data members, namedtuple).

• key (str | int | Tuple[Callable, Callable] | Any, optional) – A key to index into the batch or a user-specified function to do the extracting. A pair of callables is also supported for cases where a get and set function pair are both passed (like in Algorithms). The getter is assumed to be the first of the pair.

Returns

The part of the batch specified by the key. This could be any type – depending on what the batch is composed of.