18. @differentiable
@differentiable
func square1(_ x: Float) -> Float {
return x * x
}
@differentiable
func square2(_ x: Float) -> Float {
return x * x * x * x
}
let x: Float = 3.0
print(gradient(at: x, in: square1)) // x^2, 6.0
print(gradient(at: x, in: square2)) // 4*x^3, 108.0
19. Python Interoperability
// NumPy example:
import Python
let np = Python.import("numpy") // import numpy as np
let a = np.arange(15).reshape(3, 5) // a = np.arange(15).reshape(3, 5)
let b = np.array([6, 7, 8]) // b = np.array([6, 7, 8])
// Pickle example:
let gzip = Python.import("gzip") // import gzip as gzip
let pickle = Python.import("pickle") // import pickle as pickle
let file = gzip.open("mnist.pkl.gz", "rb") // file = gzip.open("mnist.pkl.gz", "rb")
// (images, labels) = pickle.load(file)
let (images, labels) = pickle.load(file).tuple2
print(images.shape) // (50000, 784) print(images.shape)
20. Swift
• Performance
• Concurrency
Swift C-based low-level .
Swift compile , .
Tensorflow Swift Tensor compile-time .
Swift pthread API . Python .
Swift Dispatch() (async/await) .
21. Disadvantages of Swift
• New language: Swift , Python native .
• Windows support: BSD, Linux, UNIX .
• Small data-science community: Python data-science .
30. Which one is Next-generation platform?
Swift is Next-generation platform of TensorFlow
But, Python is still dominient.
Python and Swift are in a complement relationship
31. • Tensorflow github : https://github.com/tensorflow/
• Swift for Tensorflow github : https://github.com/tensorflow/swift
• Swift for Tensorflow : https://www.tensorflow.org/swift
• Swift for Tensorflow Design Overview : https://github.com/tensorflow/swift/blob/master/docs/
DesignOverview.md
• Why Swift for Tensorflow? : https://github.com/tensorflow/swift/blob/master/docs/
WhySwiftForTensorFlow.md
• Swift example : https://github.com/tensorflow/swift/blob/master/docs/site/tutorials/
model_training_walkthrough.ipynb
• https://github.com/bbvch13531/tf.swift