by_answer

Note

ID: catalog.operators.balancers.qa.by_answer | Type: DeterministicBalancer

{
    "fields": [
        "outputs/answer"
    ],
    "type": "deterministic_balancer"
}

Explanation about DeterministicBalancer

A class used to balance streams deterministically.

For each instance, a signature is constructed from the values of the instance in specified input ‘fields’. By discarding instances from the input stream, DeterministicBalancer maintains equal number of instances for all signatures. When also input ‘max_instances’ is specified, DeterministicBalancer maintains a total instance count not exceeding ‘max_instances’. The total number of discarded instances is as few as possible.

Attributes:

fields (List[str]): A list of field names to be used in producing the instance’s signature. max_instances (Optional, int)

Usage:

balancer = DeterministicBalancer(fields=[“field1”, “field2”], max_instances=200) balanced_stream = balancer.process(stream)

Example:

When input [{“a”: 1, “b”: 1},{“a”: 1, “b”: 2},{“a”: 2},{“a”: 3},{“a”: 4}] is fed into DeterministicBalancer(fields=[“a”]) the resulting stream will be: [{“a”: 1, “b”: 1},{“a”: 2},{“a”: 3},{“a”: 4}]