def __init__(self, nlp, shape, **settings): Chain.__init__(self, embed=_Embed(shape['nr_vector'], shape['nr_dim'], shape['nr_hidden'], initialW=lambda arr: set_vectors(arr, nlp.vocab)), encode=_Encode(shape['nr_hidden'], shape['nr_hidden']), attend=_Attend(shape['nr_hidden'], shape['nr_hidden']), predict=_Predict(shape['nr_hidden'], shape['nr_class'])) self.to_gpu(0)
def __init__(self, owner, kind_name, link, input=None): if input == owner: input = None if input is not None and not isinstance(input, Node): raise TypeError("Invalid argument. 'input' must be Node.") if not isinstance(link, Link): raise TypeError('Cannot register a non-link object as a child') Chain.__init__(self) Node.__init__(self, owner, kind_name) self.allow_multi_inputs = False self.output_same_value = True if input is not None: input.add_ouput(self) self.add_input(input) with self.init_scope(): self.link = link
def __init__(self, model, owner=None, kind_name='root', input=None): if input == owner: input = None if input is not None and not isinstance(input, Node): raise TypeError("Invalid argument. 'input' must be Node.") Chain.__init__(self) Node.__init__(self, owner, kind_name) self.allow_multi_inputs = False self.output_same_value = True if input is not None: input.add_ouput(self) self.add_input(input) self.model = model # この Module が属する Model self.nodes = [] # 子ノード列 self.kindwise_count = {} # 種類毎の子ノード数 self.firsts = None # 最初のノード列 self.lasts = None # 最後のノード列 self.assembly_depth = 0 # これが 0 以外ならノード生成時に子ノードとして登録される、0 なら self.owner の子ノードとして登録される
def __init__(self): # super(MyChain, self).__init__() # 多继承的时候,这种比较方便,一次性调用所有父类的构造器 Chain.__init__(self) # 在子类中调用父类的方法,需要加上基类名作为前缀,且还需传入self with self.init_scope(): self.l1 = L.Linear(4, 3) self.l2 = L.Linear(3, 2)
def __init__(self, nr_vector, nr_dim, nr_out): Chain.__init__(self, embed=L.EmbedID(nr_vector, nr_dim), project=L.Linear(None, nr_out, nobias=True))
def __init__(self, nr_in, nr_out): Chain.__init__(self, l1=L.Linear(nr_in, nr_in), l2=L.Linear(nr_in, nr_out))
def __init__(self, nr_in, nr_out): Chain.__init__(self)
def __init__(self, nr_in, nr_out): Chain.__init__(self, fwd=L.LSTM(nr_in, nr_out), bwd=L.LSTM(nr_in, nr_out), mix=L.Bilinear(nr_out, nr_out, nr_out))
def __init__(self, nr_vector, nr_dim, nr_out, set_vectors=None): Chain.__init__(self, embed=L.EmbedID(nr_vector, nr_dim, initialW=set_vectors), project=L.Linear(None, nr_out, nobias=True)) self.embed.W.volatile = False