ding.torch_utils.metric¶
ding.torch_utils.metric
¶
levenshtein_distance(pred, target, pred_extra=None, target_extra=None, extra_fn=None)
¶
Overview
Levenshtein Distance, i.e. Edit Distance.
Arguments:
- pred (:obj:torch.LongTensor): The first tensor to calculate the distance, shape: (N1, ) (N1 >= 0).
- target (:obj:torch.LongTensor): The second tensor to calculate the distance, shape: (N2, ) (N2 >= 0).
- pred_extra (:obj:Optional[torch.Tensor]): Extra tensor to calculate the distance, only works when extra_fn is not None.
- target_extra (:obj:Optional[torch.Tensor]): Extra tensor to calculate the distance, only works when extra_fn is not None.
- extra_fn (:obj:Optional[Callable]): The distance function for pred_extra and target_extra. If set to None, this distance will not be considered.
Returns:
- distance (:obj:torch.FloatTensor): distance(scalar), shape: (1, ).
hamming_distance(pred, target, weight=1.0)
¶
Overview
Hamming Distance.
Arguments:
- pred (:obj:torch.LongTensor): Pred input, boolean vector(0 or 1).
- target (:obj:torch.LongTensor): Target input, boolean vector(0 or 1).
- weight (:obj:torch.LongTensor): Weight to multiply.
Returns:
- distance(:obj:torch.LongTensor): Distance (scalar), shape (1, ).
Shapes:
- pred & target (:obj:torch.LongTensor): shape :math:(B, N), while B is the batch size, N is the dimension
Full Source Code
../ding/torch_utils/metric.py