We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[BUG] Wrong initialization of the Linear link weights when called with n_batch_axes>1
# **Overview**
When creating the _Linear_ link without specifying the __input_size__ in the constructor and then calling the link with the parameter __n_batch_axes__ > 1, the weight matrix is initialized with a wrong shape and causes an error.

# **Conditions**
Platform: Windows-7-6.1.7601-SP1
Chainer: 5.4.0
NumPy: 1.15.4
CuPy: Not Available
iDeep: Not Available

# Code to reproduce
```
import numpy as np
import chainer
batch_size, seq_len, num_of_features, out_features = (1, 4, 3, 8)
linear_layer_chainer = chainer.links.Linear(out_features)
data = chainer.Variable(np.ones((batch_size, seq_len, num_of_features), dtype=np.float32))
results = linear_layer_chainer (data, n_batch_axes=2)
```


# **Error messages, stack traces, or logs**
```
Traceback (most recent call last):
  File "C:\Users\ntt\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3267, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-9-9df2914c2f5a>", line 1, in <module>
    results = linear_layer_chainer_2_axes(data, n_batch_axes=2)
  File "C:\Users\ntt\Anaconda3\lib\site-packages\chainer\link.py", line 242, in __call__
    out = forward(*args, **kwargs)
  File "C:\Users\ntt\Anaconda3\lib\site-packages\chainer\links\connection\linear.py", line 138, in forward
    return linear.linear(x, self.W, self.b, n_batch_axes=n_batch_axes)
  File "C:\Users\ntt\Anaconda3\lib\site-packages\chainer\functions\connection\linear.py", line 288, in linear
    y, = LinearFunction().apply(args)
  File "C:\Users\ntt\Anaconda3\lib\site-packages\chainer\function_node.py", line 245, in apply
    self._check_data_type_forward(in_data)
  File "C:\Users\ntt\Anaconda3\lib\site-packages\chainer\function_node.py", line 330, in _check_data_type_forward
    self.check_type_forward(in_type)
  File "C:\Users\ntt\Anaconda3\lib\site-packages\chainer\functions\connection\linear.py", line 27, in check_type_forward
    x_type.shape[1] == w_type.shape[1],
  File "C:\Users\ntt\Anaconda3\lib\site-packages\chainer\utils\type_check.py", line 546, in expect
    expr.expect()
  File "C:\Users\ntt\Anaconda3\lib\site-packages\chainer\utils\type_check.py", line 483, in expect
    '{0} {1} {2}'.format(left, self.inv, right))
chainer.utils.type_check.InvalidType: 
Invalid operation is performed in: LinearFunction (Forward)
Expect: x.shape[1] == W.shape[1]
Actual: 3 != 12
```

# Others 
If you create the _Linear_ layer link with __in_size__ passed explicitly to the correct shape, it works:

```
working_linear = chainer.links.Linear(num_of_features, out_features)
working_results = working_linear(data,  n_batch_axes=2)
working_results.shape
```
Output : `(1, 4, 8)`

# Solution 
I believe the culprit lays in the _Linear_ link _forward_ method:
```
    def forward(self, x, n_batch_axes=1):
        """Applies the linear layer.

        Args:
            x (~chainer.Variable): Batch of input vectors.
            n_batch_axes (int): The number of batch axes. The default is 1. The
                input variable is reshaped into
                (:math:`{\\rm n\\_batch\\_axes} + 1`)-dimensional tensor.
                This should be greater than 0.

        Returns:
            ~chainer.Variable: Output of the linear layer.

        """
        if self.W.array is None:
            in_size = functools.reduce(operator.mul, x.shape[1:], 1)
            self._initialize_params(in_size)
        return linear.linear(x, self.W, self.b, n_batch_axes=n_batch_axes)
```
If I interpret this part correctly, it does not take into account the _n_batch_axes_ parameter when initializing the weight matrix.



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `chainer/links/connection/linear.py`
Content:
```
1 import typing as tp  # NOQA
2 
3 from chainer.functions.connection import linear
4 from chainer import initializers
5 from chainer import link
6 from chainer import types  # NOQA
7 from chainer import utils
8 from chainer import variable
9 
10 
11 class Linear(link.Link):
12 
13     """Linear layer (a.k.a.\\  fully-connected layer).
14 
15     This is a link that wraps the :func:`~chainer.functions.linear` function,
16     and holds a weight matrix ``W`` and optionally a bias vector ``b`` as
17     parameters.
18 
19     If ``initialW`` is left to the default value of ``None``, the weight matrix
20     ``W`` is initialized with i.i.d. Gaussian samples, each of which has zero
21     mean and deviation :math:`\\sqrt{1/\\text{in_size}}`. The bias vector ``b``
22     is of size ``out_size``. If the ``initial_bias`` is to left the default
23     value of ``None``, each element is initialized as zero.  If the ``nobias``
24     argument is set to ``True``, then this link does not hold a bias vector.
25 
26     Args:
27         in_size (int or None): Dimension of input vectors. If unspecified or
28             ``None``, parameter initialization will be deferred until the
29             first forward data pass at which time the size will be determined.
30         out_size (int): Dimension of output vectors. If only one value is
31             passed for ``in_size`` and ``out_size``, that value will be used
32             for the ``out_size`` dimension.
33         nobias (bool): If ``True``, then this function does not use the bias.
34         initialW (:ref:`initializer <initializer>`): Initializer to initialize
35             the weight. When it is :class:`numpy.ndarray`,
36             its ``ndim`` should be 2. If ``initialW`` is ``None``, then the
37             weights are initialized with i.i.d. Gaussian samples, each of which
38             has zero mean and deviation :math:`\\sqrt{1/\\text{in_size}}`.
39         initial_bias (:ref:`initializer <initializer>`): Initializer to
40             initialize the bias. If ``None``, the bias will be initialized to
41             zero. When it is :class:`numpy.ndarray`, its ``ndim`` should be 1.
42     .. seealso:: :func:`~chainer.functions.linear`
43 
44     Attributes:
45         W (~chainer.Variable): Weight parameter.
46         b (~chainer.Variable): Bias parameter.
47 
48     .. admonition:: Example
49 
50         There are several ways to make a Linear link.
51 
52         Define an input vector ``x`` as:
53 
54         >>> x = np.array([[0, 1, 2, 3, 4]], np.float32)
55 
56         1. Give the first two arguments explicitly:
57 
58             Those numbers are considered as the input size and the output size.
59 
60             >>> l = L.Linear(5, 10)
61             >>> y = l(x)
62             >>> y.shape
63             (1, 10)
64 
65         2. Omit ``in_size`` (give the output size only as the first argument)
66            or fill it with ``None``:
67 
68             In this case, the size of second axis of ``x`` is used as the
69             input size. So the below two cases are the same.
70 
71             >>> l = L.Linear(10)
72             >>> y = l(x)
73             >>> y.shape
74             (1, 10)
75 
76             >>> l = L.Linear(None, 10)
77             >>> y = l(x)
78             >>> y.shape
79             (1, 10)
80 
81             When you omit the first argument, you need to specify the other
82             subsequent arguments from ``nobias`` as keyword arguments. So the
83             below two cases are the same.
84 
85             >>> l = L.Linear(None, 10, False, None, 0)
86             >>> y = l(x)
87             >>> y.shape
88             (1, 10)
89 
90             >>> l = L.Linear(10, nobias=False, initialW=None, initial_bias=0)
91             >>> y = l(x)
92             >>> y.shape
93             (1, 10)
94 
95     """
96 
97     def __init__(self, in_size, out_size=None, nobias=False,
98                  initialW=None, initial_bias=None):
99         # type: (tp.Optional[int], tp.Optional[int], bool, tp.Optional[types.InitializerSpec], tp.Optional[types.InitializerSpec]) -> None # NOQA
100 
101         super(Linear, self).__init__()
102 
103         if out_size is None:
104             in_size, out_size = None, in_size
105         self.in_size = in_size
106         self.out_size = out_size
107 
108         with self.init_scope():
109             W_initializer = initializers._get_initializer(initialW)
110             self.W = variable.Parameter(W_initializer)  # type: variable.Variable  # NOQA
111             if in_size is not None:
112                 self._initialize_params(in_size)
113 
114             if nobias:
115                 self.b = None  # type: tp.Optional[variable.Variable]
116             else:
117                 if initial_bias is None:
118                     initial_bias = 0
119                 bias_initializer = initializers._get_initializer(initial_bias)
120                 self.b = variable.Parameter(bias_initializer, out_size)
121 
122     def _initialize_params(self, in_size):
123         # type: (int) -> None
124 
125         self.W.initialize((self.out_size, in_size))  # type: ignore
126 
127     @property
128     def printable_specs(self):
129         specs = [
130             ('in_size', self.in_size),
131             ('out_size', self.out_size),
132             ('nobias', self.b is None),
133         ]
134         for spec in specs:
135             yield spec
136 
137     def forward(self, x, n_batch_axes=1):
138         # type: (variable.Variable, int) -> variable.Variable
139         """Applies the linear layer.
140 
141         Args:
142             x (~chainer.Variable): Batch of input vectors.
143             n_batch_axes (int): The number of batch axes. The default is 1. The
144                 input variable is reshaped into
145                 (:math:`{\\rm n\\_batch\\_axes} + 1`)-dimensional tensor.
146                 This should be greater than 0.
147 
148         Returns:
149             ~chainer.Variable: Output of the linear layer.
150 
151         """
152         if self.W.array is None:
153             in_size = utils.size_of_shape(x.shape[1:])
154             self._initialize_params(in_size)
155         return linear.linear(x, self.W, self.b, n_batch_axes=n_batch_axes)
156
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/chainer/links/connection/linear.py b/chainer/links/connection/linear.py
--- a/chainer/links/connection/linear.py
+++ b/chainer/links/connection/linear.py
@@ -150,6 +150,6 @@
 
         """
         if self.W.array is None:
-            in_size = utils.size_of_shape(x.shape[1:])
+            in_size = utils.size_of_shape(x.shape[n_batch_axes:])
             self._initialize_params(in_size)
         return linear.linear(x, self.W, self.b, n_batch_axes=n_batch_axes)

{"golden_diff": "diff --git a/chainer/links/connection/linear.py b/chainer/links/connection/linear.py\n--- a/chainer/links/connection/linear.py\n+++ b/chainer/links/connection/linear.py\n@@ -150,6 +150,6 @@\n \n         \"\"\"\n         if self.W.array is None:\n-            in_size = utils.size_of_shape(x.shape[1:])\n+            in_size = utils.size_of_shape(x.shape[n_batch_axes:])\n             self._initialize_params(in_size)\n         return linear.linear(x, self.W, self.b, n_batch_axes=n_batch_axes)\n", "issue": "[BUG] Wrong initialization of the Linear link weights when called with n_batch_axes>1\n# **Overview**\r\nWhen creating the _Linear_ link without specifying the __input_size__ in the constructor and then calling the link with the parameter __n_batch_axes__ > 1, the weight matrix is initialized with a wrong shape and causes an error.\r\n\r\n# **Conditions**\r\nPlatform: Windows-7-6.1.7601-SP1\r\nChainer: 5.4.0\r\nNumPy: 1.15.4\r\nCuPy: Not Available\r\niDeep: Not Available\r\n\r\n# Code to reproduce\r\n```\r\nimport numpy as np\r\nimport chainer\r\nbatch_size, seq_len, num_of_features, out_features = (1, 4, 3, 8)\r\nlinear_layer_chainer = chainer.links.Linear(out_features)\r\ndata = chainer.Variable(np.ones((batch_size, seq_len, num_of_features), dtype=np.float32))\r\nresults = linear_layer_chainer (data, n_batch_axes=2)\r\n```\r\n\r\n\r\n# **Error messages, stack traces, or logs**\r\n```\r\nTraceback (most recent call last):\r\n  File \"C:\\Users\\ntt\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py\", line 3267, in run_code\r\n    exec(code_obj, self.user_global_ns, self.user_ns)\r\n  File \"<ipython-input-9-9df2914c2f5a>\", line 1, in <module>\r\n    results = linear_layer_chainer_2_axes(data, n_batch_axes=2)\r\n  File \"C:\\Users\\ntt\\Anaconda3\\lib\\site-packages\\chainer\\link.py\", line 242, in __call__\r\n    out = forward(*args, **kwargs)\r\n  File \"C:\\Users\\ntt\\Anaconda3\\lib\\site-packages\\chainer\\links\\connection\\linear.py\", line 138, in forward\r\n    return linear.linear(x, self.W, self.b, n_batch_axes=n_batch_axes)\r\n  File \"C:\\Users\\ntt\\Anaconda3\\lib\\site-packages\\chainer\\functions\\connection\\linear.py\", line 288, in linear\r\n    y, = LinearFunction().apply(args)\r\n  File \"C:\\Users\\ntt\\Anaconda3\\lib\\site-packages\\chainer\\function_node.py\", line 245, in apply\r\n    self._check_data_type_forward(in_data)\r\n  File \"C:\\Users\\ntt\\Anaconda3\\lib\\site-packages\\chainer\\function_node.py\", line 330, in _check_data_type_forward\r\n    self.check_type_forward(in_type)\r\n  File \"C:\\Users\\ntt\\Anaconda3\\lib\\site-packages\\chainer\\functions\\connection\\linear.py\", line 27, in check_type_forward\r\n    x_type.shape[1] == w_type.shape[1],\r\n  File \"C:\\Users\\ntt\\Anaconda3\\lib\\site-packages\\chainer\\utils\\type_check.py\", line 546, in expect\r\n    expr.expect()\r\n  File \"C:\\Users\\ntt\\Anaconda3\\lib\\site-packages\\chainer\\utils\\type_check.py\", line 483, in expect\r\n    '{0} {1} {2}'.format(left, self.inv, right))\r\nchainer.utils.type_check.InvalidType: \r\nInvalid operation is performed in: LinearFunction (Forward)\r\nExpect: x.shape[1] == W.shape[1]\r\nActual: 3 != 12\r\n```\r\n\r\n# Others \r\nIf you create the _Linear_ layer link with __in_size__ passed explicitly to the correct shape, it works:\r\n\r\n```\r\nworking_linear = chainer.links.Linear(num_of_features, out_features)\r\nworking_results = working_linear(data,  n_batch_axes=2)\r\nworking_results.shape\r\n```\r\nOutput : `(1, 4, 8)`\r\n\r\n# Solution \r\nI believe the culprit lays in the _Linear_ link _forward_ method:\r\n```\r\n    def forward(self, x, n_batch_axes=1):\r\n        \"\"\"Applies the linear layer.\r\n\r\n        Args:\r\n            x (~chainer.Variable): Batch of input vectors.\r\n            n_batch_axes (int): The number of batch axes. The default is 1. The\r\n                input variable is reshaped into\r\n                (:math:`{\\\\rm n\\\\_batch\\\\_axes} + 1`)-dimensional tensor.\r\n                This should be greater than 0.\r\n\r\n        Returns:\r\n            ~chainer.Variable: Output of the linear layer.\r\n\r\n        \"\"\"\r\n        if self.W.array is None:\r\n            in_size = functools.reduce(operator.mul, x.shape[1:], 1)\r\n            self._initialize_params(in_size)\r\n        return linear.linear(x, self.W, self.b, n_batch_axes=n_batch_axes)\r\n```\r\nIf I interpret this part correctly, it does not take into account the _n_batch_axes_ parameter when initializing the weight matrix.\r\n\r\n\n", "before_files": [{"content": "import typing as tp  # NOQA\n\nfrom chainer.functions.connection import linear\nfrom chainer import initializers\nfrom chainer import link\nfrom chainer import types  # NOQA\nfrom chainer import utils\nfrom chainer import variable\n\n\nclass Linear(link.Link):\n\n    \"\"\"Linear layer (a.k.a.\\\\  fully-connected layer).\n\n    This is a link that wraps the :func:`~chainer.functions.linear` function,\n    and holds a weight matrix ``W`` and optionally a bias vector ``b`` as\n    parameters.\n\n    If ``initialW`` is left to the default value of ``None``, the weight matrix\n    ``W`` is initialized with i.i.d. Gaussian samples, each of which has zero\n    mean and deviation :math:`\\\\sqrt{1/\\\\text{in_size}}`. The bias vector ``b``\n    is of size ``out_size``. If the ``initial_bias`` is to left the default\n    value of ``None``, each element is initialized as zero.  If the ``nobias``\n    argument is set to ``True``, then this link does not hold a bias vector.\n\n    Args:\n        in_size (int or None): Dimension of input vectors. If unspecified or\n            ``None``, parameter initialization will be deferred until the\n            first forward data pass at which time the size will be determined.\n        out_size (int): Dimension of output vectors. If only one value is\n            passed for ``in_size`` and ``out_size``, that value will be used\n            for the ``out_size`` dimension.\n        nobias (bool): If ``True``, then this function does not use the bias.\n        initialW (:ref:`initializer <initializer>`): Initializer to initialize\n            the weight. When it is :class:`numpy.ndarray`,\n            its ``ndim`` should be 2. If ``initialW`` is ``None``, then the\n            weights are initialized with i.i.d. Gaussian samples, each of which\n            has zero mean and deviation :math:`\\\\sqrt{1/\\\\text{in_size}}`.\n        initial_bias (:ref:`initializer <initializer>`): Initializer to\n            initialize the bias. If ``None``, the bias will be initialized to\n            zero. When it is :class:`numpy.ndarray`, its ``ndim`` should be 1.\n    .. seealso:: :func:`~chainer.functions.linear`\n\n    Attributes:\n        W (~chainer.Variable): Weight parameter.\n        b (~chainer.Variable): Bias parameter.\n\n    .. admonition:: Example\n\n        There are several ways to make a Linear link.\n\n        Define an input vector ``x`` as:\n\n        >>> x = np.array([[0, 1, 2, 3, 4]], np.float32)\n\n        1. Give the first two arguments explicitly:\n\n            Those numbers are considered as the input size and the output size.\n\n            >>> l = L.Linear(5, 10)\n            >>> y = l(x)\n            >>> y.shape\n            (1, 10)\n\n        2. Omit ``in_size`` (give the output size only as the first argument)\n           or fill it with ``None``:\n\n            In this case, the size of second axis of ``x`` is used as the\n            input size. So the below two cases are the same.\n\n            >>> l = L.Linear(10)\n            >>> y = l(x)\n            >>> y.shape\n            (1, 10)\n\n            >>> l = L.Linear(None, 10)\n            >>> y = l(x)\n            >>> y.shape\n            (1, 10)\n\n            When you omit the first argument, you need to specify the other\n            subsequent arguments from ``nobias`` as keyword arguments. So the\n            below two cases are the same.\n\n            >>> l = L.Linear(None, 10, False, None, 0)\n            >>> y = l(x)\n            >>> y.shape\n            (1, 10)\n\n            >>> l = L.Linear(10, nobias=False, initialW=None, initial_bias=0)\n            >>> y = l(x)\n            >>> y.shape\n            (1, 10)\n\n    \"\"\"\n\n    def __init__(self, in_size, out_size=None, nobias=False,\n                 initialW=None, initial_bias=None):\n        # type: (tp.Optional[int], tp.Optional[int], bool, tp.Optional[types.InitializerSpec], tp.Optional[types.InitializerSpec]) -> None # NOQA\n\n        super(Linear, self).__init__()\n\n        if out_size is None:\n            in_size, out_size = None, in_size\n        self.in_size = in_size\n        self.out_size = out_size\n\n        with self.init_scope():\n            W_initializer = initializers._get_initializer(initialW)\n            self.W = variable.Parameter(W_initializer)  # type: variable.Variable  # NOQA\n            if in_size is not None:\n                self._initialize_params(in_size)\n\n            if nobias:\n                self.b = None  # type: tp.Optional[variable.Variable]\n            else:\n                if initial_bias is None:\n                    initial_bias = 0\n                bias_initializer = initializers._get_initializer(initial_bias)\n                self.b = variable.Parameter(bias_initializer, out_size)\n\n    def _initialize_params(self, in_size):\n        # type: (int) -> None\n\n        self.W.initialize((self.out_size, in_size))  # type: ignore\n\n    @property\n    def printable_specs(self):\n        specs = [\n            ('in_size', self.in_size),\n            ('out_size', self.out_size),\n            ('nobias', self.b is None),\n        ]\n        for spec in specs:\n            yield spec\n\n    def forward(self, x, n_batch_axes=1):\n        # type: (variable.Variable, int) -> variable.Variable\n        \"\"\"Applies the linear layer.\n\n        Args:\n            x (~chainer.Variable): Batch of input vectors.\n            n_batch_axes (int): The number of batch axes. The default is 1. The\n                input variable is reshaped into\n                (:math:`{\\\\rm n\\\\_batch\\\\_axes} + 1`)-dimensional tensor.\n                This should be greater than 0.\n\n        Returns:\n            ~chainer.Variable: Output of the linear layer.\n\n        \"\"\"\n        if self.W.array is None:\n            in_size = utils.size_of_shape(x.shape[1:])\n            self._initialize_params(in_size)\n        return linear.linear(x, self.W, self.b, n_batch_axes=n_batch_axes)\n", "path": "chainer/links/connection/linear.py"}], "after_files": [{"content": "import typing as tp  # NOQA\n\nfrom chainer.functions.connection import linear\nfrom chainer import initializers\nfrom chainer import link\nfrom chainer import types  # NOQA\nfrom chainer import utils\nfrom chainer import variable\n\n\nclass Linear(link.Link):\n\n    \"\"\"Linear layer (a.k.a.\\\\  fully-connected layer).\n\n    This is a link that wraps the :func:`~chainer.functions.linear` function,\n    and holds a weight matrix ``W`` and optionally a bias vector ``b`` as\n    parameters.\n\n    If ``initialW`` is left to the default value of ``None``, the weight matrix\n    ``W`` is initialized with i.i.d. Gaussian samples, each of which has zero\n    mean and deviation :math:`\\\\sqrt{1/\\\\text{in_size}}`. The bias vector ``b``\n    is of size ``out_size``. If the ``initial_bias`` is to left the default\n    value of ``None``, each element is initialized as zero.  If the ``nobias``\n    argument is set to ``True``, then this link does not hold a bias vector.\n\n    Args:\n        in_size (int or None): Dimension of input vectors. If unspecified or\n            ``None``, parameter initialization will be deferred until the\n            first forward data pass at which time the size will be determined.\n        out_size (int): Dimension of output vectors. If only one value is\n            passed for ``in_size`` and ``out_size``, that value will be used\n            for the ``out_size`` dimension.\n        nobias (bool): If ``True``, then this function does not use the bias.\n        initialW (:ref:`initializer <initializer>`): Initializer to initialize\n            the weight. When it is :class:`numpy.ndarray`,\n            its ``ndim`` should be 2. If ``initialW`` is ``None``, then the\n            weights are initialized with i.i.d. Gaussian samples, each of which\n            has zero mean and deviation :math:`\\\\sqrt{1/\\\\text{in_size}}`.\n        initial_bias (:ref:`initializer <initializer>`): Initializer to\n            initialize the bias. If ``None``, the bias will be initialized to\n            zero. When it is :class:`numpy.ndarray`, its ``ndim`` should be 1.\n    .. seealso:: :func:`~chainer.functions.linear`\n\n    Attributes:\n        W (~chainer.Variable): Weight parameter.\n        b (~chainer.Variable): Bias parameter.\n\n    .. admonition:: Example\n\n        There are several ways to make a Linear link.\n\n        Define an input vector ``x`` as:\n\n        >>> x = np.array([[0, 1, 2, 3, 4]], np.float32)\n\n        1. Give the first two arguments explicitly:\n\n            Those numbers are considered as the input size and the output size.\n\n            >>> l = L.Linear(5, 10)\n            >>> y = l(x)\n            >>> y.shape\n            (1, 10)\n\n        2. Omit ``in_size`` (give the output size only as the first argument)\n           or fill it with ``None``:\n\n            In this case, the size of second axis of ``x`` is used as the\n            input size. So the below two cases are the same.\n\n            >>> l = L.Linear(10)\n            >>> y = l(x)\n            >>> y.shape\n            (1, 10)\n\n            >>> l = L.Linear(None, 10)\n            >>> y = l(x)\n            >>> y.shape\n            (1, 10)\n\n            When you omit the first argument, you need to specify the other\n            subsequent arguments from ``nobias`` as keyword arguments. So the\n            below two cases are the same.\n\n            >>> l = L.Linear(None, 10, False, None, 0)\n            >>> y = l(x)\n            >>> y.shape\n            (1, 10)\n\n            >>> l = L.Linear(10, nobias=False, initialW=None, initial_bias=0)\n            >>> y = l(x)\n            >>> y.shape\n            (1, 10)\n\n    \"\"\"\n\n    def __init__(self, in_size, out_size=None, nobias=False,\n                 initialW=None, initial_bias=None):\n        # type: (tp.Optional[int], tp.Optional[int], bool, tp.Optional[types.InitializerSpec], tp.Optional[types.InitializerSpec]) -> None # NOQA\n\n        super(Linear, self).__init__()\n\n        if out_size is None:\n            in_size, out_size = None, in_size\n        self.in_size = in_size\n        self.out_size = out_size\n\n        with self.init_scope():\n            W_initializer = initializers._get_initializer(initialW)\n            self.W = variable.Parameter(W_initializer)  # type: variable.Variable  # NOQA\n            if in_size is not None:\n                self._initialize_params(in_size)\n\n            if nobias:\n                self.b = None  # type: tp.Optional[variable.Variable]\n            else:\n                if initial_bias is None:\n                    initial_bias = 0\n                bias_initializer = initializers._get_initializer(initial_bias)\n                self.b = variable.Parameter(bias_initializer, out_size)\n\n    def _initialize_params(self, in_size):\n        # type: (int) -> None\n\n        self.W.initialize((self.out_size, in_size))  # type: ignore\n\n    @property\n    def printable_specs(self):\n        specs = [\n            ('in_size', self.in_size),\n            ('out_size', self.out_size),\n            ('nobias', self.b is None),\n        ]\n        for spec in specs:\n            yield spec\n\n    def forward(self, x, n_batch_axes=1):\n        # type: (variable.Variable, int) -> variable.Variable\n        \"\"\"Applies the linear layer.\n\n        Args:\n            x (~chainer.Variable): Batch of input vectors.\n            n_batch_axes (int): The number of batch axes. The default is 1. The\n                input variable is reshaped into\n                (:math:`{\\\\rm n\\\\_batch\\\\_axes} + 1`)-dimensional tensor.\n                This should be greater than 0.\n\n        Returns:\n            ~chainer.Variable: Output of the linear layer.\n\n        \"\"\"\n        if self.W.array is None:\n            in_size = utils.size_of_shape(x.shape[n_batch_axes:])\n            self._initialize_params(in_size)\n        return linear.linear(x, self.W, self.b, n_batch_axes=n_batch_axes)\n", "path": "chainer/links/connection/linear.py"}]}