<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 10.14.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateML",
  "identifier" : "/documentation/CreateML/MLTextClassifier",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Create ML"
    ],
    "preciseIdentifier" : "s:8CreateML16MLTextClassifierV"
  },
  "title" : "MLTextClassifier"
}
-->

# MLTextClassifier

A model you train to classify natural language text.

```
struct MLTextClassifier
```

## Overview

Use a text classifier to train a machine learning model you can include in
your app to classify natural language text. The model learns to associate
labels with features of the input text, which can be sentences, paragraphs,
or even entire documents.

After you train a text classifier, you save it to a Core ML model file. You
then use an instance of the
<doc://com.apple.documentation/documentation/NaturalLanguage/NLModel> class
from the <doc://com.apple.documentation/documentation/NaturalLanguage>
framework to read the model file into your app.

## Topics

### Creating and training a text classifier

[`init(trainingData:parameters:)`](/documentation/CreateML/MLTextClassifier/init(trainingData:parameters:))

Creates a text classifier.

[`init(trainingData:textColumn:labelColumn:parameters:)`](/documentation/CreateML/MLTextClassifier/init(trainingData:textColumn:labelColumn:parameters:))

Creates a text classifier.

[`MLTextClassifier.DataSource`](/documentation/CreateML/MLTextClassifier/DataSource)

A data source for a text classifier.

[`MLTextClassifier.ModelParameters`](/documentation/CreateML/MLTextClassifier/ModelParameters-swift.struct)

Parameters that specify model training parameters and validation data.

[`modelParameters`](/documentation/CreateML/MLTextClassifier/modelParameters-swift.property)

The configuration parameters that the text classifier used for training during initialization.

### Evaluating a text classifier

[`evaluation(on:)`](/documentation/CreateML/MLTextClassifier/evaluation(on:))

Computes evaluation metrics.

[`evaluation(on:textColumn:labelColumn:)`](/documentation/CreateML/MLTextClassifier/evaluation(on:textColumn:labelColumn:))

Computes evaluation metrics.

[`trainingMetrics`](/documentation/CreateML/MLTextClassifier/trainingMetrics)

Measurements of the classifier’s performance on the training data set.

[`validationMetrics`](/documentation/CreateML/MLTextClassifier/validationMetrics)

Measurements of the classifier’s performance on the validation data set.

### Testing a text classifier

[`prediction(from:)`](/documentation/CreateML/MLTextClassifier/prediction(from:))

Classifies a string with a label.

[`predictions(from:)`](/documentation/CreateML/MLTextClassifier/predictions(from:))

Classifies an array of strings with labels.

[`predictionWithConfidence(from:)`](/documentation/CreateML/MLTextClassifier/predictionWithConfidence(from:))

Predicts multiple possible labels and their confidence scores for the specified string.

[`predictionsWithConfidence(from:)`](/documentation/CreateML/MLTextClassifier/predictionsWithConfidence(from:))

Predicts multiple possible labels and their confidence scores for each string in the specified array.

### Saving a text classifier

[`write(to:metadata:)`](/documentation/CreateML/MLTextClassifier/write(to:metadata:))

Exports the text classifier as a Core ML model file at the specified URL.

[`write(toFile:metadata:)`](/documentation/CreateML/MLTextClassifier/write(toFile:metadata:))

Exports the text classifier as a Core ML model file at the specified file path.

### Describing a text classifier

[`model`](/documentation/CreateML/MLTextClassifier/model)

The underlying Core ML model of the text classifier.

[`description`](/documentation/CreateML/MLTextClassifier/description)

A text representation of the text classifier.

[`debugDescription`](/documentation/CreateML/MLTextClassifier/debugDescription)

A text representation of the text classifier that’s suitable for output
during debugging.

[`playgroundDescription`](/documentation/CreateML/MLTextClassifier/playgroundDescription)

A description of the text classifier in a playground.

### Supporting types

[`MLTextClassifier.FeatureExtractorType`](/documentation/CreateML/MLTextClassifier/FeatureExtractorType)

The text feature extractor type.

[`MLTextClassifier.ModelAlgorithmType`](/documentation/CreateML/MLTextClassifier/ModelAlgorithmType)

The type of algorithm that a text classifier uses.



---

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)