license import { Scalar , Tensor1D , Tensor2D } from '../tensor' ; import { convertToTensor } from '../tensor_util_env' ; import { TensorLike } from '../types' ; import { add } from './add' ; import { concat } from './concat' ; import { matMul } from './mat_mul' ; import { mul } from './mul' ; import { op } from './operation' ; import { sigmoid } from './sigmoid' ; import { slice } from './slice' ; import { tanh } from './tanh' ; param forgetBias param lstmKernel param lstmBias param data param c param h doc function basicLSTMCell_ ( forgetBias , lstmKernel , lstmBias , data , c , h ) { const $forgetBias = convertToTensor ( forgetBias , 'forgetBias' , 'basicLSTMCell' ) ; const $lstmKernel = convertToTensor ( lstmKernel , 'lstmKernel' , 'basicLSTMCell' ) ; const $lstmBias = convertToTensor ( lstmBias , 'lstmBias' , 'basicLSTMCell' ) ; const $data = convertToTensor ( data , 'data' , 'basicLSTMCell' ) ; const $c = convertToTensor ( c , 'c' , 'basicLSTMCell' ) ; const $h = convertToTensor ( h , 'h' , 'basicLSTMCell' ) ; const combined = concat ( [ $data , $h ] , 1 ) ; const weighted = matMul ( combined , $lstmKernel ) ; const res = add ( weighted , $lstmBias ) ; const batchSize = res . shape [ 0 ] ; const sliceCols = res . shape [ 1 ] / 4 ; const sliceSize = [ batchSize , sliceCols ] ; const i = slice ( res , [ 0 , 0 ] , sliceSize ) ; const j = slice ( res , [ 0 , sliceCols ] , sliceSize ) ; const f = slice ( res , [ 0 , sliceCols * 2 ] , sliceSize ) ; const o = slice ( res , [ 0 , sliceCols * 3 ] , sliceSize ) ; const newC = add ( mul ( sigmoid ( i ) , tanh ( j ) ) , mul ( $c , sigmoid ( add ( $forgetBias , f ) ) as Tensor2D ) ) ; const newH = mul ( tanh ( newC ) , sigmoid ( o ) ) ; return [ newC , newH ] ; } export const basicLSTMCell = op ( { basicLSTMCell_ } ) ;