This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/groovy-website.git


The following commit(s) were added to refs/heads/asf-site by this push:
     new 31d42af  draft blog post (cont'd)
31d42af is described below

commit 31d42afa759f4d25abffd1112dec5648dba5e287
Author: Paul King <[email protected]>
AuthorDate: Fri Feb 28 00:08:45 2025 +1000

    draft blog post (cont'd)
---
 site/src/site/blog/wayang-tensorflow.adoc | 40 +++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 7 deletions(-)

diff --git a/site/src/site/blog/wayang-tensorflow.adoc 
b/site/src/site/blog/wayang-tensorflow.adoc
index f41fe65..c58c077 100644
--- a/site/src/site/blog/wayang-tensorflow.adoc
+++ b/site/src/site/blog/wayang-tensorflow.adoc
@@ -84,7 +84,18 @@ Operator testData = testSource.field0
 Operator testLabel = testSource.field1
 ----
 
-We'll define a model.
+Next up we'll define a model for our deep-learning network.
+Recall that such networks have inputs (the features),
+one or more hidden layers, and outputs (in this case, labels).
+
+image:img/deep_network.png[Iris neural net layers,width=600]
+
+The nodes can be activated by linear or non-linear functions.
+
+image:img/deep_node.png[Neural net node,width=600]
+
+We'll have 4 inputs going to 32 hidden nodes to 3 outputs
+with Sigmoid activation.
 
 [source,groovy]
 ----
@@ -94,6 +105,9 @@ Op l2 = new Linear(32, 3, true).with(s1)
 DLModel model = new DLModel(l2)
 ----
 
+We define an operator, providing some needed options, that will do
+our training.
+
 [source,groovy]
 ----
 Op criterion = new CrossEntropyLoss(3).with(
@@ -104,27 +118,34 @@ Optimizer optimizer = new Adam(0.1f) // optimizer with 
learning rate
 int batchSize = 45
 int epoch = 10
 var option = new DLTrainingOperator.Option(criterion, optimizer, batchSize, 
epoch)
-option.setAccuracyCalculation(new Mean(0).with(new 
Cast(Op.DType.FLOAT32).with(new Eq().with(
-    new ArgMax(1).with(new Input(Input.Type.PREDICTED, Op.DType.FLOAT32)),
-    new Input(Input.Type.LABEL, Op.DType.INT32)
+option.setAccuracyCalculation(new Mean(0).with(
+    new Cast(Op.DType.FLOAT32).with(new Eq().with(
+        new ArgMax(1).with(new Input(Input.Type.PREDICTED, Op.DType.FLOAT32)),
+        new Input(Input.Type.LABEL, Op.DType.INT32)
 ))))
 var trainingOp = new DLTrainingOperator<>(model, option, float[], Integer)
 ----
 
+Now we'll define a few more operators to work out and collect results:
+
 [source,groovy]
 ----
 var predictOp = new PredictOperator<>(float[], float[])
 
-/* map to label */
-var bestFitOp = new MapOperator<>(array -> array.toList().indexed().max{ 
it.value }.key, float[], Integer)
+var bestFitOp = new MapOperator<>(array ->
+    array.indexed().max{ it.value }.key, float[], Integer)
 
-/* sink */
 var predicted = []
 var predictedSink = createCollectingSink(predicted, Integer)
 
 var groundTruth = []
 var groundTruthSink = createCollectingSink(groundTruth, Integer)
+----
 
+With operators defined, let's connect them together:
+
+[source,groovy]
+----
 trainData.connectTo(0, trainingOp, 0)
 trainLabel.connectTo(0, trainingOp, 1)
 trainingOp.connectTo(0, predictOp, 0)
@@ -132,7 +153,12 @@ testData.connectTo(0, predictOp, 1)
 predictOp.connectTo(0, bestFitOp, 0)
 bestFitOp.connectTo(0, predictedSink, 0)
 testLabel.connectTo(0, groundTruthSink, 0)
+----
 
+Let's now define a plan and execute it:
+
+[source,groovy]
+----
 var wayangPlan = new WayangPlan(predictedSink, groundTruthSink)
 
 new WayangContext().with {

Reply via email to