コード例 #1
0
    def generate_input(self, device, use_label):
        inputs = {}
        inputs["task_name"] = self.task_name
        inputs["input_ids"] = create_tensor(self.input_features, "input_ids",
                                            torch.long, device)
        inputs["input_mask"] = create_tensor(self.input_features, "input_mask",
                                             torch.long, device)
        inputs["segment_ids"] = create_tensor(self.input_features,
                                              "segment_ids", torch.long,
                                              device)
        inputs["input_head"] = create_tensor(self.input_features, "is_head",
                                             torch.long, device)
        if use_label:
            label_ids = create_tensor(self.input_features, "label_ids",
                                      torch.long, device)
            inputs["label_ids"] = label_ids
        else:
            inputs["label_ids"] = None

        # inputs["extra_args"] = {
        #   "selected_non_final_layers": [10]
        # }
        inputs["extra_args"] = {}

        if self.config.tasks[
                self.task_name]["selected_non_final_layers"] is not None:
            inputs["extra_args"][
                "selected_non_final_layers"] = self.config.tasks[
                    self.task_name]["selected_non_final_layers"]

        return inputs
コード例 #2
0
  def generate_input(self, device, use_label):
    """Generate tensors based on Parallel Feature"""
    # BERT based features
    inputs = {}
    inputs["task_name"] = self.task_name
    inputs["a_input_ids"] = create_tensor(self.input_features, "a_input_ids",
                                          torch.long, device)
    inputs["b_input_ids"] = create_tensor(self.input_features, "b_input_ids",
                                          torch.long, device)
    inputs["a_input_mask"] = create_tensor(self.input_features, "a_input_mask",
                                           torch.long, device)
    inputs["b_input_mask"] = create_tensor(self.input_features, "b_input_mask",
                                           torch.long, device)
    inputs["a_segment_ids"] = create_tensor(self.input_features, "a_segment_ids",
                                            torch.long, device)
    inputs["b_segment_ids"] = create_tensor(self.input_features, "b_segment_ids",
                                            torch.long, device)
    inputs["a_selected_indices"] = create_tensor(self.input_features, "a_selected_indices",
                                            torch.long, device)
    inputs["b_selected_indices"] = create_tensor(self.input_features, "b_selected_indices",
                                            torch.long, device)
    inputs["a_is_head"] = create_tensor(self.input_features, "a_is_head",
                                            torch.long, device)
    inputs["b_is_head"] = create_tensor(self.input_features, "b_is_head",
                                            torch.long, device)

    inputs["extra_args"] = {}
    if self.config.tasks[self.task_name]["selected_non_final_layers"] is not None:
      inputs["extra_args"]["selected_non_final_layers"] = self.config.tasks[self.task_name]["selected_non_final_layers"]


    return inputs
コード例 #3
0
ファイル: pairwise.py プロジェクト: vrmpx/relogic
  def generate_input(self, device, use_label):
    inputs = {}
    inputs["task_name"] = self.task_name
    inputs["input_ids"] = create_tensor(self.input_features, "input_ids",
                                        torch.long, device)
    inputs["input_mask"] = create_tensor(self.input_features, "input_mask",
                                        torch.long, device)
    inputs["segment_ids"] = create_tensor(self.input_features, "segment_ids",
                                          torch.long, device)
    inputs["p_input_ids"] = create_tensor(self.input_features, "p_input_ids",
                                          torch.long, device)
    inputs["p_input_mask"] = create_tensor(self.input_features, "p_input_mask",
                                           torch.long, device)
    inputs["p_segment_ids"] = create_tensor(self.input_features, "p_segment_ids",
                                            torch.long, device)
    inputs["n_input_ids"] = create_tensor(self.input_features, "n_input_ids",
                                          torch.long, device)
    inputs["n_input_mask"] = create_tensor(self.input_features, "n_input_mask",
                                           torch.long, device)
    inputs["n_segment_ids"] = create_tensor(self.input_features, "n_segment_ids",
                                            torch.long, device)
    inputs["is_inference"] = not use_label
    inputs["extra_args"] = {"target": -torch.ones(inputs["input_ids"].size(0)).to(device)}

    return inputs
コード例 #4
0
  def generate_input(self, device, use_label):
    inputs = {}
    inputs["task_name"] = self.task_name
    inputs["input_ids"] = create_tensor(self.input_features, "input_ids",
                                        torch.long, device)
    inputs["input_mask"] = create_tensor(self.input_features, "input_mask",
                                         torch.long, device)
    inputs["segment_ids"] = create_tensor(self.input_features, "segment_ids",
                                          torch.long, device)
    inputs["input_head"] = create_tensor(self.input_features, "is_head",
                                         torch.long, device)
    if use_label:
      label_ids = create_tensor(self.input_features, "label_ids",
                                torch.long, device)
      inputs["label_ids"] = label_ids
    else:
      inputs["label_ids"] = None

    inputs["lang_ids"] = create_tensor(self.input_features, "lang_ids",
                                       torch.long, device)

    inputs["extra_args"] = {}
    if self.config.tasks[self.task_name]["selected_non_final_layers"] is not None:
      inputs["extra_args"]["selected_non_final_layers"] = self.config.tasks[self.task_name]["selected_non_final_layers"]

    # Classical Features
    inputs["_input_token_ids"] = create_tensor(self.input_features, "_input_token_ids",
                                               torch.long, device)
    inputs["_token_length"] = create_tensor(self.input_features, "_token_length",
                                            torch.long, device)

    # if inputs["_input_token_ids"] is not None:
    #   batch_size = inputs["_input_token_ids"].size(0)
    #   sequence_length = inputs["_input_token_ids"].size(1)
    #
    #   _tmp = torch.arange(0, sequence_length).long().expand(batch_size, sequence_length).to(device)
    #   inputs["_input_token_mask"] = _tmp < inputs["_token_length"].unsqueeze(1).expand_as(_tmp).contiguous()
    #   del _tmp
    # else:
    #   inputs["_input_token_mask"] = None
    inputs["_input_token_mask"] = create_tensor(self.input_features, "_input_token_mask",
                                                torch.bool, device)

    if use_label:
      inputs["_label_ids"] = create_tensor(self.input_features, "_label_ids",
                                           torch.long, device)
    else:
      inputs["_label_ids"] = None

    return inputs
コード例 #5
0
ファイル: ecp.py プロジェクト: vrmpx/relogic
 def generate_input(self, device, use_label):
     """Generate tensors based on ECP Features"""
     # BERT based features
     inputs = {}
     inputs["task_name"] = self.task_name
     inputs["input_ids"] = create_tensor(self.input_features, "input_ids",
                                         torch.long, device)
     inputs["input_mask"] = create_tensor(self.input_features, "input_mask",
                                          torch.long, device)
     inputs["segment_ids"] = create_tensor(self.input_features,
                                           "segment_ids", torch.long,
                                           device)
     inputs["label_ids"] = create_tensor(self.input_features, "label_ids",
                                         torch.long, device)
     inputs["clause_candidates"] = create_tensor(self.input_features,
                                                 "clause_candidates",
                                                 torch.long, device)
     inputs["extra_args"] = {}
     return inputs
コード例 #6
0
 def generate_input(self, device, use_label):
   """Generate tensors based on PointwiseFeatures
   """
   # BERT based feature
   inputs = {}
   inputs["task_name"] = self.task_name
   inputs["input_ids"] = create_tensor(self.input_features, "input_ids",
                                       torch.long, device)
   inputs["input_mask"] = create_tensor(self.input_features, "input_mask",
                                        torch.long, device)
   inputs["segment_ids"] = create_tensor(self.input_features, "segment_ids",
                                         torch.long, device)
   inputs["input_head"] = create_tensor(self.input_features, "is_head",
                                         torch.long, device)
   if use_label:
     inputs["label_ids"] = create_tensor(self.input_features, "label_ids",
                                         torch.long, device)
   else:
     inputs["label_ids"] = None
   inputs["extra_args"] = {}
   return inputs
コード例 #7
0
ファイル: doc_pointwise.py プロジェクト: vrmpx/relogic
 def generate_input(self, device, use_label):
     inputs = {}
     inputs["task_name"] = self.task_name
     inputs["input_ids"] = create_tensor(self.input_features, "input_ids",
                                         torch.long, device)
     inputs["input_mask"] = create_tensor(self.input_features, "input_mask",
                                          torch.long, device)
     inputs["segment_ids"] = create_tensor(self.input_features,
                                           "segment_ids", torch.long,
                                           device)
     inputs["input_head"] = create_tensor(self.input_features, "is_head",
                                          torch.long, device)
     if use_label:
         if self.config.regression:
             inputs["label_ids"] = create_tensor(self.input_features,
                                                 "label_ids", torch.float,
                                                 device)
         else:
             inputs["label_ids"] = create_tensor(self.input_features,
                                                 "label_ids", torch.long,
                                                 device)
     else:
         inputs["label_ids"] = None
     inputs["extra_args"] = {}
     return inputs
コード例 #8
0
ファイル: pointwise.py プロジェクト: vrmpx/relogic
    def generate_input(self, device, use_label):
        """Generate tensors based on PointwiseFeatures
    """
        # BERT based feature
        inputs = {}
        inputs["task_name"] = self.task_name
        inputs["input_ids"] = create_tensor(self.input_features, "input_ids",
                                            torch.long, device)
        inputs["input_mask"] = create_tensor(self.input_features, "input_mask",
                                             torch.long, device)
        inputs["segment_ids"] = create_tensor(self.input_features,
                                              "segment_ids", torch.long,
                                              device)
        inputs["input_head"] = create_tensor(self.input_features, "is_head",
                                             torch.long, device)
        inputs["text_a_indices"] = create_tensor(self.input_features,
                                                 "text_a_indices", torch.long,
                                                 device)
        inputs["text_b_indices"] = create_tensor(self.input_features,
                                                 "text_b_indices", torch.long,
                                                 device)
        if use_label:
            if self.config.regression:
                inputs["label_ids"] = create_tensor(self.input_features,
                                                    "label_ids", torch.float,
                                                    device)
            else:
                inputs["label_ids"] = create_tensor(self.input_features,
                                                    "label_ids", torch.long,
                                                    device)
        else:
            inputs["label_ids"] = None

        inputs["extra_args"] = {}
        if self.config.tasks[
                self.task_name]["selected_non_final_layers"] is not None:
            inputs["extra_args"][
                "selected_non_final_layers"] = self.config.tasks[
                    self.task_name]["selected_non_final_layers"]

        return inputs
コード例 #9
0
ファイル: dep.py プロジェクト: vrmpx/relogic
  def generate_input(self, device, use_label):
    inputs = {}
    inputs["task_name"] = self.task_name
    inputs["input_ids"] = create_tensor(self.input_features, "input_ids", torch.long, device)
    inputs["input_mask"] = create_tensor(self.input_features, "input_mask", torch.long, device)
    inputs["segment_ids"] = create_tensor(self.input_features, "segment_ids", torch.long, device)
    inputs["input_head"] = create_tensor(self.input_features, "is_head", torch.long, device)

    if use_label:
      label_ids = create_tensor(self.input_features, "label_ids", torch.long, device)
      inputs["label_ids"] = label_ids
      arcs_ids = create_tensor(self.input_features, "arcs_ids", torch.long, device)
      inputs["arcs_ids"] = arcs_ids
    else:
      inputs["label_ids"] = None
      inputs["arcs_ids"] = None

    inputs["lang_ids"] = create_tensor(self.input_features, "lang_ids",
                                       torch.long, device)
    inputs["extra_args"] = {}
    return inputs
コード例 #10
0
    def generate_input(self, device, use_label):
        """Generate tensors based on Parallel Feature"""
        # BERT based features
        inputs = {}
        inputs["task_name"] = self.task_name
        inputs["a_input_ids"] = create_tensor(self.input_features,
                                              "a_input_ids", torch.long,
                                              device)
        inputs["b_input_ids"] = create_tensor(self.input_features,
                                              "b_input_ids", torch.long,
                                              device)
        inputs["a_input_mask"] = create_tensor(self.input_features,
                                               "a_input_mask", torch.long,
                                               device)
        inputs["b_input_mask"] = create_tensor(self.input_features,
                                               "b_input_mask", torch.long,
                                               device)
        inputs["a_segment_ids"] = create_tensor(self.input_features,
                                                "a_segment_ids", torch.long,
                                                device)
        inputs["b_segment_ids"] = create_tensor(self.input_features,
                                                "b_segment_ids", torch.long,
                                                device)

        if use_label:
            label_ids = create_tensor(self.input_features, "label_ids",
                                      torch.long, device)
            inputs["label_ids"] = label_ids
        else:
            inputs["label_ids"] = None

        inputs["extra_args"] = {}
        if self.config.tasks[
                self.task_name]["selected_non_final_layers"] is not None:
            inputs["extra_args"][
                "selected_non_final_layers"] = self.config.tasks[
                    self.task_name]["selected_non_final_layers"]

        # Classical Features
        inputs["_a_input_token_ids"] = create_tensor(self.input_features,
                                                     "_a_input_token_ids",
                                                     torch.long, device)
        inputs["_b_input_token_ids"] = create_tensor(self.input_features,
                                                     "_b_input_token_ids",
                                                     torch.long, device)
        inputs["_a_token_length"] = create_tensor(self.input_features,
                                                  "_a_token_length",
                                                  torch.long, device)
        inputs["_b_token_length"] = create_tensor(self.input_features,
                                                  "_b_token_length",
                                                  torch.long, device)
        inputs["_a_input_token_mask"] = create_tensor(self.input_features,
                                                      "_a_input_token_mask",
                                                      torch.long, device)
        inputs["_b_input_token_mask"] = create_tensor(self.input_features,
                                                      "_b_input_token_mask",
                                                      torch.long, device)

        if use_label:
            _label_ids = create_tensor(self.input_features, "_label_ids",
                                       torch.long, device)
            inputs["_label_ids"] = _label_ids
        else:
            inputs["_label_ids"] = None
        return inputs
コード例 #11
0
    def generate_input(self, device, use_label):
        """Generate tensors based on SRL Features."""
        # BERT based features
        inputs = {}
        inputs["task_name"] = self.task_name
        inputs["input_ids"] = create_tensor(self.input_features, "input_ids",
                                            torch.long, device)
        inputs["input_mask"] = create_tensor(self.input_features, "input_mask",
                                             torch.long, device)
        inputs["segment_ids"] = create_tensor(self.input_features,
                                              "segment_ids", torch.long,
                                              device)
        inputs["input_head"] = create_tensor(self.input_features, "is_head",
                                             torch.long, device)
        if use_label:
            label_ids = create_tensor(self.input_features, "label_ids",
                                      torch.long, device)
            predicate_candidate_label_ids = create_tensor(
                self.input_features, "predicate_candidate_label_ids",
                torch.long, device)
            arg_candidate_label_ids = create_tensor(self.input_features,
                                                    "arg_candidate_label_ids",
                                                    torch.long, device)
            pos_tag_label_ids = create_tensor(self.input_features,
                                              "pos_tag_label_ids", torch.long,
                                              device)
            if predicate_candidate_label_ids is None or arg_candidate_label_ids is None:
                inputs["label_ids"] = label_ids
            else:
                inputs["label_ids"] = (label_ids,
                                       predicate_candidate_label_ids,
                                       arg_candidate_label_ids,
                                       pos_tag_label_ids)
        else:
            inputs["label_ids"] = None
        inputs["arg_candidates"] = create_tensor(self.input_features,
                                                 "arg_candidates", torch.long,
                                                 device)
        inputs["predicate_candidates"] = create_tensor(self.input_features,
                                                       "predicate_candidates",
                                                       torch.long, device)

        # Label Embeddings
        inputs["label_candidates"] = create_tensor(self.input_features,
                                                   "label_candidates",
                                                   torch.long, device)
        inputs["label_candidates_mask"] = create_tensor(
            self.input_features, "label_candidates_mask", torch.long, device)
        # Classical features
        # inputs["_input_token_ids"] = create_tensor(self.input_features, "_input_token_ids",
        #                                            torch.long, device)
        # inputs["_token_length"] = create_tensor(self.input_features, "_token_length",
        #                                         torch.long, device)
        # if use_label:
        #   _label_ids = create_tensor(self.input_features, "_label_ids",
        #                                       torch.long, device)
        #   _predicate_candidate_label_ids = create_tensor(self.input_features, "_predicate_candidate_label_ids",
        #                                        torch.long, device)
        #   _arg_candidate_label_ids = create_tensor(self.input_features, "_arg_candidate_label_ids",
        #                                        torch.long, device)
        #   if _predicate_candidate_label_ids is None or _arg_candidate_label_ids is None:
        #     inputs["_label_ids"] = _label_ids
        #   else:
        #     inputs["_label_ids"] = (_label_ids, _predicate_candidate_label_ids, _arg_candidate_label_ids)
        # else:
        #   inputs["_label_ids"] = None
        # inputs["_arg_candidates"] = create_tensor(
        #     self.input_features, "_arg_candidates", torch.long, device)
        # inputs["_predicate_candidates"] = create_tensor(
        #   self.input_features, "_predicate_candidates", torch.long, device)
        inputs["extra_args"] = {"selected_non_final_layers": [1, 9, 18]}

        return inputs