What is machine learning? How does it work? You will find the answers to all these questions in this article.
First of all, machine learning is an algorithm, a really complex one. This algorithm can learn to predict an outcome for an input it had never seen before. Pretty cool right? Well, this is possible only after the algorithm was trained on a set of similar data. So, let’s say you want your app to be able to recognize different objects. First, you need to prepare a set of images, each one labeled with the name of the object that is in that photo. So you will have a folder named chair, where you will keep all the photos of chairs, another one named sunglasses, with all the sunglasses images, and so on. After that, you will have to write an algorithm based on a neural network that will be trained with the data previously prepared. Now you can think of this algorithm as a function that will have an input, the image of the object you want to identify, and an output, the name of that object.
How can you write that algorithm? How can you integrate it into your app? This is where Apple steps in. They created a set of frameworks that make our lives easier when it comes to machine learning: CreateML, Vision, Natural Language, and CoreML.
CreateML is used for creating and training the model. A model is a file containing all the logic, the algorithm. If your task is a simple one you can find a model already available online. If not, you can create it yourself using this framework. There are 2 ways you can do this:
- using Playground or from Xcode 11 and macOS Catalina there is a CreateML developer tool available; this way you can create the model once and add it to your project
- on the backend side, using Swift Perfect, if you need to be able to retrain your model
If you prefer to use another tool for creating the model, like Keras or Caffe, you will have to convert your model into CoreML format. For this, you can use coremltools, a Python package that can be used to do this conversion.
The Vision framework applies computer vision algorithms for processing images and videos. It has features like:
- face and face landmark detection
- text detection
- barcode recognition
- feature tracking
You can use a Core ML model with Vision when you want to process and classify images. Using these technologies you’ll be able to recognize objects or faces and identify them using your iPhone’s camera.
Natural Language (NLP)
If your machine learning feature is based on text or speech input you have to use Natural Language Framework. It has the following features:
- language identification: it can detect the language of a certain text
- tokenization: can separate a text into paragraphs, sentences or words
- parts-of-speech tagging: it can assign a part-of-speech tag to every word of a text (preposition, noun, verb, etc.)
- lemmatization: it can extract the root form of a word (was -> be)
- named entity recognition: it can detect names of persons, locations or organizations
These features combined with CoreML can lead to some really cool and nice to have functionalities, like better auto-complete, better search results and so on.
CoreML is the framework that lets you build and compile a Core ML model to add machine learning features to your app. It’s available on all Apple platforms. If you want to see exactly how you can do that, you can follow my tutorial here.
Thanks for reading! If you have any questions leave me a comment below 🙏 .
Zipper Studios is a group of passionate engineers helping startups and well-established companies build their mobile products. Our clients are leaders in the fields of health and fitness, AI, and Machine Learning. We love to talk to likeminded people who want to innovate in the world of mobile so drop us a line here.