espnet.nets.chainer_backend.deterministic_embed_id.EmbedID
Less than 1 minute
espnet.nets.chainer_backend.deterministic_embed_id.EmbedID
class espnet.nets.chainer_backend.deterministic_embed_id.EmbedID(in_size, out_size, initialW=None, ignore_label=None)
Bases: Link
Efficient linear layer for one-hot input.
This is a link that wraps the embed_id()
function. This link holds the ID (word) embedding matrix W
as a parameter.
- Parameters:
- in_size (int) – Number of different identifiers (a.k.a. vocabulary size).
- out_size (int) – Output dimension.
- initialW (Initializer) – Initializer to initialize the weight.
- ignore_label (int) – If ignore_label is an int value, i-th column of return value is filled with 0.
embed_id<span class='small-bracket'>()</span>
W
Embedding parameter matrix.
- Type:Variable
Examples
>>> W = np.array([[0, 0, 0],
... [1, 1, 1],
... [2, 2, 2]]).astype('f')
>>> W
array([[ 0., 0., 0.],
[ 1., 1., 1.],
[ 2., 2., 2.]], dtype=float32)
>>> l = L.EmbedID(W.shape[0], W.shape[1], initialW=W)
>>> x = np.array([2, 1]).astype('i')
>>> x
array([2, 1], dtype=int32)
>>> y = l(x)
>>> y.data
array([[ 2., 2., 2.],
[ 1., 1., 1.]], dtype=float32)
ignore_label = None