<!--
{
  "availability" : [
    "iOS: 14.0.0 - 17.4.0",
    "iPadOS: 14.0.0 - 17.4.0",
    "macCatalyst: 14.0.0 - 17.4.0",
    "macOS: 11.0.0 - 14.3.0",
    "tvOS: 14.0.0 - 17.4.0"
  ],
  "documentType" : "symbol",
  "framework" : "MLCompute",
  "identifier" : "/documentation/MLCompute/MLCLossLayer",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "ML Compute"
    ],
    "preciseIdentifier" : "c:objc(cs)MLCLossLayer"
  },
  "title" : "MLCLossLayer"
}
-->

# MLCLossLayer

A layer that estimates the inaccuracies of the model to reduce the loss on the next evaluation.

```
class MLCLossLayer
```

## Topics

### Creating Loss Layers with Descriptors

[`init(descriptor:)`](/documentation/MLCompute/MLCLossLayer/init(descriptor:))

Creates a loss layer with the descriptor you specify.

[`init(descriptor:weights:)`](/documentation/MLCompute/MLCLossLayer/init(descriptor:weights:))

Creates a loss layer with the descriptor and weights you specify.

[`MLCLossDescriptor`](/documentation/MLCompute/MLCLossDescriptor)

A configuration object you use to create a loss layer.

[`MLCLossType`](/documentation/MLCompute/MLCLossType)

A loss function.

### Creating Loss Layers with Scalar Weights

[`softmaxCrossEntropy(reductionType:labelSmoothing:classCount:weight:)`](/documentation/MLCompute/MLCLossLayer/softmaxCrossEntropy(reductionType:labelSmoothing:classCount:weight:))

Creates a softmax cross entropy loss layer with the reduction type, label smoothing, number of classes, and weight you specify.

[`categoricalCrossEntropy(reductionType:labelSmoothing:classCount:weight:)`](/documentation/MLCompute/MLCLossLayer/categoricalCrossEntropy(reductionType:labelSmoothing:classCount:weight:))

Creates a categorical cross entropy loss layer with the reduction type, label smoothing, number of classes, and weight you specify.

[`sigmoidCrossEntropy(reductionType:labelSmoothing:weight:)`](/documentation/MLCompute/MLCLossLayer/sigmoidCrossEntropy(reductionType:labelSmoothing:weight:))

Creates a sigmoid cross entropy loss layer with the reduction type, label smoothing, and weight you specify.

[`log(reductionType:epsilon:weight:)`](/documentation/MLCompute/MLCLossLayer/log(reductionType:epsilon:weight:))

Creates a log loss layer with the reduction type, epsilon, and weight you specify.

[`huberLoss(reductionType:delta:weight:)`](/documentation/MLCompute/MLCLossLayer/huberLoss(reductionType:delta:weight:))

Creates a huber loss layer with the reduction type, delta, and weight you specify.

[`meanAbsoluteError(reductionType:weight:)`](/documentation/MLCompute/MLCLossLayer/meanAbsoluteError(reductionType:weight:))

Creates a mean absolute loss layer with the reduction type and weight.

[`meanSquaredError(reductionType:weight:)`](/documentation/MLCompute/MLCLossLayer/meanSquaredError(reductionType:weight:))

Creates a mean squared loss layer with the reduction type and weight you specify.

[`hingeLoss(reductionType:weight:)`](/documentation/MLCompute/MLCLossLayer/hingeLoss(reductionType:weight:))

Creates a hinge loss layer with the reduction type and weight you specify.

[`cosineDistance(reductionType:weight:)`](/documentation/MLCompute/MLCLossLayer/cosineDistance(reductionType:weight:))

Creates a cosine distance loss layer with the reduction type and weight you specify.

### Creating Loss Layers with Tensor Weights

[`softmaxCrossEntropy(reductionType:labelSmoothing:classCount:weights:)`](/documentation/MLCompute/MLCLossLayer/softmaxCrossEntropy(reductionType:labelSmoothing:classCount:weights:))

Creates a softmax cross entropy loss layer with the reduction type, label smoothing, number of classes, and weights you specify.

[`categoricalCrossEntropy(reductionType:labelSmoothing:classCount:weights:)`](/documentation/MLCompute/MLCLossLayer/categoricalCrossEntropy(reductionType:labelSmoothing:classCount:weights:))

Creates a categorical cross entropy loss layer with the reduction type, label smoothing, number of classes, and weights you specify.

[`sigmoidCrossEntropy(reductionType:labelSmoothing:weights:)`](/documentation/MLCompute/MLCLossLayer/sigmoidCrossEntropy(reductionType:labelSmoothing:weights:))

Creates a sigmoid cross entropy loss layer with the reduction type, label smoothing, and weights you specify.

[`log(reductionType:epsilon:weights:)`](/documentation/MLCompute/MLCLossLayer/log(reductionType:epsilon:weights:))

Creates a log loss layer with the reduction type, epsilon, and weights you specify.

[`huberLoss(reductionType:delta:weights:)`](/documentation/MLCompute/MLCLossLayer/huberLoss(reductionType:delta:weights:))

Creates a huber loss layer with the reduction type, delta, and weights you specify.

[`meanAbsoluteError(reductionType:weights:)`](/documentation/MLCompute/MLCLossLayer/meanAbsoluteError(reductionType:weights:))

Creates a mean absolute loss layer with the reduction type and weights you specify.

[`meanSquaredError(reductionType:weights:)`](/documentation/MLCompute/MLCLossLayer/meanSquaredError(reductionType:weights:))

Creates a mean squared loss layer with the reduction type and weights you specify.

[`hingeLoss(reductionType:weights:)`](/documentation/MLCompute/MLCLossLayer/hingeLoss(reductionType:weights:))

Creates a hinge loss layer with the reduction type and weights you specify.

[`cosineDistance(reductionType:weights:)`](/documentation/MLCompute/MLCLossLayer/cosineDistance(reductionType:weights:))

Creates a cosine distance loss layer with the reduction type and weights you specify.

### Inspecting Loss Layers

[`descriptor`](/documentation/MLCompute/MLCLossLayer/descriptor)

The configuration object you use to create the loss layer.

[`weights`](/documentation/MLCompute/MLCLossLayer/weights)

The loss label weights tensor.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)