Jointly train four tasks. m_xxx stands for feature and label to train the set membership task. p_xxx stands for a pair of set to train intersection and union. f_xxx stands for features to train the follow operation. Args: features: features params: hyper-parameters
(self, features,
params)
| 293 | return loss, {'logits': logits, 'labels': labels} |
| 294 | |
| 295 | def model_mixture(self, features, |
| 296 | params): |
| 297 | """Jointly train four tasks. |
| 298 | |
| 299 | m_xxx stands for feature and label to train the set membership task. |
| 300 | p_xxx stands for a pair of set to train intersection and union. |
| 301 | f_xxx stands for features to train the follow operation. |
| 302 | |
| 303 | Args: |
| 304 | features: features |
| 305 | params: hyper-parameters |
| 306 | |
| 307 | Returns: |
| 308 | predictions and losses |
| 309 | """ |
| 310 | m_padded_ent_ids, m_labels, \ |
| 311 | p_candidate_set1, p_candidate_set2, p_union_labels, p_intersection_labels, \ |
| 312 | f_subject_set, f_relation_set, f_labels = features |
| 313 | |
| 314 | # Run model on the task of set membership. |
| 315 | m_features = (m_padded_ent_ids, m_labels) |
| 316 | m_loss, m_tensors = self.model_membership(m_features, params) |
| 317 | |
| 318 | # Run model on the task of intersection and union. |
| 319 | p_features = (p_candidate_set1, p_candidate_set2, p_intersection_labels) |
| 320 | p_intersection_loss, p_tensors = self.model_intersection( |
| 321 | p_features, params) |
| 322 | p_union_loss = self.compute_tf_loss( |
| 323 | p_tensors['logits'], p_union_labels) |
| 324 | |
| 325 | # Run model on the task of set follow. |
| 326 | f_features = (f_subject_set, f_relation_set, f_labels) |
| 327 | f_loss, f_tensors = self.model_follow(f_features, params) |
| 328 | |
| 329 | loss = m_loss + p_intersection_loss + p_union_loss + f_loss |
| 330 | tensors = dict() |
| 331 | tensors['membership_logits'] = m_tensors['logits'] |
| 332 | tensors['membership_labels'] = m_labels |
| 333 | tensors['intersection_logits'] = p_tensors['logits'] |
| 334 | tensors['intersection_labels'] = p_intersection_labels |
| 335 | tensors['union_logits'] = p_tensors['logits'] |
| 336 | tensors['union_labels'] = p_union_labels |
| 337 | tensors['set_follows_logits'] = f_tensors['logits'] |
| 338 | tensors['set_follows_labels'] = f_labels |
| 339 | return loss, tensors |
| 340 | |
| 341 | def model_metaqa(self, features, params, |
| 342 | hop, top_k): |
no test coverage detected