def __init__(self, config): self.vocab_size = int(config['vocabulary_size']) self.emb_size = int(config['embedding_dim']) self.kernel_size = int(config['num_filters']) self.win_size = int(config['window_size']) self.hidden_size = int(config['hidden_size']) self.left_name, self.seq_len = config['left_slots'][0] #左文本长度 self.right_name, self.seq_len = config['right_slots'][0] #右文本长度 self.task_mode = config['training_mode'] self.emb_layer = layers.EmbeddingLayer(self.vocab_size, self.emb_size) #embedding矩阵 self.cnn_layer = layers.CNNLayer(self.seq_len, self.emb_size, self.win_size, self.kernel_size) #卷积池化层 self.relu_layer = layers.ReluLayer() #激活函数层 self.concat_layer = layers.ConcatLayer() #concat连接层 if self.task_mode == "pointwise": self.n_class = int(config['n_class']) self.fc1_layer = layers.FCLayer( 2 * self.kernel_size, self.hidden_size) #全连接层1 2*self.kernel_size hidden_size self.fc2_layer = layers.FCLayer( self.hidden_size, self.n_class) #全连接层2 hidden_size * n_class elif self.task_mode == "pairwise": self.fc1_layer = layers.FCLayer(self.kernel_size, self.hidden_size) self.cos_layer = layers.CosineLayer() else: logging.error("training mode not supported")
def __init__(self, config): self.vocab_size = int(config['vocabulary_size']) self.emb_size = int(config['embedding_dim']) self.kernel_size = int(config['num_filters']) self.win_size = int(config['window_size']) self.hidden_size = int(config['hidden_size']) self.left_name, self.seq_len = config['left_slots'][0] self.right_name, self.seq_len = config['right_slots'][0] self.emb_layer = layers.EmbeddingLayer(self.vocab_size, self.emb_size) self.cnn_layer = layers.CNNLayer(self.seq_len, self.emb_size, self.win_size, self.kernel_size) self.relu_layer = layers.ReluLayer() self.tanh_layer = layers.TanhLayer() self.concat_layer = layers.ConcatLayer() self.fc1_layer = layers.FCLayer(self.kernel_size, self.hidden_size) self.n_class = int(config['n_class']) self.fc2_layer = layers.FCLayer(2 * self.hidden_size, self.n_class)