lvjian700
7/11/2017 - 4:08 AM

Core ML Workshop part 1

Core ML Workshop part 1

Prepare

Agenda

  • Summarize the WWDC sessions ( 10 mins )
  • Core ML - Let's try Core ML model ( 30 mins )
  • Core ML - Natural Language Processing ( 30 mins )

Summarize the WWDC sessions

The videos: https://trello.com/c/P2UOxAbc/10-rock-of-wwdc-core-ml

The summaries

Core ML - Let's try Core ML model

https://www.evernote.com/shard/s392/sh/b954eff6-7ab9-4322-ab9d-b97a97bd1b7d/8854e845f7af251b

Core ML - Natural Language Processing

1. Detech the Language

Inputs:

let ja = "グレート・ティーチャー・オニヅカ"
let zh = "内啥,借个设备"
let en = "Mr. Tim Cook presided over the earnings report of Apple. The stock was up 3% after hours."

Steps:

// 1. Create a `NSLinguisticTagger` base on scheme `.language`
// 2. Set `string` to `tagger`
// 3. Get `dominantLanguage`

2. Tokenization

Input:

let mixedText = "NSLinguisticTagger provides text processing APIs.\n NSLinguisticTagger 是苹果的文字处理平台。"

Expected output:

["NSLinguisticTagger", "provides", "text", "processing", "APIs", "NSLinguisticTagger", "是", "苹果", "的", "文字", "处理", "平台"]

Steps:

// 1. Create a `NSLinguisticTagger` base on scheme `.tokenType`
// 2. Set `string` to `tagger`
// 3. Create a token range: `let tokenRange = NSRange(location: 0, length: mixedText.utf16.count)`
// 4. Create a token Options: `let tokenOptions: NSLinguisticTagger.Options = [NSLinguisticTagger.Options.omitPunctuation, .omitWhitespace]`
// 5. enumerateTags

3. Lemmatization

Input:

let lemText = "Great hikes make great pics! Wonderful afternoon in Marin County."

Expected output:

["great", "hike", "make", "great", "pic", "wonderful", "afternoon", "in", "Marin", "county"]

Steps:

// 1. Create a `NSLinguisticTagger` base on scheme `.lemma`
// 2. Set `string` to `tagger`
// 3. Create a token range: `let lemRange = NSRange(location: 0, length: lemText.utf16.count)`
// 4. Create a token Options: `let lemOptions: NSLinguisticTagger.Options = [.omitPunctuation, .omitWhitespace]`
// 5. enumerateTags

4. Named Entity Recognition

Input:

let namedText = "Tim Cook is the CEO of Apple Inc. which is located in Cupertino, Californi. Lv Jian is a iOS developer in Xian of Thoughtworks."

Expected output:

["Tim Cook", "Apple Inc.", "Cupertino", "Californi", "Xian", "Thoughtworks"]

Steps:

// 1. Create a `NSLinguisticTagger` base on scheme `.nameType`
// 2. Set `string` to `tagger`
// 3. Create a token range: `let namedRange = NSRange(location: 0, length: namedText.utf16.count)`
// 4. Create a token Options: `let namedOptions: NSLinguisticTagger.Options = [.omitPunctuation, .omitWhitespace, .joinNames]`
// 5. Create a namedTagsOption: `let namedTags: [NSLinguisticTag] = [.personalName, .placeName, .organizationName]`
// 6. enumerateTags