NLP in Swift

🏴󠁧󠁢󠁷󠁬󠁳󠁿 iOSDevUK on 4 Sep 2019
iOS NLP Swift
NLP in Swift

It's not a secret that for the majority of NLP tasks people tend to use either Python, Java, or R, nonetheless due to a wide range of frameworks and libraries. However, recently Apple came up with a native Natural Language framework for Swift. In this talk we will learn how to detect language, tokenise sentences, detect names of people and places, identify parts of the speech. In other words, make apps relying on text interaction way more precise and fast.

About this talk

What does this talk cover?

Apple's NaturalLanguage framework in Swift: detecting a text's language, tokenising sentences, finding names of people and places, tagging parts of speech, and lemmatisation - on-device NLP without reaching for Python or R.

Which Apple frameworks does the talk use?

NaturalLanguage.framework (iOS 12 and later) - NLTokenizer and NLTagger with their tagging schemes - with a nod to the older NSLinguisticTagger it replaced. Every example is plain Swift that runs on device.

Why do NLP on the phone instead of a server?

Four reasons from the talk: it's cheap, it's fast, there's no vendor to depend on, and the text never leaves the device.

Why is sentence splitting harder than splitting on full stops?

Because 'J. Bond will complain to M.I.6' splits into four pieces if you try - the talk shows the failure and how NLTokenizer's sentence unit copes with abbreviations and initialisms.

Where can I get the slides and the sample code?

The slide deck (PDF) and the companion GitHub repository with the sample code are both in the resources section on this page.

Related consulting

Shipping on-device language features is client work I take on: NaturalLanguage, Core ML, and converting models from Python.

Core ML & On-Device AI