3
の数と一致しなければなりませんありません。 LSTMのユニット数(num_units
)。私はそれらが完全に無関係であると期待しますが、どういうわけか彼らはそうではありません。はなぜLSTMCellの入力の大きさは単位
誰でも知っていますか?
の数と一致しなければなりませんありません。 LSTMのユニット数(num_units
)。私はそれらが完全に無関係であると期待しますが、どういうわけか彼らはそうではありません。はなぜLSTMCellの入力の大きさは単位
誰でも知っていますか?
セルの単位(すなわち隠れた次元)の数と一致させる必要はありません。
まず:
num_proj:(オプション)、INT、投影 行列の出力の次元。 Noneの場合、投影は行われません。
つまり、num_projは、num_units(非表示の次元)の次元と一致できないセルの出力の次元です。通常、デコード中に必要な出力は、ボキャブラリと同じディメンションです(ここでは隠しディメンションまたは数値ユニットのディメンションではありません)。
if self._num_proj is not None:
with vs.variable_scope("projection") as proj_scope:
if self._num_proj_shards is not None:
proj_scope.set_partitioner(
partitioned_variables.fixed_size_partitioner(
self._num_proj_shards))
m = _linear(m, self._num_proj, bias=False)
先ほど_linear投影/変換によってnum_proj寸法を有するべき出力(m)を転送し、その上に見ることができるように。 num_projがNoneの場合、このデフォルトは隠し次元と同じになります。
def _linear(args, output_size, bias, bias_start=0.0, scope=None):
"""Linear map: sum_i(args[i] * W[i]), where W[i] is a variable.
Args:
args: a 2D Tensor or a list of 2D, batch x n, Tensors.
output_size: int, second dimension of W[i].
bias: boolean, whether to add a bias term or not.
bias_start: starting value to initialize the bias; 0 by default.
scope: VariableScope for the created subgraph; defaults to "Linear".
Returns:
A 2D Tensor with shape [batch x output_size] equal to
sum_i(args[i] * W[i]), where W[i]s are newly created matrices.
Raises:
ValueError: if some of the arguments has unspecified or wrong shape.
"""
if args is None or (isinstance(args, (list, tuple)) and not args):
raise ValueError("`args` must be specified")
if not isinstance(args, (list, tuple)):
args = [args]
# Calculate the total size of arguments on dimension 1.
total_arg_size = 0
shapes = [a.get_shape().as_list() for a in args]
for shape in shapes:
if len(shape) != 2:
raise ValueError("Linear is expecting 2D arguments: %s" % str(shapes))
if not shape[1]:
raise ValueError("Linear expects shape[1] of arguments: %s" % str(shapes))
else:
total_arg_size += shape[1]
# Now the computation.
with tf.variable_scope(scope or "Linear"):
matrix = tf.get_variable("Matrix", [total_arg_size, output_size])
if len(args) == 1:
res = tf.matmul(args[0], matrix)
else:
res = tf.matmul(tf.concat(axis=1, values=args), matrix)
if not bias:
return res
bias_term = tf.get_variable("Bias", [output_size], initializer=tf.constant_initializer(bias_start))
return res + bias_term