class PairwiseDistance(Module):
r"""
Computes the batchwise pairwise distance between vectors :math:`v_1`, :math:`v_2` using the p-norm:
+
.. math ::
- \Vert x \Vert _p = \left( \sum_{i=1}^n \vert x_i \vert ^ p \right) ^ {1/p}
+ \Vert x \Vert _p = \left( \sum_{i=1}^n \vert x_i \vert ^ p \right) ^ {1/p}.
+
Args:
p (real): the norm degree. Default: 2
eps (float, optional): Small value to avoid division by zero.
@weak_module
class CosineSimilarity(Module):
r"""Returns cosine similarity between :math:`x_1` and :math:`x_2`, computed along dim.
+
.. math ::
- \text{similarity} = \dfrac{x_1 \cdot x_2}{\max(\Vert x_1 \Vert _2 \cdot \Vert x_2 \Vert _2, \epsilon)}
+ \text{similarity} = \dfrac{x_1 \cdot x_2}{\max(\Vert x_1 \Vert _2 \cdot \Vert x_2 \Vert _2, \epsilon)}.
+
Args:
dim (int, optional): Dimension where cosine similarity is computed. Default: 1
eps (float, optional): Small value to avoid division by zero.
Calculates loss between a continuous (unsegmented) time series and a target sequence. CTCLoss sums over the
probability of possible alignments of input to target, producing a loss value which is differentiable
with respect to each input node. The alignment of input to target is assumed to be "many-to-one", which
- limits the length of the target sequence such that it must be :math: `\leq` the input length.
+ limits the length of the target sequence such that it must be :math:`\leq` the input length.
**Args:**
**blank** (int, optional): blank label. Default :math:`0`.
**Inputs:**
**log_probs**: Tensor of size :math:`(T, N, C)`
- | :math:`T = input length`
- | :math:`N = batch size`
- | :math:`C = number of classes (including blank)`
+ | :math:`T = \text{input length}`
+ | :math:`N = \text{batch size}`
+ | :math:`C = \text{number of classes (including blank)}`
The logarithmized probabilities of the outputs
(e.g. obtained with :func:`torch.nn.functional.log_softmax`).
- **targets**: Tensor of size :math:`(N, S)` or `(sum(target_lengths))`
- | :math:`N = batch size`
- | :math:`S = max target length, if shape is (N, S)`.
+ **targets**: Tensor of size :math:`(N, S)` or :math:`(\text{sum(target_lengths)})`
+ | :math:`N = \text{batch size}`
+ | :math:`S = \text{max target length, if shape is } (N, S)`.
| Target sequences. Each element in the target sequence is a class index. Target index
cannot be blank (default=0).
| In the :math:`(N, S)` form, targets are padded to the length of the longest sequence, and stacked.
- | In the :math:`(sum(target_lengths))` form, the targets are assumed to be un-padded and concatenated
+ | In the :math:`(\text{sum(target_lengths)})` form, the targets are assumed to be un-padded and concatenated
within 1 dimension.
**input_lengths**: Tuple or tensor of size :math:`(N)`.
Lengths of the inputs (must each be :math:`\leq T`).