Classifying Movie Reviews With Natural Language Framework

Exploring Apple’s new built-in sentiment analysis and NLP’s Text classification on a Rotten Tomatoes dataset

Photo by Felix Mooneeram on Unsplash

Apple showed some good progress in the field of Natural Language Processing during WWDC 2019. They’ve brought enhancements in both Text Classification And Word Tagging, the two pillars of NLP.

In this article, we’ll be discussing the advancements in Text Classification only, which deals with classifying input text to a set of predefined class labels.

This year, Apple brings in the transfer learning technique for text classifiers model training. Transfer learning pays heed to the semantics of the overall context of the text and is able to figure out cases where the same word has different meanings in different parts of the text.

Though state of the art transfer learning is better equipped for semantic analysis, it does take a bit longer time to train than a say, maximum entropy algorithm.

Apple also introduces built-in sentiment analysis this year. Using the NLP framework, now you get a score in the range -1 to 1 signifying the degree of sentiment.

Here’s a sample code showing how NLP’s built-in sentiment analysis predicts the sentiment score in a string:

import NaturalLanguage tagger.string = text let (sentiment, _) = tagger.tag(at: text.startIndex, unit: .paragraph, scheme: .sentimentScore) print(sentiment.rawValue)

The built-in sentiment analysis is pretty accurate as we can see below:

A sample SwiftUI preview with NLP Sentiment Analysis

In the next sections, we’ll be using Rotten Tomatoes dataset to create a Text Classifier Core ML Model using Create ML and deploy it in our Natural Language Framework.