qfeval_functions.functions.soft_topk_bottomk

soft_topk_bottomk(x, k, dim=-1, *, epsilon=0.1, max_iter=200, topk_only=False)[source]

Apply SoftTopKBottomK module along with given dimension.

See qfeval.extension.SoftTopKBottomK for futher information.

Return type:

Tensor

Examples

>>> x = torch.tensor([[1., 2., 3., 4., 5.], [6., 7., 8., 9., 10.]])
>>> soft_topk_bottomk(x, k=1, dim=1)
tensor([[-0.7624, -0.2123,  0.0000,  0.2123,  0.7624],
        [-0.7624, -0.2123,  0.0000,  0.2123,  0.7624]])
>>> soft_topk_bottomk(x, k=1, dim=0)
tensor([[-0.9999, -0.9999, -0.9999, -0.9999, -0.9999],
        [ 0.9999,  0.9999,  0.9999,  0.9999,  0.9999]])
>>> soft_topk_bottomk(x, k=1, dim=1, epsilon=1e-3)
tensor([[-0.9965, -0.0035,  0.0000,  0.0035,  0.9965],
        [-0.9965, -0.0035,  0.0000,  0.0035,  0.9965]])