O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Practical Artificial Intelligence with Swift

Book Description

Create and implement AI-based features in your Swift apps for iOS, macOS, tvOS, and watchOS. With this practical book, programmers and developers of all kinds will find a one-stop shop for AI and machine learning with Swift. Taking a task-based approach, you’ll learn how to build features that use powerful AI features to identify images, make predictions, generate content, recommend things, and more.

AI is increasingly essential for every developer—and you don’t need to be a data scientist or mathematician to take advantage of it in your apps. Explore Swift-based AI and ML techniques for building applications. Learn where and how AI-driven features make sense. Inspect tools such as Apple’s Python-powered Turi Create and Google’s Swift for TensorFlow to train and build models.

  • I: Fundamentals and Tools—Learn AI basics, our task-based approach, and discover how to build or find a dataset.
  • II: Task Based AI—Build vision, audio, text, motion, and augmentation-related features; learn how to convert preexisting models.
  • III: Beyond—Discover the theory behind task-based practice, explore AI and ML methods, and learn how you can build it all from scratch... if you want to

Table of Contents

  1. Preface
    1. Resources Used in This Book
    2. Audience and Approach
    3. Organization of This Book
    4. Using This Book
      1. Our Tasks
    5. Conventions Used in This Book
    6. Using Code Examples
    7. O’Reilly Online Learning
    8. How to Contact Us
    9. Acknowledgments
  2. I. Fundamentals and Tools
  3. 1. Artificial Intelligence!?
    1. Practical AI with Swift…and Python?
      1. Code Examples
    2. Why Swift?
      1. Why AI?
    3. What Is AI and What Can It Do?
      1. Deep Learning versus AI?
      2. Where Do the Neural Networks Come In?
      3. Ethical, Effective, and Appropriate Use of AI
    4. Practical AI Tasks
    5. A Typical Task-Based Approach
  4. 2. Tools for Artificial Intelligence
    1. Why Top Down?
    2. Great Tools for Great AI
    3. Tools from Apple
      1. CoreML
      2. CreateML
      3. Turi Create
      4. Apple’s Other Frameworks
      5. CoreML Community Tools
    4. Tools from Others
      1. Swift for TensorFlow
      2. TensorFlow to CoreML Model Converter
      3. Other Converters
    5. AI-Adjacent Tools
      1. Python
      2. Keras, Pandas, Jupyter, Colaboratory, Docker, Oh My!
      3. Other People’s Tools
    6. What’s Next?
  5. 3. Finding or Building a Dataset
    1. Planning and Identifying Data to Target
      1. Negation as Failure
      2. Closed-World Assumptions
    2. Finding a Dataset
      1. Where to Look
      2. What to Look Out for
    3. Building a Dataset
      1. Data Recording
      2. Data Collation
      3. Data Scraping
    4. Preparing a Dataset
      1. Getting to Know a Dataset
      2. Cleaning a Dataset
      3. Transforming a Dataset
      4. Verifying the Suitability of a Dataset
    5. Apple’s Models
  6. II. Tasks
  7. 4. Vision
    1. Practical AI and Vision
    2. Task: Face Detection
      1. Problem and Approach
      2. Building the App
      3. What Just Happened? How Does This Work?
      4. Improving the App
      5. Even More Improvements
    3. Task: Barcode Detection
    4. Task: Saliency Detection
    5. Task: Image Similarity
      1. Problem and Approach
      2. Building the App
      3. What Just Happened? How Does This Work?
      4. Next Steps
    6. Task: Image Classification
      1. Problem and Approach
      2. Building the App
      3. AI Toolkit and Dataset
      4. Incorporating the Model in the App
      5. Improving the App
    7. Task: Drawing Recognition
      1. Problem and Approach
      2. AI Toolkit and Dataset
      3. Building the App
      4. What’s Next?
    8. Task: Style Classification
      1. Converting the Model
      2. Using the Model
    9. Next Steps
  8. 5. Audio
    1. Audio and Practical AI
    2. Task: Speech Recognition
      1. Problem and Approach
      2. Building the App
      3. What Just Happened? How Does This Work?
      4. What’s Next?
    3. Task: Sound Classification
      1. Problem and Approach
      2. Building the App
      3. AI Toolkit and Dataset
      4. Creating a Model
      5. Incorporating the Model in the App
      6. Improving the App
    4. Next Steps
  9. 6. Text and Language
    1. Practical AI, Text, and Language
    2. Task: Language Identification
    3. Task: Named Entity Recognition
    4. Task: Lemmatization, Tagging, and Tokenization
      1. Parts of Speech
      2. Tokenizing a Sentence
    5. Task: Sentiment Analysis
      1. Problem and Approach
      2. Building the App
      3. AI Toolkit and Dataset
      4. Creating a Model
      5. Incorporating the Model in the App
    6. Task: Custom Text Classifiers
      1. AI Toolkit and Dataset
    7. Next Steps
  10. 7. Motion and Gestures
    1. Practical AI, Motion, and Gestures
    2. Task: Activity Recognition
      1. Problem and Approach
      2. Building the App
      3. What Just Happened? How Does This Work?
    3. Task: Gestural Classification for Drawing
      1. Problem and Approach
      2. AI Toolkit and Dataset
      3. Building the App
    4. Task: Activity Classification
    5. Problem and Approach
      1. AI Toolkit and Dataset
    6. Using the Model
    7. Task: Using Augmented Reality with AI
    8. Next Steps
  11. 8. Augmentation
    1. Practical AI and Augmentation
    2. Task: Image Style Transfer
      1. Problem and Approach
      2. Building the App
      3. AI Toolkit and Dataset
      4. Creating a Model
      5. Incorporating the Model in the App
    3. Task: Sentence Generation
      1. What Just Happened? How Does This Work?
    4. Task: Image Generation with a GAN
      1. Problem and Approach
      2. AI Toolkit and Dataset
      3. Building an App
    5. Task: Recommending Movies
      1. Problem and Approach
      2. AI Toolkit and Dataset
      3. Using a Recommender
    6. Task: Regressor Prediction
      1. Problem and Approach
      2. AI Toolkit and Dataset
      3. Using the Regressor in an App
    7. Next Steps
  12. 9. Beyond Features
    1. Task: Installing Swift for TensorFlow
      1. Adding Swift for TensorFlow to Xcode
      2. Installing Swift for TensorFlow with Docker and Jupyter
    2. Using Python with Swift
    3. Task: Training a Classifier Using Swift for TensorFlow
    4. Task: Using the CoreML Community Tools
      1. The Problem
      2. The Process
      3. Using the Converted Model
    5. On-Device Model Updates
    6. Task: Downloading Models On-device
    7. Next Steps
  13. III. Beyond
  14. 10. AI and ML Methods
    1. Terminology
      1. AI/ML Components
      2. AI/ML Objectives
      3. Types of Values
    2. Classification
      1. Methods
      2. Applications
    3. Clustering
      1. Methods
      2. Applications
    4. Next Steps
  15. 11. Looking Under the Hood
    1. A Look Inside CoreML
    2. Vision
      1. Face Detection
      2. Barcode Detection
      3. Saliency Detection
      4. Image Classification
      5. Image Similarity
      6. Bitmap Drawing Classification
    3. Audio
      1. Sound Classification
      2. Speech Recognition
    4. Text and Language
      1. Language Identification
      2. Named Entity Recognition
      3. Lemmatization, Tagging, Tokenization
    5. Recommendations
    6. Prediction
    7. Text Generation
    8. Generation
    9. The Future of CoreML
    10. Next Steps
  16. 12. The Hard Way
    1. Behind CoreML’s Magic
    2. Task: Building XOR
      1. The Shape of Our Network
    3. The Code
      1. Building It Up
      2. Making It Work
      3. Tearing It Down
      4. Using the Neural Network
      5. Approximations of XOR
    4. Training
    5. Next Steps
  17. Index