def __init__(self, n_word_types, n_trig_types, n_role_types, n_entity_types, trigger_type2id, entity_type2id, DIM_EMBED, DIM_EVENT, DIM_BILSTM, DIM_TRIG_TYPE, DIM_ROLE_TYPE, DIM_ARG_TYPE, DIM_IO, DROPOUT, REPLACE_TYPE, GENERALISATION, THRESHOLD): super(Loader, self).__init__() with self.init_scope(): self.DIM_EMBED = DIM_EMBED self.DIM_EVENT = DIM_EVENT self.DIM_BILSTM = DIM_BILSTM self.DIM_TRIG_TYPE = DIM_TRIG_TYPE self.DIM_ROLE_TYPE = DIM_ROLE_TYPE self.DIM_ARG_TYPE = DIM_ARG_TYPE self.DIM_IO = DIM_IO self.DROPOUT = DROPOUT self.THRESHOLD = THRESHOLD self.GENERALISATION = GENERALISATION self.REPLACE_TYPE = REPLACE_TYPE self.DROPOUT = DROPOUT self.DIM_TREE_LSTM_INPUT = self.DIM_TRIG_TYPE + ( self.DIM_BILSTM * 2) + self.DIM_ROLE_TYPE + self.DIM_TRIG_TYPE + ( self.DIM_BILSTM * 2) + self.DIM_IO self.DIM_ARG = self.DIM_TRIG_TYPE + (self.DIM_BILSTM * 2) self.id2triggertype = {v: k for k, v in trigger_type2id.items()} self.id2entitytype = {v: k for k, v in entity_type2id.items()} self.embed = L.EmbedID(n_word_types, self.DIM_EMBED, ignore_label=-1) self.bilstm = L.NStepBiLSTM(1, self.DIM_EMBED, self.DIM_BILSTM, 0) self.embed_trigtype = L.EmbedID(n_trig_types, self.DIM_TRIG_TYPE, ignore_label=-1) self.embed_roletype = L.EmbedID(n_role_types, self.DIM_ROLE_TYPE, ignore_label=-1) self.embed_argtype = L.EmbedID(n_entity_types, self.DIM_ARG_TYPE, ignore_label=-1) self.embed_io = L.EmbedID(2, self.DIM_IO, ignore_label=-1) self.treelstm = L.ChildSumTreeLSTM(self.DIM_TREE_LSTM_INPUT, self.DIM_EVENT) self.l1 = L.Linear(None, self.DIM_EVENT) self.y = L.Linear(None, self.DIM_EVENT) self.final = L.Linear(None, 1) # event or non-event self.reducedEvent = L.Linear(None, self.DIM_ARG) self.len_type_and_arg = self.DIM_TRIG_TYPE + (self.DIM_BILSTM * 2) self.len_relation = self.DIM_TRIG_TYPE + (self.DIM_BILSTM * 2) + self.DIM_ROLE_TYPE + self.DIM_ARG_TYPE + \ (self.DIM_BILSTM * 2) + self.DIM_IO self.trigger_type2id = trigger_type2id self.entity_type2id = entity_type2id
def setUp(self): if self.model_type == 'ChildSumTreeLSTM': self.link = links.ChildSumTreeLSTM(self.in_size, self.out_size) elif self.model_type == 'NaryTreeLSTM': if self.n_ary == 0: # n_ary=0 test should be skipped for NaryTreeLSTM self.n_ary = 1 self.link = links.NaryTreeLSTM(self.in_size, self.out_size, n_ary=self.n_ary) else: NotImplementedError() for p in self.link.params(): p.data[:] = numpy.random.uniform(-1, 1, p.shape).astype(self.dtype) self.c_prevs = [ numpy.random.uniform(-1, 1, (5, self.out_size)).astype(self.dtype) for _ in range(self.n_ary) ] self.h_prevs = [ numpy.random.uniform(-1, 1, (5, self.out_size)).astype(self.dtype) for _ in range(self.n_ary) ] self.x = numpy.random.uniform(-1, 1, (5, self.in_size)).astype(self.dtype) self.inputs = self.c_prevs + self.h_prevs + [self.x] self.gc = numpy.random.uniform(-1, 1, (5, self.out_size)).astype(self.dtype) self.gh = numpy.random.uniform(-1, 1, (5, self.out_size)).astype(self.dtype) self.check_forward_options = {} self.check_backward_options = {'dtype': numpy.float64} if self.dtype == numpy.float16: self.check_forward_options = {'atol': 5e-4, 'rtol': 5e-3} self.check_backward_options = { 'dtype': numpy.float64, 'atol': 5e-4, 'rtol': 5e-3 }