MCPcopy Create free account
hub / github.com/alibaba/bigcomputing / __init__

Method __init__

DIEN/utils.py:29–73  ·  view source on GitHub ↗
(self,
               args,
               output_size,
               build_bias,
               bias_initializer=None,
               kernel_initializer=None)

Source from the content-addressed store, hash-verified

27
28
29 def __init__(self,
30 args,
31 output_size,
32 build_bias,
33 bias_initializer=None,
34 kernel_initializer=None):
35 self._build_bias = build_bias
36
37 if args is None or (nest.is_sequence(args) and not args):
38 raise ValueError("`args` must be specified")
39 if not nest.is_sequence(args):
40 args = [args]
41 self._is_sequence = False
42 else:
43 self._is_sequence = True
44
45 # Calculate the total size of arguments on dimension 1.
46 total_arg_size = 0
47 shapes = [a.get_shape() for a in args]
48 for shape in shapes:
49 if shape.ndims != 2:
50 raise ValueError("linear is expecting 2D arguments: %s" % shapes)
51 if shape[1].value is None:
52 raise ValueError("linear expects shape[1] to be provided for shape %s, "
53 "but saw %s" % (shape, shape[1]))
54 else:
55 total_arg_size += shape[1].value
56
57 dtype = [a.dtype for a in args][0]
58
59 scope = vs.get_variable_scope()
60 with vs.variable_scope(scope) as outer_scope:
61 self._weights = vs.get_variable(
62 _WEIGHTS_VARIABLE_NAME, [total_arg_size, output_size],
63 dtype=dtype,
64 initializer=kernel_initializer)
65 if build_bias:
66 with vs.variable_scope(outer_scope) as inner_scope:
67 inner_scope.set_partitioner(None)
68 if bias_initializer is None:
69 bias_initializer = init_ops.constant_initializer(0.0, dtype=dtype)
70 self._biases = vs.get_variable(
71 _BIAS_VARIABLE_NAME, [output_size],
72 dtype=dtype,
73 initializer=bias_initializer)
74
75 def __call__(self, args):
76 if not self._is_sequence:

Callers 1

__init__Method · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected