Loss ops

Unreleased native NuTorch shell reference. Generated by scripts/gen-ops-reference.ts; every op also documents itself with torch <op> --help. Tensor operands are native values, not strings.

mse_loss

mean squared error (—reduction mean|sum|none)

Signature (placeholders describe arguments; this is not a runnable example):

use torch
torch mse_loss <t1> <t2> [--reduction <Str>]

l1_loss

mean absolute error (—reduction)

Signature (placeholders describe arguments; this is not a runnable example):

use torch
torch l1_loss <t1> <t2> [--reduction <Str>]

smooth_l1_loss

smooth L1 loss (—beta, default 1.0)

Signature (placeholders describe arguments; this is not a runnable example):

use torch
torch smooth_l1_loss <t1> <t2> [--reduction <Str>] [--beta <Float>]

huber_loss

Huber loss (—delta, default 1.0)

Signature (placeholders describe arguments; this is not a runnable example):

use torch
torch huber_loss <t1> <t2> [--reduction <Str>] [--delta <Float>]

cross_entropy

cross entropy over logits vs int64 class indices

Signature (placeholders describe arguments; this is not a runnable example):

use torch
torch cross_entropy <t1> <t2> [--reduction <Str>]

nll_loss

negative log likelihood (log-prob inputs, int64 targets)

Signature (placeholders describe arguments; this is not a runnable example):

use torch
torch nll_loss <t1> <t2> [--reduction <Str>]

binary_cross_entropy

BCE over probabilities in [0,1]

Signature (placeholders describe arguments; this is not a runnable example):

use torch
torch binary_cross_entropy <t1> <t2> [--reduction <Str>]

binary_cross_entropy_with_logits

BCE over logits (the stable form)

Signature (placeholders describe arguments; this is not a runnable example):

use torch
torch binary_cross_entropy_with_logits <t1> <t2> [--reduction <Str>]

kl_div

KL divergence (—log_target if target is log-space)

Signature (placeholders describe arguments; this is not a runnable example):

use torch
torch kl_div <t1> <t2> [--reduction <Str>] [--log_target]

Tips

Intro

mse_loss compares a guess with a target.

use torch
let pred = torch tensor [1.0 0.0]
let target = torch tensor [1.0 0.0]
torch mse_loss $pred $target

Basic

Read the mean squared error as a value.

use torch
let p = torch tensor [1.0 0.0]
let t = torch tensor [1.0 0.0]
torch mse_loss $p $t | torch abs | torch value

Intermediate

Absolute error, summed and read.

use torch
let p = torch tensor [1.0 0.0]
let t = torch tensor [0.0 1.0]
torch l1_loss $p $t | torch abs | torch sum | torch value

Advanced

Four steps from a loss to a value.

use torch
let p = torch tensor [1.0]
let t = torch tensor [0.0]
torch l1_loss $p $t | torch abs | torch sum | torch abs | torch value