How to Build a Text Classification Model with Create ML

Step-by-step instructions for training a text classifier in Create ML — for sentiment, topic, or intent detection — and turning it into a Core ML model your iOS app can run on-device.

When to Use a Text Classifier

A text classifier assigns a label to a piece of text. Common examples are sentiment analysis (positive, negative, neutral), topic tagging, or intent detection for a support inbox.

Create ML's text classification template is built for exactly this. You provide labeled text examples, and it trains a model that predicts a label for new, unseen text.

This is a great fit for on-device features like categorizing user notes, flagging feedback tone, or routing messages — all without sending text to a server.

As always, keep the scope clear. Create ML produces a Core ML model. You still build the app in Xcode and ship it through the standard Apple pipeline.

Step 1: Prepare Your Labeled Text Data

Text classification needs examples paired with labels. Create ML accepts a couple of common structures, including a folder-per-label layout of text files, or a single structured file like JSON or CSV with a text column and a label column.

The CSV or JSON approach is often the most convenient. Each row holds one text sample and its correct label, for example a review and the word positive or negative.

Quality matters more than volume. Labels should be consistent — decide clear rules for edge cases before labeling, so borderline examples do not contradict each other.

Balance your classes. If most of your rows are positive, the model can score well by simply guessing positive, which is useless in practice.

Step 2: Start a Text Classifier Project

Open the Create ML app and choose New Document, then select the Text Classification template. Name the project and pick a location.

The interface mirrors the other templates: wells for training data, validation, and testing, plus tabs for training, evaluation, and preview.

If you are more comfortable in code, note that Create ML also has a Swift framework. You can script text classifier training programmatically, which is useful for reproducible retraining. For a first model, the app is the fastest route.

Have your data file or folder ready before you start so you can drag it straight in.

Step 3: Import Data and Choose Columns

Drag your training data into the Training Data well. If you are using a CSV or JSON file, Create ML will ask you to identify which column holds the text and which holds the label.

Select those columns carefully. Pointing the model at the wrong column is a common early mistake that produces meaningless results.

Reserve a separate testing set that the model does not train on. This gives you an honest accuracy figure later.

Confirm the label list that Create ML detects. If you see an unexpected label — often caused by a typo or inconsistent casing like Positive versus positive — fix it in your data now.

Step 4: Pick an Approach and Train

Create ML's text classifier offers different underlying approaches, including transfer-learning-based feature extractors and more classic algorithms. The defaults are a reasonable starting point.

Approaches built on Apple's pre-trained language features can capture more nuance but may take longer or produce larger models. Simpler approaches train fast and stay small. Try the default first, then experiment.

Click Train and watch the accuracy climb. As with images, compare training accuracy against validation accuracy to spot overfitting.

Text models can overfit quickly on small datasets by memorizing specific phrases. If validation accuracy lags well behind training accuracy, you likely need more varied examples.

Step 5: Evaluate and Preview

Open the Evaluation tab and run your held-out test set. Review precision and recall per class where available, not just overall accuracy.

Precision and recall matter because they reveal different failures. A sentiment model might catch most negative reviews (high recall) but also wrongly flag many neutral ones (low precision).

Use the Preview tab to type or paste in fresh sentences and see live predictions with confidence scores. Try tricky, sarcastic, or ambiguous inputs — that is where real text data gets hard.

If a particular class underperforms, gather more examples for it, especially the confusing edge cases. Improving the data almost always beats fiddling with settings.

Step 6: Export and Integrate with Natural Language

When you are happy with the results, export the model as a Core ML file. Give it a descriptive name because that becomes the generated Swift class in Xcode.

Drag the model into your Xcode project and confirm it is added to your app target. Xcode generates the interface automatically.

Apple's Natural Language framework is the natural companion for text models. It can load your Create ML text classifier and run predictions with minimal code, and it also handles tokenization and language basics.

Running on-device means classification works offline and keeps user text private on the device — a strong selling point for messaging, notes, and journaling apps.

Handling Ambiguous and Multi-Label Text

Real text rarely fits neatly into one bucket, so it helps to think through ambiguity before you train.

Some inputs genuinely belong to more than one category. A support message can be both a complaint and a feature request. A single-label classifier forces one answer, so decide up front whether you need mutually exclusive classes or a different design that allows multiple labels.

Ambiguous inputs also expose weak labeling rules. If two reasonable people would tag the same sentence differently, the model inherits that inconsistency and its accuracy suffers. Writing down concrete labeling guidelines, with example sentences for each class, keeps your dataset coherent.

Be deliberate about a neutral or other category as well. Without one, the model is forced to squeeze every input into a defined class, which produces confident but wrong answers on text that fits none of them. A catch-all class often makes the whole system behave more sensibly.

Finally, plan for language and tone drift. Slang, product names, and phrasing shift over time, so the sentences your classifier sees a year from now may not look like today's training data. Revisiting the dataset periodically keeps the model honest.

Step 7: Test, Retrain, and Ship

Test the integrated model on a real device with realistic input. Text that looks fine in the Preview tab can behave differently once it comes from actual users with typos, emoji, and slang.

Plan for retraining. Language drifts and your categories evolve, so keep your Create ML project and dataset so you can add examples and re-export later.

Version your models. Naming exports clearly and tracking which app release used which model saves confusion when you compare behavior over time.

And close the loop honestly. Create ML trained the classifier, but shipping to users still requires building and signing in Xcode and distributing via the App Store with an Apple Developer Program membership.

Frequently Asked Questions

What data format does the Create ML text classifier accept?

It supports labeled text in common structures, including a folder-per-label layout of text files or a structured file such as CSV or JSON with a text column and a label column. You tell Create ML which columns to use.

Can Create ML do sentiment analysis?

Yes. Sentiment analysis is a classic text classification task — you label examples as positive, negative, or neutral and train a classifier that predicts sentiment for new text on-device.

Which framework runs the text model in my app?

Apple's Natural Language framework can load and run a Create ML text classifier with very little code, and Core ML handles the underlying on-device inference.

Why does my text model overfit so fast?

Text models can memorize specific phrases when the dataset is small or unbalanced. Add more varied examples per class, balance your labels, and keep a separate test set to measure real generalization.

Does text classification work without an internet connection?

Yes. Because the model runs on-device through Core ML, classification works offline and the text never has to leave the user's device.