Practical Artificial Intelligence with Swift
by Mars Geldard , Jonathon Manning , Paris Buttfield-Addison , and Tim Nugent
Copyright 2020 Secret Lab. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Acquisition Editor: Rachel Roumeliotis
- Developmental Editor: Michele Cronin
- Production Editor: Nan Barber
- Copyeditor: Kim Cofer
- Proofreader: Octal Publishing, LLC
- Indexer: WordCo Indexing Services, Inc.
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Rebecca Demarest
- October 2019: First Edition
Revision History for the First Edition
- 2019-10-18: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781492044819 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. Practical Artificial Intelligence with Swift, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
The views expressed in this work are those of the authors, and do not represent the publishers views. While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-492-04481-9
[LSI]
Praise for Practical Artificial Intelligence with Swift
In the long run, the vast majority of AI will be consumed not in data centers, but where the data actually areon billions of real-world devices. With its combination of speed and expressiveness, Swift has emerged as the language of choice to enable this transition. This book provides a fantastic introduction to the tools forming the foundation of the next decade of AI.
Dr. Jameson Toole, Cofounder and CTO of Fritz AI
The importance of bananas and apples to machine learning developers cannot be overstated. Fortunately this book has a sufficiency of both, or at least, enough to be getting on with. So if, like me, youre starting to suspect that the future of machine learning is on device, this book is a good place to get started.
Dr. Alasdair Allan, Babilim Light Industries
Over the past several years, AI has transitioned from academia and science fiction to a pragmatic technology for solving real-world problems. This book shows how to bring AI right to the palm of your hand, implementing ML capabilities that are only now becoming possible. Im incredibly excited to see what readers do with what they learn from this book.
Chris Devers, Technical Lead of Sustaining Engineering, EditShare
Preface
Welcome to Practical Artificial Intelligence with Swift.
This book takes a task-based approach to practical implementations of artificial intelligence (AI) using Swift. We do this because we think that you shouldnt need to dive deep into complicated mathematics and algorithms in order to have clever AI- and machine learning-driven features in your iOS application. AI shouldnt be a specialist area thats available only to AI experts. AI should be accessible.
We live in a world where these techniques are becoming more than commonplace. Theyre becoming part of the fabric of how we interact with computers. Because of the incredible power of machine learning, and its ability to impact, benefit, influence, and control human beings, its as important for people to be able to have knowledge over how to build and understand artificial intelligence as it was to know how to operate a computer.
To that end, this book is designed to give you a practical understanding of common machine learning tasks. With these, youll be able to build better tools, and understand the behaviour of the tools used by others in the wider world. Were glad youre here. Lets build the machine.
Resources Used in This Book
We recommend following along with the book by writing code yourself as you progress through each chapter. If you become stuck, or just want to archive a copy of the code, you can find what you need via our website.
Audience and Approach
This book is written for people who already know how to program in Swift, and want to learn about the specific features and techniques that power machine learning. This isnt a book that will teach you the basics of programming, which means that the examples will expect a reasonable familiarity with the language.
In addition to using Swift, well occasionally dip into Python from time to time. Python is incredibly common in the world of machine learning and artificial intelligence. The meat of the book is in Swift, though, and we explain why whenever were using Python. Were going to remind you about this a few times.
Finally, we also assume that youre fairly comfortable navigating macOS and iOS as a user, and that you have access to a Mac to develop on, as well as an iOS device to test on, for the tasks that require certain sensors, like motion tracking or analysing the camera.
Organization of This Book
This book is divided into three parts.
In , we introduce the fundamental ideas behind machine learning and artificial intelligence. We set you up with the languages and tools youll be using, and get you ready to build useful things.
In , we visit a wide range of interesting topics, ranging from computer vision, audio, motion, and language. For each topic, well present and build an app that highlights various techniques and APIs; at the end of each chapter, youll have a complete working demo app that shows off a practical task that your code can now accomplish.
In in detail. Well look closely at the theory of machine learning, and provide a deeper understanding of what it is that your device is actually doing.
Using This Book
We want this book to be deeply founded in the practical. Because of this, weve structured it around the practical tasks that you might want to do when dealing with artificial intelligence and Swift. Weve split the book into three parts.
).
) to explore the more advanced tools and frameworks we touched on at the end of the first part. We outline what each of the tasks entails in the next section.
).
Our Tasks
In this book, we cover the following tasks in the following domains:
The bulk of this book is dedicated to exploring how you can implement AI-driven things in your apps, (mostly) using Swift. Because we take a top-down, task-focused perspective to AI, we decided to front load our discussion of the tools that you might encounter. We do this in .
There, we explore some of the tools that you can use to create models for machine learning and AI tasks with Swift as well as some of the tools for manipulating models, working with data, and generally doing practical AI things with Swift.