Loading TOC...


   $x as cntk:variable,
   $additional-parameters as map:map,
   [$go-backwards as xs:boolean],
   [$initial-states as cntk:constant*],
   [$return-full-state as xs:boolean],
   [$name as xs:string]
) as cntk:function


Layer factory function to create a LSTM layer.


"shape": xs:unsignedLong*.

"cell-shape": xs:unsignedLong*.

"activation": xs:string. Default: "tanh"

"use-peepholes": xs:boolean. Default: false.

"init": xs:double, or cntk:value, or cntk:initializer. Default: cntk:glorot-uniform-initializer().

"bias-init": xs:double, or cntk:value, or cntk:initializer. Default: 0.

"enable-self-stablization": xs:boolean. Default: false.

"name": xs:string. Default: ""

$initial-states Initial states must be a sequence of length 2.


xquery version "1.0-ml";

let $num-classes := 2
let $num-samples := 5
let $num-sequences := 8
let $input-shape := cntk:shape((64))
let $input-variable := cntk:input-variable($input-shape, "float", fn:false(), fn:false(), "input")
let $lstm-block-option := map:map()=>
                          map:with("shape", (100))
let $lstm-output := cntk:function-outputs(cntk:lstm-layer($input-variable, $lstm-block-option))[1]
let $last-lstm-output := cntk:sequence-last($lstm-output)
let $dense-option := map:map()=>
                     map:with("output-shape", cntk:shape(($num-classes)))
let $dense-output := cntk:dense-layer($last-lstm-output, $dense-option)
let $input-value-array := json:to-array(for $i in (1 to $num-sequences) return json:to-array((1 to cntk:shape-total-size($input-shape)*$num-samples)))
let $input-value := cntk:batch-of-sequences($input-shape, $input-value-array, for $i in (1 to $num-sequences) return fn:true())
let $label-shape := cntk:shape(($num-classes))
let $label-variable := cntk:input-variable($label-shape, "float",fn:false(), fn:false(), "label",(cntk:default-batch-axis()))
let $label-array := json:to-array(for $i in (1 to $num-sequences) return (0,1))
let $label-value := cntk:batch($label-shape, $label-array)
let $learner := cntk:sgd-learner((cntk:function-parameters($dense-output)), cntk:learning-rate-schedule-from-constant(0.1))
let $loss := cntk:cross-entropy-with-softmax($dense-output, $label-variable,cntk:axis(0))
let $trainer := cntk:trainer($dense-output, ($learner), $loss)
let $input-pair := json:to-array(($input-variable, $input-value))
let $label-pair := json:to-array(($label-variable, $label-value))
let $minibatch := json:to-array(($input-pair, $label-pair))
return cntk:train-minibatch($trainer, $minibatch, fn:true())

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.