Swift for TensorFlow APIs
Deep learning library for Swift for TensorFlow.
- A latest Swift for TensorFlow toolchain.
A Swift for TensorFlow toolchain is required to use this package. Add the following to your Swift package manifest.
packages: [
.package(url: "https://github.com/tensorflow/swift-apis.git")
]
To get started, simply import TensorFlow
in your Swift code.
import TensorFlow
// Define a model.
struct Classifier: Layer {
var l1, l2: Dense<Float>
func applied(to input: Tensor<Float>) -> Tensor<Float> {
let h1 = sigmoid(l1.applied(to: input))
return sigmoid(l2.applied(to: h1))
}
}
var model = Classifier(...)
let optimizer = SGD<Classifier, Float>(learningRate: 0.02)
for _ in 0..<1000 {
let (loss, 𝛁model) = model.valueWithGradient { model in
let ŷ = model.applied(to: x)
print("Prediction: \(ŷ)")
return (y - ŷ).squared().mean()
}
print("Loss: \(loss)")
optimizer.update(&model.allDifferentiableVariables,
along: 𝛁model)
}
swift build
Please report bugs and feature requests using GitHub issues in this repository.
Discussion about Swift for TensorFlow happens on the [email protected] mailing list.
We welcome contributions: please read the Contributor Guide to get started. It's always a good idea to discuss your plans on the mailing list before making any major submissions.
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
The Swift for TensorFlow community is guided by our Code of Conduct, which we encourage everybody to read before participating.