jiant/models.py
def forward(self, task, batch, predict=False):
        """
        Pass inputs to correct forward pass
        Args:
            - task (tasks.Task): task for which batch is drawn
            - batch (Dict[str:Dict[str:Tensor]]): dictionary of (field, indexing) pairs,
                where indexing is a dict of the index namespace and the actual indices.
            - predict (Bool): passed to task specific forward(). If true, forward()
                should return predictions.
        Returns:
            - out: dictionary containing task outputs and loss if label was in batch
        """
        if self.utilization is not None:
            if "input1" in batch:
                self.utilization(get_batch_utilization(batch["input1"]))
            elif "input" in batch:
                self.utilization(get_batch_utilization(batch["input"]))
        if isinstance(task, SingleClassificationTask): #XXX CoLA is a SingleClassificationTask
            out = self._single_sentence_forward(batch, task, predict)
        elif isinstance(task, GLUEDiagnosticTask):
            out = self._nli_diagnostic_forward(batch, task, predict)
        elif isinstance( #XXX RTE is type PairClassificationTask
            task, (PairClassificationTask, PairRegressionTask, PairOrdinalRegressionTask)
        ):
            out = self._pair_sentence_forward(batch, task, predict)
        elif isinstance(task, LanguageModelingTask):
            if isinstance(self.sent_encoder._phrase_layer, ONLSTMStack) or isinstance(
                self.sent_encoder._phrase_layer, PRPN
            ):
                out = self._lm_only_lr_forward(batch, task)
            else:
                out = self._lm_forward(batch, task, predict)
        elif isinstance(task, TaggingTask):
            out = self._tagger_forward(batch, task, predict)
        elif isinstance(task, MultipleChoiceTask):
            out = self._mc_forward(batch, task, predict)
        elif isinstance(task, EdgeProbingTask):
            # Just get embeddings and invoke task module.
            word_embs_in_context, sent_mask = self.sent_encoder(batch["input1"], task)
            module = getattr(self, "%s_mdl" % task.name)
            out = module.forward(batch, word_embs_in_context, sent_mask, task, predict)
        elif isinstance(task, SequenceGenerationTask):
            out = self._seq_gen_forward(batch, task, predict)
        elif isinstance(task, (MultiRCTask, ReCoRDTask)):
            out = self._multiple_choice_reading_comprehension_forward(batch, task, predict)
        elif isinstance(task, SpanClassificationTask):
            out = self._span_forward(batch, task, predict)
        else:
            raise ValueError("Task-specific components not found!")
        return out

        Pass inputs to correct forward pass
        Args:
            - task (tasks.Task): task for which batch is drawn
            - batch (Dict[str:Dict[str:Tensor]]): dictionary of (field, indexing) pairs,
                where indexing is a dict of the index namespace and the actual indices.
            - predict (Bool): passed to task specific forward(). If true, forward()
                should return predictions.
        Returns:
            - out: dictionary containing task outputs and loss if label was in batch
        
Pass inputs to correct forward pass
Pass inputs to correct forward pass
def forward(self, task, batch, predict=False):
        if self.utilization is not None:
            if "input1" in batch:
                self.utilization(get_batch_utilization(batch["input1"]))
            elif "input" in batch:
                self.utilization(get_batch_utilization(batch["input"]))
        if isinstance(task, SingleClassificationTask): 
            out = self._single_sentence_forward(batch, task, predict)
        elif isinstance(task, GLUEDiagnosticTask):
            out = self._nli_diagnostic_forward(batch, task, predict)
        elif isinstance( 
            task, (PairClassificationTask, PairRegressionTask, PairOrdinalRegressionTask)
        ):
            out = self._pair_sentence_forward(batch, task, predict)
        elif isinstance(task, LanguageModelingTask):
            if isinstance(self.sent_encoder._phrase_layer, ONLSTMStack) or isinstance(
                self.sent_encoder._phrase_layer, PRPN
            ):
                out = self._lm_only_lr_forward(batch, task)
            else:
                out = self._lm_forward(batch, task, predict)
        elif isinstance(task, TaggingTask):
            out = self._tagger_forward(batch, task, predict)
        elif isinstance(task, MultipleChoiceTask):
            out = self._mc_forward(batch, task, predict)
        elif isinstance(task, EdgeProbingTask):
            word_embs_in_context, sent_mask = self.sent_encoder(batch["input1"], task)
            module = getattr(self, "%s_mdl" % task.name)
            out = module.forward(batch, word_embs_in_context, sent_mask, task, predict)
        elif isinstance(task, SequenceGenerationTask):
            out = self._seq_gen_forward(batch, task, predict)
        elif isinstance(task, (MultiRCTask, ReCoRDTask)):
            out = self._multiple_choice_reading_comprehension_forward(batch, task, predict)
        elif isinstance(task, SpanClassificationTask):
            out = self._span_forward(batch, task, predict)
        else:
            raise ValueError("Task-specific components not found!")
        return out
def forward ( self , task , batch , predict = False ) : if self . utilization is not None : if "input1" in batch : self . utilization ( get_batch_utilization ( batch [ "input1" ] ) ) elif "input" in batch : self . utilization ( get_batch_utilization ( batch [ "input" ] ) ) if isinstance ( task , SingleClassificationTask ) : out = self . _single_sentence_forward ( batch , task , predict ) elif isinstance ( task , GLUEDiagnosticTask ) : out = self . _nli_diagnostic_forward ( batch , task , predict ) elif isinstance ( task , ( PairClassificationTask , PairRegressionTask , PairOrdinalRegressionTask ) ) : out = self . _pair_sentence_forward ( batch , task , predict ) elif isinstance ( task , LanguageModelingTask ) : if isinstance ( self . sent_encoder . _phrase_layer , ONLSTMStack ) or isinstance ( self . sent_encoder . _phrase_layer , PRPN ) : out = self . _lm_only_lr_forward ( batch , task ) else : out = self . _lm_forward ( batch , task , predict ) elif isinstance ( task , TaggingTask ) : out = self . _tagger_forward ( batch , task , predict ) elif isinstance ( task , MultipleChoiceTask ) : out = self . _mc_forward ( batch , task , predict ) elif isinstance ( task , EdgeProbingTask ) : word_embs_in_context , sent_mask = self . sent_encoder ( batch [ "input1" ] , task ) module = getattr ( self , "%s_mdl" % task . name ) out = module . forward ( batch , word_embs_in_context , sent_mask , task , predict ) elif isinstance ( task , SequenceGenerationTask ) : out = self . _seq_gen_forward ( batch , task , predict ) elif isinstance ( task , ( MultiRCTask , ReCoRDTask ) ) : out = self . _multiple_choice_reading_comprehension_forward ( batch , task , predict ) elif isinstance ( task , SpanClassificationTask ) : out = self . _span_forward ( batch , task , predict ) else : raise ValueError ( "Task-specific components not found!" ) return out
Pass inputs to correct forward pass
Pass inputs to correct forward pass
"""
        Pass inputs to correct forward pass
        Args:
            - task (tasks.Task): task for which batch is drawn
            - batch (Dict[str:Dict[str:Tensor]]): dictionary of (field, indexing) pairs,
                where indexing is a dict of the index namespace and the actual indices.
            - predict (Bool): passed to task specific forward(). If true, forward()
                should return predictions.
        Returns:
            - out: dictionary containing task outputs and loss if label was in batch
        """ #XXX CoLA is a SingleClassificationTask #XXX RTE is type PairClassificationTask # Just get embeddings and invoke task module.
dictionary containing task outputs and loss if label was in batch
dictionary containing task outputs and loss if label was in batch
self
task
batch
predict
- task
task for which batch is drawn
task for which batch is drawn
- batch (Dict[str
Dict[str:Tensor]]): dictionary of (field, indexing) pairs,
where indexing is a dict of the index namespace and the actual indices.
Dict [ str : Tensor ]] ) : dictionary of ( field indexing ) pairs where indexing is a dict of the index namespace and the actual indices .
- predict
passed to task specific forward(). If true, forward()
should return predictions.
passed to task specific forward () . If true forward () should return predictions .