Implementing a Natural Language Classifier in iOS with Keras + Core ML

(Jeff_L) #1

The wrapper folder contains the following Swift les to implement the


one-hot embedding using the NSLinguistic tagger and to easily wrap


access to the Core ML model. This simplies the annoying creation of


MLMultiArray parameters.


Lemmatizer.swift


BagOfWords.swift


1 2 3 4 5 6 7 8 9

10

11

12

13

14

15

16

17

18

import Foundation

class Lemmatizer {
typealias TaggedToken = (String, String?)

func tag(text: String, scheme: String) -> [TaggedT
let options: NSLinguisticTagger.Options = [.om
let tagger = NSLinguisticTagger(tagSchemes: NS

tagger.string = text

var tokens: [TaggedToken] = []

tagger.enumerateTags(in: NSMakeRange( 0 , text.c
let token = (text as NSString).substring(w
tokens.append((token, tag?.rawValue))
}
Free download pdf