bernoulli
bernoulli(
f,
*,
kind,
targets=None,
generator=None,
mc_samples=1,
grouping='full',
)Factors of the sigmoid binary cross-entropy loss.
The exact square root is sqrt(p (1 - p)) on the diagonal. An MC draw is (y - p) / sqrt(S) with y ~ Bernoulli(p), and the empirical factor is y - p at the targets.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| f | Tensor | Logits [N, ..., K]. The last axis holds the columns, the others positions. |
required |
| kind | Kind | "exact", "mc" or "empirical". |
required |
| targets | Tensor | None | Labels in [0, 1] of f’s shape (soft labels are fine). Needed for "empirical". |
None |
| generator | torch.Generator | None | Random generator for "mc". |
None |
| mc_samples | int | Number of draws S for "mc". |
1 |
| grouping | Grouping | How exact factors of several positions are grouped. | 'full' |
Returns
| Name | Type | Description |
|---|---|---|
| OutputFactors | Factors [E, *f.shape]. |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | Unknown kind or grouping, or mc_samples < 1. |
|
| FactorError | f has no output axis, or the targets are missing or of the wrong shape. |