From 88f78c719aaac8f5a72440662711775af54a46a5 Mon Sep 17 00:00:00 2001 From: zhiqiang Date: Tue, 23 Apr 2019 07:20:32 -0700 Subject: [PATCH] Fix math formatting of PairwiseDistance and CosineSimilarity docs and fix math formatting of CTC loss docs. Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/19534 Differential Revision: D15034011 Pulled By: ezyang fbshipit-source-id: 60b81c970c919508a57c86fb23edc9f64973117c --- torch/nn/modules/distance.py | 8 ++++++-- torch/nn/modules/loss.py | 16 ++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/torch/nn/modules/distance.py b/torch/nn/modules/distance.py index 9218992..29edfdd 100644 --- a/torch/nn/modules/distance.py +++ b/torch/nn/modules/distance.py @@ -7,8 +7,10 @@ from ..._jit_internal import weak_module, weak_script_method 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. @@ -41,8 +43,10 @@ class PairwiseDistance(Module): @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. diff --git a/torch/nn/modules/loss.py b/torch/nn/modules/loss.py index 38aefc6..ee3e6a1 100644 --- a/torch/nn/modules/loss.py +++ b/torch/nn/modules/loss.py @@ -1221,7 +1221,7 @@ class CTCLoss(_Loss): 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`. @@ -1238,21 +1238,21 @@ class CTCLoss(_Loss): **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`). -- 2.7.4