MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / build

Method build

tensorflow/python/ops/rnn_cell_impl.py:944–985  ·  view source on GitHub ↗
(self, inputs_shape)

Source from the content-addressed store, hash-verified

942
943 @tf_utils.shape_type_conversion
944 def build(self, inputs_shape):
945 if inputs_shape[-1] is None:
946 raise ValueError("Expected inputs.shape[-1] to be known, saw shape: %s" %
947 str(inputs_shape))
948 _check_supported_dtypes(self.dtype)
949 input_depth = inputs_shape[-1]
950 h_depth = self._num_units if self._num_proj is None else self._num_proj
951 maybe_partitioner = (
952 partitioned_variables.fixed_size_partitioner(self._num_unit_shards)
953 if self._num_unit_shards is not None else None)
954 self._kernel = self.add_variable(
955 _WEIGHTS_VARIABLE_NAME,
956 shape=[input_depth + h_depth, 4 * self._num_units],
957 initializer=self._initializer,
958 partitioner=maybe_partitioner)
959 if self.dtype is None:
960 initializer = init_ops.zeros_initializer
961 else:
962 initializer = init_ops.zeros_initializer(dtype=self.dtype)
963 self._bias = self.add_variable(
964 _BIAS_VARIABLE_NAME,
965 shape=[4 * self._num_units],
966 initializer=initializer)
967 if self._use_peepholes:
968 self._w_f_diag = self.add_variable(
969 "w_f_diag", shape=[self._num_units], initializer=self._initializer)
970 self._w_i_diag = self.add_variable(
971 "w_i_diag", shape=[self._num_units], initializer=self._initializer)
972 self._w_o_diag = self.add_variable(
973 "w_o_diag", shape=[self._num_units], initializer=self._initializer)
974
975 if self._num_proj is not None:
976 maybe_proj_partitioner = (
977 partitioned_variables.fixed_size_partitioner(self._num_proj_shards)
978 if self._num_proj_shards is not None else None)
979 self._proj_kernel = self.add_variable(
980 "projection/%s" % _WEIGHTS_VARIABLE_NAME,
981 shape=[self._num_units, self._num_proj],
982 initializer=self._initializer,
983 partitioner=maybe_proj_partitioner)
984
985 self.built = True
986
987 def call(self, inputs, state):
988 """Run one step of LSTM.

Callers

nothing calls this directly

Calls 2

_check_supported_dtypesFunction · 0.85
add_variableMethod · 0.45

Tested by

no test coverage detected