def __init__(self, config): super(Visual, self).__init__() util.autoassign(locals()) self.margin_size = config.get('margin_size', 0.2) # FIXME FIXME ADD gradient clipping! #self.make_updater = lambda: optim.Adam(self.parameters(), lr=config['lr']) self.max_norm = config['max_norm'] self.Encode = Encoder(config['size_vocab'], config['size'], filter_length=config.get('filter_length', 6), filter_size=config.get('filter_size', 1024), stride=config.get('stride', 3), depth=config.get('depth', 1), bidirectional=config.get('bidirectional', False)) self.Attn = attention.SelfAttention(config['size'], size=config.get('size_attn', 512)) self.ImgEncoder = util.make_linear(config['size_target'], config['size'])
def __init__(self, size_in, size, activation=F.tanh): super(SelfAttention, self).__init__() util.autoassign(locals()) self.Regress1 = util.make_linear(self.size_in, self.size) self.Regress2 = util.make_linear(self.size, 1)
def __init__(self, size, size_target): super(ImageEncoder, self).__init__() self.Encoder = util.make_linear(size_target, size)