sugartensor.sg_loss module

sugartensor.sg_loss.sg_bce(tensor, opt)[source]

Returns sigmoid cross entropy loss between tensor and target.

Args:

tensor: A Tensor. Logits. Unscaled log probabilities. opt:

target: A Tensor with the same shape and dtype as tensor. Labels. name: A string. A name to display in the tensor board web UI.
Returns:
A Tensor of the same shape as tensor

For example,

``` tensor = [[2, -1, 3], [3, 1, -2]] target = [[0, 1, 1], [1, 1, 0]] tensor.sg_bce(target=target) => [[ 2.12692809 1.31326163 0.04858733]

[ 0.04858733 0.31326166 0.12692805]]

```

sugartensor.sg_loss.sg_ce(tensor, opt)[source]

Returns softmax cross entropy loss between tensor and target.

Args:

tensor: A Tensor. Logits. Unscaled log probabilities. opt:

target: A Tensor with the same length in the first dimension as the tensor. Labels. one_hot: Boolean. Whether to treat the labels as one-hot encoding. Default is False. mask: Boolean. If True, zeros in the target will be excluded from the calculation. name: A string. A name to display in the tensor board web UI.
Returns:
A 1-D Tensor with the same shape as tensor.

For example,

` tensor = [[[2, -1, 3], [3, 1, -2]]] target = [[2, 1]] tensor.sg_ce(target=target) => [[ 0.32656264  2.13284516]] `

For example,

` tensor = [[2, -1, 3], [3, 1, -2]] target = [[0, 0, 1], [1, 0, 0]] tensor.sg_ce(target=target, one_hot=True) => [ 0.32656264  0.13284527] `

sugartensor.sg_loss.sg_ctc(tensor, opt)[source]

Computes the CTC (Connectionist Temporal Classification) Loss between tensor and target.

Args:

tensor: A 3-D float Tensor. opt:

target: A Tensor with the same length in the first dimension as the tensor. Labels. ( Dense tensor ) name: A string. A name to display in the tensor board web UI.
Returns:
A 1-D Tensor with the same length in the first dimension of the tensor.

For example,

` tensor = [[[2., -1., 3.], [3., 1., -2.]], [[1., -1., 2.], [3., 1., -2.]]] target = [[2., 1.], [2., 3.]] tensor.sg_ctc(target=target) => [ 4.45940781  2.43091154] `

sugartensor.sg_loss.sg_hinge(tensor, opt)[source]

Returns hinge loss between tensor and target.

Args:

tensor: A Tensor. opt:

target: A Tensor. Labels. margin: An int. Maximum margin. Default is 1. name: A string. A name to display in the tensor board web UI.
Returns:
A Tensor.

For example,

``` tensor = [[30, 10, 40], [13, 30, 42]] target = [[0, 0, 1], [0, 1, 0]] tensor.sg_hinge(target=target, one_hot=True) => [[ 1. 1. 0.]

[ 1. 0. 1.]]

```

sugartensor.sg_loss.sg_mae(tensor, opt)[source]

Returns absolute error between tensor and target.

Args:

tensor: A Tensor. opt:

target: A Tensor with the same shape and dtype as tensor. name: A string. A name to display in the tensor board web UI.
Returns:
A Tensor of the same shape and dtype as tensor

For example,

``` tensor = [[34, 11, 40], [13, 30, 42]] target = [[34, 10, 41], [14, 31, 40]] tensor.sg_mse(target=target) => [[ 0. 1. 1.]

[ 1. 1. 2.]]

```

sugartensor.sg_loss.sg_mse(tensor, opt)[source]

Returns squared error between tensor and target.

Args:

tensor: A Tensor. opt:

target: A Tensor with the same shape and dtype as tensor. name: A string. A name to display in the tensor board web UI.
Returns:
A Tensor of the same shape and dtype as tensor

For example,

``` tensor = [[34, 11, 40], [13, 30, 42]] target = [[34, 10, 41], [14, 31, 40]] tensor.sg_mse(target=target) => [[ 0. 1. 1.]

[ 1. 1. 4.]]

```