chainer.functions.embed_id¶
-
chainer.functions.
embed_id
(x, W, ignore_label=None)[source]¶ Efficient linear function for one-hot input.
This function implements so called word embeddings. It takes two arguments: a set of IDs (words)
x
in B dimensional integer vector, and a set of all ID (word) embeddingsW
in V×d float matrix. It outputs B×d matrix whosei
-th column is thex[i]
-th column ofW
.This function is only differentiable on the input
W
.- Parameters
x (
Variable
or N-dimensional array) – Batch vectors of IDs. Each element must be signed integer.W (
Variable
or N-dimensional array) – Distributed representation of each ID (a.k.a. word embeddings).ignore_label (
int
orNone
) – Ifignore_label
is an int value,i
-th column of return value is filled with0
.
- Returns
Output variable.
- Return type
See also
Example
>>> x = np.array([2, 1]).astype(np.int32) >>> x array([2, 1], dtype=int32) >>> W = np.array([[0, 0, 0], ... [1, 1, 1], ... [2, 2, 2]]).astype(np.float32) >>> W array([[0., 0., 0.], [1., 1., 1.], [2., 2., 2.]], dtype=float32) >>> F.embed_id(x, W).array array([[2., 2., 2.], [1., 1., 1.]], dtype=float32) >>> F.embed_id(x, W, ignore_label=1).array array([[2., 2., 2.], [0., 0., 0.]], dtype=float32)