SigmoidCrossEntropyWithLogits
Stay organized with collections
Save and categorize content based on your preferences.
Inherited Methods
From class
java.lang.Object
boolean
|
equals(Object arg0)
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
Public Constructors
public
SigmoidCrossEntropyWithLogits
()
Public Methods
public
static
Operand<T>
sigmoidCrossEntropyWithLogits
(Scope scope, Operand<T> labels, Operand<T> logits)
Computes sigmoid cross entropy given logits
.
Measures the probability error in discrete classification tasks in which each class is
independent and not mutually exclusive. For instance, one could perform multilabel
classification where a picture can contain both an elephant and a dog at the same time.
For brevity, let x = logits
, z = labels
. The logistic loss in
pseudo-code is
z * -log(sigmoid(x)) + (1 - z) * -log(1 - sigmoid(x))
= z * -log(1 / (1 + exp(-x))) + (1 - z) * -log(exp(-x) / (1 + exp(-x)))
= z * log(1 + exp(-x)) + (1 - z) * (-log(exp(-x)) + log(1 + exp(-x)))
= z * log(1 + exp(-x)) + (1 - z) * (x + log(1 + exp(-x))
= (1 - z) * x + log(1 + exp(-x))
= x - x * z + log(1 + exp(-x))
For x < 0
, to avoid overflow in exp(-x)
, we reformulate the above
x - x * z + log(1 + exp(-x))
= log(exp(x)) - x * z + log(1 + exp(-x))
= - x * z + log(1 + exp(x))
Hence, to ensure stability and avoid overflow, the implementation uses this equivalent
formulation
max(x, 0) - x * z + log(1 + exp(-abs(x)))
logits and labels
must have the same type and shape.
Parameters
scope |
The TensorFlow scope |
labels |
the labels |
logits |
the logits of type float32 or float64 |
Returns
- the component-wise logistic losses.
Throws
IllegalArgumentException |
if logits' and labels' do not have the same shape
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2021-11-29 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2021-11-29 UTC."],[],[],null,["# SigmoidCrossEntropyWithLogits\n\npublic class **SigmoidCrossEntropyWithLogits** \n\n### Public Constructors\n\n|---|------------------------------------------------------------------------------------------------------------------------------------------|\n| | [SigmoidCrossEntropyWithLogits](/jvm/api_docs/java/org/tensorflow/op/nn/SigmoidCrossEntropyWithLogits#SigmoidCrossEntropyWithLogits())() |\n\n### Public Methods\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static \\\u003cT extends [TNumber](/jvm/api_docs/java/org/tensorflow/types/family/TNumber)\\\u003e [Operand](/jvm/api_docs/java/org/tensorflow/Operand)\\\u003cT\\\u003e | [sigmoidCrossEntropyWithLogits](/jvm/api_docs/java/org/tensorflow/op/nn/SigmoidCrossEntropyWithLogits#sigmoidCrossEntropyWithLogits(org.tensorflow.op.Scope, org.tensorflow.Operand\u003cT\u003e, org.tensorflow.Operand\u003cT\u003e))([Scope](/jvm/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](/jvm/api_docs/java/org/tensorflow/Operand)\\\u003cT\\\u003e labels, [Operand](/jvm/api_docs/java/org/tensorflow/Operand)\\\u003cT\\\u003e logits) Computes sigmoid cross entropy given `logits`. |\n\n### Inherited Methods\n\nFrom class java.lang.Object \n\n|------------------|---------------------------|\n| boolean | equals(Object arg0) |\n| final Class\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| String | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Constructors\n-------------------\n\n#### public\n**SigmoidCrossEntropyWithLogits**\n()\n\n\u003cbr /\u003e\n\nPublic Methods\n--------------\n\n#### public static [Operand](/jvm/api_docs/java/org/tensorflow/Operand)\\\u003cT\\\u003e\n**sigmoidCrossEntropyWithLogits**\n([Scope](/jvm/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](/jvm/api_docs/java/org/tensorflow/Operand)\\\u003cT\\\u003e labels, [Operand](/jvm/api_docs/java/org/tensorflow/Operand)\\\u003cT\\\u003e logits)\n\nComputes sigmoid cross entropy given `logits`.\n\nMeasures the probability error in discrete classification tasks in which each class is\nindependent and not mutually exclusive. For instance, one could perform multilabel\nclassification where a picture can contain both an elephant and a dog at the same time.\n\nFor brevity, let `x = logits`, `z = labels`. The logistic loss in\npseudo-code is\n\n```\n z * -log(sigmoid(x)) + (1 - z) * -log(1 - sigmoid(x))\n = z * -log(1 / (1 + exp(-x))) + (1 - z) * -log(exp(-x) / (1 + exp(-x)))\n = z * log(1 + exp(-x)) + (1 - z) * (-log(exp(-x)) + log(1 + exp(-x)))\n = z * log(1 + exp(-x)) + (1 - z) * (x + log(1 + exp(-x))\n = (1 - z) * x + log(1 + exp(-x))\n = x - x * z + log(1 + exp(-x))\n \n```\n\nFor `x \u003c 0`, to avoid overflow in `exp(-x)`, we reformulate the above\n\n```\n x - x * z + log(1 + exp(-x))\n = log(exp(x)) - x * z + log(1 + exp(-x))\n = - x * z + log(1 + exp(x))\n \n```\n\nHence, to ensure stability and avoid overflow, the implementation uses this equivalent\nformulation\n\n```\n max(x, 0) - x * z + log(1 + exp(-abs(x)))\n \n```\n\nlogits and `labels` must have the same type and shape.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| scope | The TensorFlow scope |\n| labels | the labels |\n| logits | the logits of type float32 or float64 |\n|--------|---------------------------------------|\n\n##### Returns\n\n- the component-wise logistic losses. \n\n##### Throws\n\n| IllegalArgumentException | if logits' and labels' do not have the same shape |\n|--------------------------|---------------------------------------------------|"]]