MCPcopy Create free account
hub / github.com/google-research/language / batch_namedtuples

Function batch_namedtuples

language/realm/featurization.py:649–665  ·  view source on GitHub ↗

Combines a batch of namedtuples into a single namedtuple of the same type. Args: namedtuples: a list of namedtuples, all of the same type. Returns: a single namedtuple, where each value is the result of stacking all values from the original inputs along the the first dimension.

(namedtuples)

Source from the content-addressed store, hash-verified

647
648
649def batch_namedtuples(namedtuples):
650 """Combines a batch of namedtuples into a single namedtuple of the same type.
651
652 Args:
653 namedtuples: a list of namedtuples, all of the same type.
654
655 Returns:
656 a single namedtuple, where each value is the result of stacking all values
657 from the original inputs along the the first dimension.
658 """
659 if not namedtuples:
660 return namedtuples
661
662 nt_type = type(namedtuples[0])
663 dicts = [nt._asdict() for nt in namedtuples]
664 batched_dict = batch_feature_dicts(dicts)
665 return nt_type(**batched_dict)

Callers 1

Calls 1

batch_feature_dictsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…