Structure

MLWordTagger

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

Declaration

struct MLWordTagger

Overview

Use an MLWordTagger to create a custom word tagger to identify content that’s relevant your app, like product names and points of interest.

To use your custom word tagger in the Natural Language framework, save it to a model file and import it into an NLModel. Then add your custom NLModel to an NLTagger with its setModels(_:forTagScheme:) method.

Topics

Creating and Training a Word Tagger

init(trainingData: [(tokens: [MLWordTagger.Token], labels: [String])], parameters: MLWordTagger.ModelParameters)

Creates a word tagger from a training set in an array of tokens and their labels.

typealias MLWordTagger.Token

The token type of a word tagger, which is String.

struct MLWordTagger.ModelParameters

Parameters that affect the process of training a model.

let modelParameters: MLWordTagger.ModelParameters

The configuration parameters that the word tagger used for training during initialization.

Assessing Model Accuracy

var trainingMetrics: MLWordTaggerMetrics

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

var validationMetrics: MLWordTaggerMetrics

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

struct MLWordTaggerMetrics

Metrics used to evaluate a word tagger’s performance.

Evaluating a Word Tagger

func evaluation(on: MLDataTable, tokenColumn: String, labelColumn: String) -> MLWordTaggerMetrics

Generates metrics describing the tagger’s performance on labeled data provided in a data table.

func evaluation(on: [(tokens: [MLWordTagger.Token], labels: [String])]) -> MLWordTaggerMetrics

Generates metrics describing the tagger’s performance on labeled tokens provided in a dictionary.

Testing a Word Tagger

func prediction(from: [MLWordTagger.Token]) -> [String]

Tags each input token in the given array.

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

Tags each token in the given string.

Saving a Word Tagger

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

Exports the word tagger as a Core ML model file at the given URL.

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

Exports the word tagger as a Core ML model file at the given file path.

Describing a Word Tagger

var model: MLModel

The underlying Core ML model of the word tagger stored in memory.

var description: String

A text representation of the word tagger.

var debugDescription: String

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

var playgroundDescription: Any

A description of the word tagger 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 MLTextClassifier

A model you train to classify natural language text.

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.