UNPKG

27.9 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2018 Google LLC
4 *
5 * Use of this source code is governed by an MIT-style
6 * license that can be found in the LICENSE file or at
7 * https://opensource.org/licenses/MIT.
8 * =============================================================================
9 */
10/// <amd-module name="@tensorflow/tfjs-layers/dist/layers/recurrent" />
11/**
12 * TensorFlow.js Layers: Recurrent Neural Network Layers.
13 */
14import * as tfc from '@tensorflow/tfjs-core';
15import { serialization, Tensor } from '@tensorflow/tfjs-core';
16import { Activation } from '../activations';
17import { Constraint, ConstraintIdentifier } from '../constraints';
18import { InputSpec, SymbolicTensor } from '../engine/topology';
19import { Layer, LayerArgs } from '../engine/topology';
20import { Initializer, InitializerIdentifier } from '../initializers';
21import { ActivationIdentifier } from '../keras_format/activation_config';
22import { Shape } from '../keras_format/common';
23import { Regularizer, RegularizerIdentifier } from '../regularizers';
24import { Kwargs, RnnStepFunction } from '../types';
25import { LayerVariable } from '../variables';
26/**
27 * Standardize `apply()` args to a single list of tensor inputs.
28 *
29 * When running a model loaded from file, the input tensors `initialState` and
30 * `constants` are passed to `RNN.apply()` as part of `inputs` instead of the
31 * dedicated kwargs fields. `inputs` consists of
32 * `[inputs, initialState0, initialState1, ..., constant0, constant1]` in this
33 * case.
34 * This method makes sure that arguments are
35 * separated and that `initialState` and `constants` are `Array`s of tensors
36 * (or None).
37 *
38 * @param inputs Tensor or `Array` of tensors.
39 * @param initialState Tensor or `Array` of tensors or `null`/`undefined`.
40 * @param constants Tensor or `Array` of tensors or `null`/`undefined`.
41 * @returns An object consisting of
42 * inputs: A tensor.
43 * initialState: `Array` of tensors or `null`.
44 * constants: `Array` of tensors or `null`.
45 * @throws ValueError, if `inputs` is an `Array` but either `initialState` or
46 * `constants` is provided.
47 */
48export declare function standardizeArgs(inputs: Tensor | Tensor[] | SymbolicTensor | SymbolicTensor[], initialState: Tensor | Tensor[] | SymbolicTensor | SymbolicTensor[], constants: Tensor | Tensor[] | SymbolicTensor | SymbolicTensor[], numConstants?: number): {
49 inputs: Tensor | SymbolicTensor;
50 initialState: Tensor[] | SymbolicTensor[];
51 constants: Tensor[] | SymbolicTensor[];
52};
53/**
54 * Iterates over the time dimension of a tensor.
55 *
56 * @param stepFunction RNN step function.
57 * Parameters:
58 * inputs: tensor with shape `[samples, ...]` (no time dimension),
59 * representing input for the batch of samples at a certain time step.
60 * states: an Array of tensors.
61 * Returns:
62 * outputs: tensor with shape `[samples, outputDim]` (no time dimension).
63 * newStates: list of tensors, same length and shapes as `states`. The first
64 * state in the list must be the output tensor at the previous timestep.
65 * @param inputs Tensor of temporal data of shape `[samples, time, ...]` (at
66 * least 3D).
67 * @param initialStates Tensor with shape `[samples, outputDim]` (no time
68 * dimension), containing the initial values of the states used in the step
69 * function.
70 * @param goBackwards If `true`, do the iteration over the time dimension in
71 * reverse order and return the reversed sequence.
72 * @param mask Binary tensor with shape `[sample, time, 1]`, with a zero for
73 * every element that is masked.
74 * @param constants An Array of constant values passed at each step.
75 * @param unroll Whether to unroll the RNN or to use a symbolic loop. *Not*
76 * applicable to this imperative deeplearn.js backend. Its value is ignored.
77 * @param needPerStepOutputs Whether the per-step outputs are to be
78 * concatenated into a single tensor and returned (as the second return
79 * value). Default: `false`. This arg is included so that the relatively
80 * expensive concatenation of the stepwise outputs can be omitted unless
81 * the stepwise outputs need to be kept (e.g., for an LSTM layer of which
82 * `returnSequence` is `true`.)
83 * @returns An Array: `[lastOutput, outputs, newStates]`.
84 * lastOutput: the lastest output of the RNN, of shape `[samples, ...]`.
85 * outputs: tensor with shape `[samples, time, ...]` where each entry
86 * `output[s, t]` is the output of the step function at time `t` for sample
87 * `s`. This return value is provided if and only if the
88 * `needPerStepOutputs` is set as `true`. If it is set as `false`, this
89 * return value will be `undefined`.
90 * newStates: Array of tensors, latest states returned by the step function,
91 * of shape `(samples, ...)`.
92 * @throws ValueError If input dimension is less than 3.
93 *
94 * TODO(nielsene): This needs to be tidy-ed.
95 */
96export declare function rnn(stepFunction: RnnStepFunction, inputs: Tensor, initialStates: Tensor[], goBackwards?: boolean, mask?: Tensor, constants?: Tensor[], unroll?: boolean, needPerStepOutputs?: boolean): [Tensor, Tensor, Tensor[]];
97export declare interface BaseRNNLayerArgs extends LayerArgs {
98 /**
99 * A RNN cell instance. A RNN cell is a class that has:
100 * - a `call()` method, which takes `[Tensor, Tensor]` as the
101 * first input argument. The first item is the input at time t, and
102 * second item is the cell state at time t.
103 * The `call()` method returns `[outputAtT, statesAtTPlus1]`.
104 * The `call()` method of the cell can also take the argument `constants`,
105 * see section "Note on passing external constants" below.
106 * Porting Node: PyKeras overrides the `call()` signature of RNN cells,
107 * which are Layer subtypes, to accept two arguments. tfjs-layers does
108 * not do such overriding. Instead we preseve the `call()` signature,
109 * which due to its `Tensor|Tensor[]` argument and return value, is
110 * flexible enough to handle the inputs and states.
111 * - a `stateSize` attribute. This can be a single integer (single state)
112 * in which case it is the size of the recurrent state (which should be
113 * the same as the size of the cell output). This can also be an Array of
114 * integers (one size per state). In this case, the first entry
115 * (`stateSize[0]`) should be the same as the size of the cell output.
116 * It is also possible for `cell` to be a list of RNN cell instances, in which
117 * case the cells get stacked on after the other in the RNN, implementing an
118 * efficient stacked RNN.
119 */
120 cell?: RNNCell | RNNCell[];
121 /**
122 * Whether to return the last output in the output sequence, or the full
123 * sequence.
124 */
125 returnSequences?: boolean;
126 /**
127 * Whether to return the last state in addition to the output.
128 */
129 returnState?: boolean;
130 /**
131 * If `true`, process the input sequence backwards and return the reversed
132 * sequence (default: `false`).
133 */
134 goBackwards?: boolean;
135 /**
136 * If `true`, the last state for each sample at index i in a batch will be
137 * used as initial state of the sample of index i in the following batch
138 * (default: `false`).
139 *
140 * You can set RNN layers to be "stateful", which means that the states
141 * computed for the samples in one batch will be reused as initial states
142 * for the samples in the next batch. This assumes a one-to-one mapping
143 * between samples in different successive batches.
144 *
145 * To enable "statefulness":
146 * - specify `stateful: true` in the layer constructor.
147 * - specify a fixed batch size for your model, by passing
148 * - if sequential model:
149 * `batchInputShape: [...]` to the first layer in your model.
150 * - else for functional model with 1 or more Input layers:
151 * `batchShape: [...]` to all the first layers in your model.
152 * This is the expected shape of your inputs
153 * *including the batch size*.
154 * It should be a tuple of integers, e.g., `[32, 10, 100]`.
155 * - specify `shuffle: false` when calling `LayersModel.fit()`.
156 *
157 * To reset the state of your model, call `resetStates()` on either the
158 * specific layer or on the entire model.
159 */
160 stateful?: boolean;
161 /**
162 * If `true`, the network will be unrolled, else a symbolic loop will be
163 * used. Unrolling can speed-up a RNN, although it tends to be more memory-
164 * intensive. Unrolling is only suitable for short sequences (default:
165 * `false`).
166 * Porting Note: tfjs-layers has an imperative backend. RNNs are executed with
167 * normal TypeScript control flow. Hence this property is inapplicable and
168 * ignored in tfjs-layers.
169 */
170 unroll?: boolean;
171 /**
172 * Dimensionality of the input (integer).
173 * This option (or alternatively, the option `inputShape`) is required when
174 * this layer is used as the first layer in a model.
175 */
176 inputDim?: number;
177 /**
178 * Length of the input sequences, to be specified when it is constant.
179 * This argument is required if you are going to connect `Flatten` then
180 * `Dense` layers upstream (without it, the shape of the dense outputs cannot
181 * be computed). Note that if the recurrent layer is not the first layer in
182 * your model, you would need to specify the input length at the level of the
183 * first layer (e.g., via the `inputShape` option).
184 */
185 inputLength?: number;
186}
187export declare class RNN extends Layer {
188 /** @nocollapse */
189 static className: string;
190 readonly cell: RNNCell;
191 readonly returnSequences: boolean;
192 readonly returnState: boolean;
193 readonly goBackwards: boolean;
194 readonly unroll: boolean;
195 stateSpec: InputSpec[];
196 protected states_: Tensor[];
197 protected keptStates: Tensor[][];
198 private numConstants;
199 constructor(args: RNNLayerArgs);
200 getStates(): Tensor[];
201 setStates(states: Tensor[]): void;
202 computeOutputShape(inputShape: Shape | Shape[]): Shape | Shape[];
203 computeMask(inputs: Tensor | Tensor[], mask?: Tensor | Tensor[]): Tensor | Tensor[];
204 /**
205 * Get the current state tensors of the RNN.
206 *
207 * If the state hasn't been set, return an array of `null`s of the correct
208 * length.
209 */
210 states: Tensor[];
211 build(inputShape: Shape | Shape[]): void;
212 /**
213 * Reset the state tensors of the RNN.
214 *
215 * If the `states` argument is `undefined` or `null`, will set the
216 * state tensor(s) of the RNN to all-zero tensors of the appropriate
217 * shape(s).
218 *
219 * If `states` is provided, will set the state tensors of the RNN to its
220 * value.
221 *
222 * @param states Optional externally-provided initial states.
223 * @param training Whether this call is done during training. For stateful
224 * RNNs, this affects whether the old states are kept or discarded. In
225 * particular, if `training` is `true`, the old states will be kept so
226 * that subsequent backpropgataion through time (BPTT) may work properly.
227 * Else, the old states will be discarded.
228 */
229 resetStates(states?: Tensor | Tensor[], training?: boolean): void;
230 apply(inputs: Tensor | Tensor[] | SymbolicTensor | SymbolicTensor[], kwargs?: Kwargs): Tensor | Tensor[] | SymbolicTensor | SymbolicTensor[];
231 call(inputs: Tensor | Tensor[], kwargs: Kwargs): Tensor | Tensor[];
232 getInitialState(inputs: Tensor): Tensor[];
233 readonly trainableWeights: LayerVariable[];
234 readonly nonTrainableWeights: LayerVariable[];
235 setFastWeightInitDuringBuild(value: boolean): void;
236 getConfig(): serialization.ConfigDict;
237 /** @nocollapse */
238 static fromConfig<T extends serialization.Serializable>(cls: serialization.SerializableConstructor<T>, config: serialization.ConfigDict, customObjects?: serialization.ConfigDict): T;
239}
240/**
241 * An RNNCell layer.
242 *
243 * @doc {heading: 'Layers', subheading: 'Classes'}
244 */
245export declare abstract class RNNCell extends Layer {
246 /**
247 * Size(s) of the states.
248 * For RNN cells with only a single state, this is a single integer.
249 */
250 abstract stateSize: number | number[];
251 dropoutMask: Tensor | Tensor[];
252 recurrentDropoutMask: Tensor | Tensor[];
253}
254export declare interface SimpleRNNCellLayerArgs extends LayerArgs {
255 /**
256 * units: Positive integer, dimensionality of the output space.
257 */
258 units: number;
259 /**
260 * Activation function to use.
261 * Default: hyperbolic tangent ('tanh').
262 * If you pass `null`, 'linear' activation will be applied.
263 */
264 activation?: ActivationIdentifier;
265 /**
266 * Whether the layer uses a bias vector.
267 */
268 useBias?: boolean;
269 /**
270 * Initializer for the `kernel` weights matrix, used for the linear
271 * transformation of the inputs.
272 */
273 kernelInitializer?: InitializerIdentifier | Initializer;
274 /**
275 * Initializer for the `recurrentKernel` weights matrix, used for
276 * linear transformation of the recurrent state.
277 */
278 recurrentInitializer?: InitializerIdentifier | Initializer;
279 /**
280 * Initializer for the bias vector.
281 */
282 biasInitializer?: InitializerIdentifier | Initializer;
283 /**
284 * Regularizer function applied to the `kernel` weights matrix.
285 */
286 kernelRegularizer?: RegularizerIdentifier | Regularizer;
287 /**
288 * Regularizer function applied to the `recurrent_kernel` weights matrix.
289 */
290 recurrentRegularizer?: RegularizerIdentifier | Regularizer;
291 /**
292 * Regularizer function applied to the bias vector.
293 */
294 biasRegularizer?: RegularizerIdentifier | Regularizer;
295 /**
296 * Constraint function applied to the `kernel` weights matrix.
297 */
298 kernelConstraint?: ConstraintIdentifier | Constraint;
299 /**
300 * Constraint function applied to the `recurrentKernel` weights matrix.
301 */
302 recurrentConstraint?: ConstraintIdentifier | Constraint;
303 /**
304 * Constraintfunction applied to the bias vector.
305 */
306 biasConstraint?: ConstraintIdentifier | Constraint;
307 /**
308 * Float number between 0 and 1. Fraction of the units to drop for the linear
309 * transformation of the inputs.
310 */
311 dropout?: number;
312 /**
313 * Float number between 0 and 1. Fraction of the units to drop for the linear
314 * transformation of the recurrent state.
315 */
316 recurrentDropout?: number;
317 /**
318 * This is added for test DI purpose.
319 */
320 dropoutFunc?: Function;
321}
322export declare class SimpleRNNCell extends RNNCell {
323 /** @nocollapse */
324 static className: string;
325 readonly units: number;
326 readonly activation: Activation;
327 readonly useBias: boolean;
328 readonly kernelInitializer: Initializer;
329 readonly recurrentInitializer: Initializer;
330 readonly biasInitializer: Initializer;
331 readonly kernelConstraint: Constraint;
332 readonly recurrentConstraint: Constraint;
333 readonly biasConstraint: Constraint;
334 readonly kernelRegularizer: Regularizer;
335 readonly recurrentRegularizer: Regularizer;
336 readonly biasRegularizer: Regularizer;
337 readonly dropout: number;
338 readonly recurrentDropout: number;
339 readonly dropoutFunc: Function;
340 readonly stateSize: number;
341 kernel: LayerVariable;
342 recurrentKernel: LayerVariable;
343 bias: LayerVariable;
344 readonly DEFAULT_ACTIVATION = "tanh";
345 readonly DEFAULT_KERNEL_INITIALIZER = "glorotNormal";
346 readonly DEFAULT_RECURRENT_INITIALIZER = "orthogonal";
347 readonly DEFAULT_BIAS_INITIALIZER: InitializerIdentifier;
348 constructor(args: SimpleRNNCellLayerArgs);
349 build(inputShape: Shape | Shape[]): void;
350 call(inputs: Tensor | Tensor[], kwargs: Kwargs): Tensor | Tensor[];
351 getConfig(): serialization.ConfigDict;
352}
353export declare interface SimpleRNNLayerArgs extends BaseRNNLayerArgs {
354 /**
355 * Positive integer, dimensionality of the output space.
356 */
357 units: number;
358 /**
359 * Activation function to use.
360 *
361 * Defaults to hyperbolic tangent (`tanh`)
362 *
363 * If you pass `null`, no activation will be applied.
364 */
365 activation?: ActivationIdentifier;
366 /**
367 * Whether the layer uses a bias vector.
368 */
369 useBias?: boolean;
370 /**
371 * Initializer for the `kernel` weights matrix, used for the linear
372 * transformation of the inputs.
373 */
374 kernelInitializer?: InitializerIdentifier | Initializer;
375 /**
376 * Initializer for the `recurrentKernel` weights matrix, used for
377 * linear transformation of the recurrent state.
378 */
379 recurrentInitializer?: InitializerIdentifier | Initializer;
380 /**
381 * Initializer for the bias vector.
382 */
383 biasInitializer?: InitializerIdentifier | Initializer;
384 /**
385 * Regularizer function applied to the kernel weights matrix.
386 */
387 kernelRegularizer?: RegularizerIdentifier | Regularizer;
388 /**
389 * Regularizer function applied to the recurrentKernel weights matrix.
390 */
391 recurrentRegularizer?: RegularizerIdentifier | Regularizer;
392 /**
393 * Regularizer function applied to the bias vector.
394 */
395 biasRegularizer?: RegularizerIdentifier | Regularizer;
396 /**
397 * Constraint function applied to the kernel weights matrix.
398 */
399 kernelConstraint?: ConstraintIdentifier | Constraint;
400 /**
401 * Constraint function applied to the recurrentKernel weights matrix.
402 */
403 recurrentConstraint?: ConstraintIdentifier | Constraint;
404 /**
405 * Constraint function applied to the bias vector.
406 */
407 biasConstraint?: ConstraintIdentifier | Constraint;
408 /**
409 * Number between 0 and 1. Fraction of the units to drop for the linear
410 * transformation of the inputs.
411 */
412 dropout?: number;
413 /**
414 * Number between 0 and 1. Fraction of the units to drop for the linear
415 * transformation of the recurrent state.
416 */
417 recurrentDropout?: number;
418 /**
419 * This is added for test DI purpose.
420 */
421 dropoutFunc?: Function;
422}
423/**
424 * RNNLayerConfig is identical to BaseRNNLayerConfig, except it makes the
425 * `cell` property required. This interface is to be used with constructors
426 * of concrete RNN layer subtypes.
427 */
428export declare interface RNNLayerArgs extends BaseRNNLayerArgs {
429 cell: RNNCell | RNNCell[];
430}
431export declare class SimpleRNN extends RNN {
432 /** @nocollapse */
433 static className: string;
434 constructor(args: SimpleRNNLayerArgs);
435 call(inputs: Tensor | Tensor[], kwargs: Kwargs): Tensor | Tensor[];
436 /** @nocollapse */
437 static fromConfig<T extends serialization.Serializable>(cls: serialization.SerializableConstructor<T>, config: serialization.ConfigDict): T;
438}
439export declare interface GRUCellLayerArgs extends SimpleRNNCellLayerArgs {
440 /**
441 * Activation function to use for the recurrent step.
442 *
443 * Defaults to hard sigmoid (`hardSigmoid`).
444 *
445 * If `null`, no activation is applied.
446 */
447 recurrentActivation?: ActivationIdentifier;
448 /**
449 * Implementation mode, either 1 or 2.
450 *
451 * Mode 1 will structure its operations as a larger number of
452 * smaller dot products and additions.
453 *
454 * Mode 2 will batch them into fewer, larger operations. These modes will
455 * have different performance profiles on different hardware and
456 * for different applications.
457 *
458 * Note: For superior performance, TensorFlow.js always uses implementation
459 * 2, regardless of the actual value of this configuration field.
460 */
461 implementation?: number;
462 /**
463 * GRU convention (whether to apply reset gate after or before matrix
464 * multiplication). false = "before", true = "after" (only false is
465 * supported).
466 */
467 resetAfter?: boolean;
468}
469export declare class GRUCell extends RNNCell {
470 /** @nocollapse */
471 static className: string;
472 readonly units: number;
473 readonly activation: Activation;
474 readonly recurrentActivation: Activation;
475 readonly useBias: boolean;
476 readonly kernelInitializer: Initializer;
477 readonly recurrentInitializer: Initializer;
478 readonly biasInitializer: Initializer;
479 readonly kernelRegularizer: Regularizer;
480 readonly recurrentRegularizer: Regularizer;
481 readonly biasRegularizer: Regularizer;
482 readonly kernelConstraint: Constraint;
483 readonly recurrentConstraint: Constraint;
484 readonly biasConstraint: Constraint;
485 readonly dropout: number;
486 readonly recurrentDropout: number;
487 readonly dropoutFunc: Function;
488 readonly stateSize: number;
489 readonly implementation: number;
490 readonly DEFAULT_ACTIVATION = "tanh";
491 readonly DEFAULT_RECURRENT_ACTIVATION: ActivationIdentifier;
492 readonly DEFAULT_KERNEL_INITIALIZER = "glorotNormal";
493 readonly DEFAULT_RECURRENT_INITIALIZER = "orthogonal";
494 readonly DEFAULT_BIAS_INITIALIZER: InitializerIdentifier;
495 kernel: LayerVariable;
496 recurrentKernel: LayerVariable;
497 bias: LayerVariable;
498 constructor(args: GRUCellLayerArgs);
499 build(inputShape: Shape | Shape[]): void;
500 call(inputs: Tensor | Tensor[], kwargs: Kwargs): Tensor | Tensor[];
501 getConfig(): serialization.ConfigDict;
502}
503export declare interface GRULayerArgs extends SimpleRNNLayerArgs {
504 /**
505 * Activation function to use for the recurrent step.
506 *
507 * Defaults to hard sigmoid (`hardSigmoid`).
508 *
509 * If `null`, no activation is applied.
510 */
511 recurrentActivation?: ActivationIdentifier;
512 /**
513 * Implementation mode, either 1 or 2.
514 *
515 * Mode 1 will structure its operations as a larger number of
516 * smaller dot products and additions.
517 *
518 * Mode 2 will batch them into fewer, larger operations. These modes will
519 * have different performance profiles on different hardware and
520 * for different applications.
521 *
522 * Note: For superior performance, TensorFlow.js always uses implementation
523 * 2, regardless of the actual value of this configuration field.
524 */
525 implementation?: number;
526}
527export declare class GRU extends RNN {
528 /** @nocollapse */
529 static className: string;
530 constructor(args: GRULayerArgs);
531 call(inputs: Tensor | Tensor[], kwargs: Kwargs): Tensor | Tensor[];
532 /** @nocollapse */
533 static fromConfig<T extends serialization.Serializable>(cls: serialization.SerializableConstructor<T>, config: serialization.ConfigDict): T;
534}
535export declare interface LSTMCellLayerArgs extends SimpleRNNCellLayerArgs {
536 /**
537 * Activation function to use for the recurrent step.
538 *
539 * Defaults to hard sigmoid (`hardSigmoid`).
540 *
541 * If `null`, no activation is applied.
542 */
543 recurrentActivation?: ActivationIdentifier;
544 /**
545 * If `true`, add 1 to the bias of the forget gate at initialization.
546 * Setting it to `true` will also force `biasInitializer = 'zeros'`.
547 * This is recommended in
548 * [Jozefowicz et
549 * al.](http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf).
550 */
551 unitForgetBias?: boolean;
552 /**
553 * Implementation mode, either 1 or 2.
554 *
555 * Mode 1 will structure its operations as a larger number of
556 * smaller dot products and additions.
557 *
558 * Mode 2 will batch them into fewer, larger operations. These modes will
559 * have different performance profiles on different hardware and
560 * for different applications.
561 *
562 * Note: For superior performance, TensorFlow.js always uses implementation
563 * 2, regardless of the actual value of this configuration field.
564 */
565 implementation?: number;
566}
567export declare class LSTMCell extends RNNCell {
568 /** @nocollapse */
569 static className: string;
570 readonly units: number;
571 readonly activation: Activation;
572 readonly recurrentActivation: Activation;
573 readonly useBias: boolean;
574 readonly kernelInitializer: Initializer;
575 readonly recurrentInitializer: Initializer;
576 readonly biasInitializer: Initializer;
577 readonly unitForgetBias: boolean;
578 readonly kernelConstraint: Constraint;
579 readonly recurrentConstraint: Constraint;
580 readonly biasConstraint: Constraint;
581 readonly kernelRegularizer: Regularizer;
582 readonly recurrentRegularizer: Regularizer;
583 readonly biasRegularizer: Regularizer;
584 readonly dropout: number;
585 readonly recurrentDropout: number;
586 readonly dropoutFunc: Function;
587 readonly stateSize: number[];
588 readonly implementation: number;
589 readonly DEFAULT_ACTIVATION = "tanh";
590 readonly DEFAULT_RECURRENT_ACTIVATION = "hardSigmoid";
591 readonly DEFAULT_KERNEL_INITIALIZER = "glorotNormal";
592 readonly DEFAULT_RECURRENT_INITIALIZER = "orthogonal";
593 readonly DEFAULT_BIAS_INITIALIZER = "zeros";
594 kernel: LayerVariable;
595 recurrentKernel: LayerVariable;
596 bias: LayerVariable;
597 constructor(args: LSTMCellLayerArgs);
598 build(inputShape: Shape | Shape[]): void;
599 call(inputs: Tensor | Tensor[], kwargs: Kwargs): Tensor | Tensor[];
600 getConfig(): serialization.ConfigDict;
601}
602export declare interface LSTMLayerArgs extends SimpleRNNLayerArgs {
603 /**
604 * Activation function to use for the recurrent step.
605 *
606 * Defaults to hard sigmoid (`hardSigmoid`).
607 *
608 * If `null`, no activation is applied.
609 */
610 recurrentActivation?: ActivationIdentifier;
611 /**
612 * If `true`, add 1 to the bias of the forget gate at initialization.
613 * Setting it to `true` will also force `biasInitializer = 'zeros'`.
614 * This is recommended in
615 * [Jozefowicz et
616 * al.](http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf).
617 */
618 unitForgetBias?: boolean;
619 /**
620 * Implementation mode, either 1 or 2.
621 * Mode 1 will structure its operations as a larger number of
622 * smaller dot products and additions, whereas mode 2 will
623 * batch them into fewer, larger operations. These modes will
624 * have different performance profiles on different hardware and
625 * for different applications.
626 *
627 * Note: For superior performance, TensorFlow.js always uses implementation
628 * 2, regardless of the actual value of this config field.
629 */
630 implementation?: number;
631}
632export declare class LSTM extends RNN {
633 /** @nocollapse */
634 static className: string;
635 constructor(args: LSTMLayerArgs);
636 call(inputs: Tensor | Tensor[], kwargs: Kwargs): Tensor | Tensor[];
637 /** @nocollapse */
638 static fromConfig<T extends serialization.Serializable>(cls: serialization.SerializableConstructor<T>, config: serialization.ConfigDict): T;
639}
640export declare interface StackedRNNCellsArgs extends LayerArgs {
641 /**
642 * A `Array` of `RNNCell` instances.
643 */
644 cells: RNNCell[];
645}
646export declare class StackedRNNCells extends RNNCell {
647 /** @nocollapse */
648 static className: string;
649 protected cells: RNNCell[];
650 constructor(args: StackedRNNCellsArgs);
651 readonly stateSize: number[];
652 call(inputs: Tensor | Tensor[], kwargs: Kwargs): Tensor | Tensor[];
653 build(inputShape: Shape | Shape[]): void;
654 getConfig(): serialization.ConfigDict;
655 /** @nocollapse */
656 static fromConfig<T extends serialization.Serializable>(cls: serialization.SerializableConstructor<T>, config: serialization.ConfigDict, customObjects?: serialization.ConfigDict): T;
657 readonly trainableWeights: LayerVariable[];
658 readonly nonTrainableWeights: LayerVariable[];
659 /**
660 * Retrieve the weights of a the model.
661 *
662 * @returns A flat `Array` of `tf.Tensor`s.
663 */
664 getWeights(): Tensor[];
665 /**
666 * Set the weights of the model.
667 *
668 * @param weights An `Array` of `tf.Tensor`s with shapes and types matching
669 * the output of `getWeights()`.
670 */
671 setWeights(weights: Tensor[]): void;
672}
673export declare function generateDropoutMask(args: {
674 ones: () => tfc.Tensor;
675 rate: number;
676 training?: boolean;
677 count?: number;
678 dropoutFunc?: Function;
679}): tfc.Tensor | tfc.Tensor[];