Structure

MLTextClassifier

A model you train to classify natural language text.

Overview

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

After you train a text classifier, you save it to a Core ML model file. You then use an instance of the NLModel class from the Natural Language framework to read the model file into your app.

Topics

Creating and Training a Model

init(trainingData: MLTextClassifier.DataSource, parameters: MLTextClassifier.ModelParameters)

Creates a classifier from a training set stored in a set of directories.

enum MLTextClassifier.DataSource

A data source for your text classifier.

struct MLTextClassifier.ModelParameters

Parameters that affect the process of training a model.

Evaluating a Model

var trainingMetrics: MLClassifierMetrics

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

var validationMetrics: MLClassifierMetrics

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

func evaluation(on: MLDataTable) -> MLClassifierMetrics

Evaluates the classifier on a test data table.

func evaluation(on: [String : [String]]) -> MLClassifierMetrics

Evaluates the classifier on a test dictionary.

Testing a Model with Unlabeled Data

func prediction(from: String) -> String

Classifies a string with a label.

func predictions(from: [String]) -> [String]

Classifies an array of strings with labels.

Saving a Model

func write(toFile: String, metadata: MLModelMetadata?)

Exports a Core ML model file for use in your app.

func write(to: URL, metadata: MLModelMetadata?)

Exports a Core ML model file for use in your app.

struct MLModelMetadata

Information about a model that’s stored in a Core ML model file.

Inspecting a Model

var model: MLModel

The underlying Core ML model for this text classifier.

let modelParameters: MLTextClassifier.ModelParameters

The configuration parameters that were used to train the model during initialization.

var description: String

A text representation of this model.

var debugDescription: String

A text representation of this model that's suitable for output during debugging.

See Also

Natural Language

Creating a Text Classifier Model

Train a machine learning model to classify natural language text.

struct MLWordTagger

A model you train to classify natural language text at the word level.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software