---
title: NLModel
framework: naturallanguage
role: symbol
role_heading: Class
path: naturallanguage/nlmodel
---

# NLModel

A custom model trained to classify or tag natural language text.

## Declaration

```swift
class NLModel
```

## Overview

Overview With Natural Language, you can create text classifier (MLTextClassifier) or word tagger (MLWordTagger) models. Use NLModel to integrate those models into your app. This integration ensures that your tokenization and tagger configurations are identical when you train your model and use it in your app. If you create a text classifier as described in doc:creating-a-text-classifier-model, you can integrate that model into your app and use it to make predictions like this: let text = "I am very happy."

do {     let mlModel = try SentimentClassifier(configuration: MLModelConfiguration()).model              let customModel = try NLModel(mlModel: mlModel)          // Use the text classifier model to get the most likely label.     if let label = customModel.predictedLabel(for: text) {         print("Most likely label: \(label)")     }          // Get multiple possible labels with their associated confidence scores.     let labelHypotheses = customModel.predictedLabelHypotheses(for: text, maximumCount: 3)     print("Label confidence scores: \(labelHypotheses)")      } catch {     print(error) } If you create a custom word tagger as described in doc:creating-a-word-tagger-model, you can integrate that model into your app and generate tags for new text input like this: let text = "The iPad is my favorite Apple product."

do {     let mlModel = try AppleTagger(configuration: MLModelConfiguration()).model              let customModel = try NLModel(mlModel: mlModel)     let customTagScheme = NLTagScheme("Apple")          let tagger = NLTagger(tagSchemes: [.nameType, customTagScheme])     tagger.string = text     tagger.setModels([customModel], forTagScheme: customTagScheme)          tagger.enumerateTags(in: text.startIndex..<text.endIndex, unit: .word,                           scheme: customTagScheme, options: .omitWhitespace) { tag, tokenRange  in         if let tag = tag {             print("\(text[tokenRange]): \(tag.rawValue)")         }         return true     } } catch {     print(error) }

## Topics

### Creating a model

- [init(mlModel:)](naturallanguage/nlmodel/init(mlmodel:)-9tpjr.md)
- [init(contentsOf:)](naturallanguage/nlmodel/init(contentsof:).md)

### Making predictions

- [predictedLabel(for:)](naturallanguage/nlmodel/predictedlabel(for:).md)
- [predictedLabels(forTokens:)](naturallanguage/nlmodel/predictedlabels(fortokens:).md)
- [predictedLabelHypotheses(for:maximumCount:)](naturallanguage/nlmodel/predictedlabelhypotheses(for:maximumcount:).md)
- [predictedLabelHypotheses(forTokens:maximumCount:)](naturallanguage/nlmodel/predictedlabelhypotheses(fortokens:maximumcount:).md)

### Inspecting a model

- [configuration](naturallanguage/nlmodel/configuration.md)
- [NLModelConfiguration](naturallanguage/nlmodelconfiguration.md)

### Related Documentation

- [MLTextClassifier](createml/mltextclassifier.md)
- [MLWordTagger](createml/mlwordtagger.md)

### Initializers

- [init(MLModel:)](naturallanguage/nlmodel/init(mlmodel:)-4o6g8.md)
- [init(contentsOfURL:)](naturallanguage/nlmodel/init(contentsofurl:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Natural language models

- [Creating a text classifier model](createml/creating-a-text-classifier-model.md)
- [Creating a word tagger model](createml/creating-a-word-tagger-model.md)
