From 3717dbfc42c2f823733803b692a27ede2cc96ce5 Mon Sep 17 00:00:00 2001 From: Keisuke Umezawa Date: Sat, 5 Aug 2017 14:56:31 +0900 Subject: [PATCH] add example for links.EmbedID --- chainer/functions/connection/embed_id.py | 4 ++-- chainer/links/connection/embed_id.py | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/chainer/functions/connection/embed_id.py b/chainer/functions/connection/embed_id.py index d2726f6a6188..165e47b87bf6 100644 --- a/chainer/functions/connection/embed_id.py +++ b/chainer/functions/connection/embed_id.py @@ -117,8 +117,8 @@ def embed_id(x, W, ignore_label=None): >>> x array([2, 1], dtype=int32) >>> W = np.array([[0, 0, 0], - [1, 1, 1], - [2, 2, 2]]).astype('f') + ... [1, 1, 1], + ... [2, 2, 2]]).astype('f') >>> W array([[ 0., 0., 0.], [ 1., 1., 1.], diff --git a/chainer/links/connection/embed_id.py b/chainer/links/connection/embed_id.py index fdcd65c7d8f5..13695e95e918 100644 --- a/chainer/links/connection/embed_id.py +++ b/chainer/links/connection/embed_id.py @@ -22,11 +22,29 @@ class EmbedID(link.Link): ignore_label (int or None): If ``ignore_label`` is an int value, ``i``-th column of return value is filled with ``0``. - .. seealso:: :func:`chainer.functions.embed_id` + .. seealso:: :func:`~chainer.functions.embed_id` Attributes: W (~chainer.Variable): Embedding parameter matrix. + .. admonition:: Example + + >>> 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