Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Commit 8e325a5

Browse files
authored
Add documentation to Sequential (#653)
1 parent 7e2212e commit 8e325a5

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

Sources/TensorFlow/Layers/Sequential.swift

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,37 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
/// A layer that sequentially composes two other layers.
15+
/// A layer that sequentially composes two or more other layers.
16+
///
17+
/// ### Examples: ###
18+
///
19+
/// - Build a simple 2-layer perceptron model for MNIST:
20+
///
21+
/// ````
22+
/// let inputSize = 28 * 28
23+
/// let hiddenSize = 300
24+
/// var classifier = Sequential {
25+
/// Dense<Float>(inputSize: inputSize, outputSize: hiddenSize, activation: relu)
26+
/// Dense<Float>(inputSize: hiddenSize, outputSize: 3, activation: identity)
27+
/// }
28+
/// ````
29+
///
30+
/// - Build an autoencoder for MNIST:
31+
///
32+
/// ````
33+
/// var autoencoder = Sequential {
34+
/// // The encoder.
35+
/// Dense<Float>(inputSize: 28 * 28, outputSize: 128, activation: relu)
36+
/// Dense<Float>(inputSize: 128, outputSize: 64, activation: relu)
37+
/// Dense<Float>(inputSize: 64, outputSize: 12, activation: relu)
38+
/// Dense<Float>(inputSize: 12, outputSize: 3, activation: relu)
39+
/// // The decoder.
40+
/// Dense<Float>(inputSize: 3, outputSize: 12, activation: relu)
41+
/// Dense<Float>(inputSize: 12, outputSize: 64, activation: relu)
42+
/// Dense<Float>(inputSize: 64, outputSize: 128, activation: relu)
43+
/// Dense<Float>(inputSize: 128, outputSize: imageHeight * imageWidth, activation: tanh)
44+
/// }
45+
/// ````
1646
public struct Sequential<Layer1: Module, Layer2: Layer>: Module
1747
where Layer1.Output == Layer2.Input,
1848
Layer1.TangentVector.VectorSpaceScalar == Layer2.TangentVector.VectorSpaceScalar {

Sources/TensorFlow/Layers/Sequential.swift.gyb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,37 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
/// A layer that sequentially composes two other layers.
15+
/// A layer that sequentially composes two or more other layers.
16+
///
17+
/// ### Examples: ###
18+
///
19+
/// - Build a simple 2-layer perceptron model for MNIST:
20+
///
21+
/// ````
22+
/// let inputSize = 28 * 28
23+
/// let hiddenSize = 300
24+
/// var classifier = Sequential {
25+
/// Dense<Float>(inputSize: inputSize, outputSize: hiddenSize, activation: relu)
26+
/// Dense<Float>(inputSize: hiddenSize, outputSize: 3, activation: identity)
27+
/// }
28+
/// ````
29+
///
30+
/// - Build an autoencoder for MNIST:
31+
///
32+
/// ````
33+
/// var autoencoder = Sequential {
34+
/// // The encoder.
35+
/// Dense<Float>(inputSize: 28 * 28, outputSize: 128, activation: relu)
36+
/// Dense<Float>(inputSize: 128, outputSize: 64, activation: relu)
37+
/// Dense<Float>(inputSize: 64, outputSize: 12, activation: relu)
38+
/// Dense<Float>(inputSize: 12, outputSize: 3, activation: relu)
39+
/// // The decoder.
40+
/// Dense<Float>(inputSize: 3, outputSize: 12, activation: relu)
41+
/// Dense<Float>(inputSize: 12, outputSize: 64, activation: relu)
42+
/// Dense<Float>(inputSize: 64, outputSize: 128, activation: relu)
43+
/// Dense<Float>(inputSize: 128, outputSize: imageHeight * imageWidth, activation: tanh)
44+
/// }
45+
/// ````
1646
public struct Sequential<Layer1: Module, Layer2: Layer>: Module
1747
where Layer1.Output == Layer2.Input,
1848
Layer1.TangentVector.VectorSpaceScalar == Layer2.TangentVector.VectorSpaceScalar {

0 commit comments

Comments
 (0)