def METHOD_NAME(pipeline: EnvironmentPipeline, **kwargs) -> int:
    # language=rst
    """
    Selects an action probabilistically based on spiking activity from a network layer.
    :param pipeline: EnvironmentPipeline with environment that has an integer action
        space.
    :return: Action sampled from multinomial over activity of similarly-sized output
        layer.
    Keyword arguments:
    :param str output: Name of output layer whose activity to base action selection on.
    """
    try:
        output = kwargs["output"]
    except KeyError:
        raise KeyError('select_multinomial() requires an "output" layer argument.')
    output = pipeline.network.layers[output]
    action_space = pipeline.env.action_space
    assert output.n % action_space.n == 0, (
        f"Output layer size of {output.n} is not divisible by action space size of"
        f" {action_space.n}."
    )
    pop_size = int(output.n / action_space.n)
    spikes = output.s
    _sum = spikes.sum().float()
    # Choose action based on population's spiking.
    if _sum == 0:
        action = torch.randint(low=0, high=pipeline.env.action_space.n, size=(1,))[0]
    else:
        pop_spikes = torch.tensor(
            [
                spikes[(i * pop_size) : (i * pop_size) + pop_size].sum()
                for i in range(action_space.n)
            ],
            device=spikes.device,
        )
        action = torch.multinomial((pop_spikes.float() / _sum).view(-1), 1)[0].item()
    return action