import * as tf from '@tensorflow/tfjs' ; import { l2Normalize } from '@tensorflow/tfjs-layers/dist/losses' ; export class CombineNgramsLayer extends tf . layers . Layer { public static className = 'CombineNgramsLayer' ; public className = CombineNgramsLayer . className ; public computeOutputShape ( inputShape ) { return [ inputShape [ 0 ] , inputShape [ 1 ] , inputShape [ inputShape . length - 1 ] ] ; } public call ( inputs , kwargs ) { return tf . tidy ( ( ) => { this . invokeCallHook ( inputs , kwargs ) ; const combined = inputs [ 0 ] . sum ( 2 ) ; const output = l2Normalize ( combined , 2 ) ; combined . dispose ( ) ; return output ; } ) ; } } tf . serialization . SerializationMap . register ( CombineNgramsLayer ) ;