Structure

MLTextClassifier

A model you train to classify natural language text.

Declaration

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 whole documents.

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 Text Classifier

init(trainingData: [String : [String]], parameters: MLTextClassifier.ModelParameters)

Creates a classifier from a training set in a dictionary.

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 a text classifier.

struct MLTextClassifier.ModelParameters

Parameters that affect the process of training a model.

let modelParameters: MLTextClassifier.ModelParameters

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

Assessing Model Accuracy

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.

Evaluating a Text Classifier

Testing a Text Classifier

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 Text Classifier

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

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

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

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

Describing a Text Classifier

var model: MLModel

The underlying Core ML model of the text classifier stored in memory.

var description: String

A text representation of the text classifier.

var debugDescription: String

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

var playgroundDescription: Any

A description of the text classifier shown in a playground.

See Also

Natural Language Processing

Creating a Text Classifier Model

Train a machine learning model to classify natural language text.

struct MLWordTagger

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

struct MLGazetteer

A collection of terms and their labels, which augments a tagger that analyzes natural language text.

struct MLWordEmbedding

Creates and saves a map of strings to vectors, enabling your app to find neighboring, similar strings.