mtp/machamp/dataset_readers/machamp_universal_reader.py
def text_to_instance(self,  # type: ignore
                         sent_tasks: Dict,
                         full_data: List[str],
                         col_idxs: Dict[str, int],
                         is_train: bool,
                         task2type: Dict[str, str],
                         dataset: str
                         ) -> Instance:
        """
        converts the previously read data into an AllenNLP Instance, containing mainly
        a TextField and one or more *LabelField's
        """
        fields: Dict[str, Field] = {}

        tokens = TextField(sent_tasks['tokens'], self.token_indexers)

        for task in sent_tasks:
            if task == 'tokens':
                fields[task] = tokens
                fields['src_words'] = SequenceLabelField([str(x) for x in sent_tasks[task]],
                                                         tokens, label_namespace="src_tokens")

            elif task2type[task] == 'dependency':
                fields[task + '_rels'] = SequenceLabelField([x[0] for x in sent_tasks[task]],
                                                            tokens, label_namespace=task + '_rels')
                fields[task + '_head_indices'] = SequenceLabelField([x[1] for x in sent_tasks[task]],
                                                                    tokens, label_namespace=task + '_head_indices')

            elif task2type[task] == "multiseq":
                label_sequence = []

                # For each token label, check if it is a multilabel and handle it
                for raw_label in sent_tasks[task]:
                    label_list = raw_label.split("$")
                    label_sequence.append(label_list)
                fields[task] = SequenceMultiLabelField(label_sequence, tokens, label_namespace=task)

            elif task2type[task] == 'classification':
                fields[task] = LabelField(sent_tasks[task], label_namespace=task)

            elif task2type[task] == 'seq2seq':
                fields[task + '_target'] = TextField(sent_tasks[task], self._target_token_indexers)
                fields[task + '_target_words'] = SequenceLabelField([str(x) for x in sent_tasks[task]],
                                                                    fields[task + '_target'],
                                                                    label_namespace=task + "_target_words")

            else:  # seq labeling
                fields[task] = SequenceLabelField(sent_tasks[task], tokens, label_namespace=task)

        fields['dataset'] = LabelField(dataset, label_namespace='dataset')

        sent_tasks["full_data"] = full_data
        sent_tasks["col_idxs"] = col_idxs
        sent_tasks['is_train'] = is_train
        fields["metadata"] = MetadataField(sent_tasks)
        return Instance(fields)

        converts the previously read data into an AllenNLP Instance, containing mainly
        a TextField and one or more *LabelField's
        
converts the previously read data into an AllenNLP Instance, containing mainly
a TextField and one or more *LabelField's
converts the previously read data into an AllenNLP Instance containing mainly a TextField and one or more * LabelField ' s
def text_to_instance(self,  
                         sent_tasks: Dict,
                         full_data: List[str],
                         col_idxs: Dict[str, int],
                         is_train: bool,
                         task2type: Dict[str, str],
                         dataset: str
                         ) -> Instance:
        fields: Dict[str, Field] = {}
        tokens = TextField(sent_tasks['tokens'], self.token_indexers)
        for task in sent_tasks:
            if task == 'tokens':
                fields[task] = tokens
                fields['src_words'] = SequenceLabelField([str(x) for x in sent_tasks[task]],
                                                         tokens, label_namespace="src_tokens")
            elif task2type[task] == 'dependency':
                fields[task + '_rels'] = SequenceLabelField([x[0] for x in sent_tasks[task]],
                                                            tokens, label_namespace=task + '_rels')
                fields[task + '_head_indices'] = SequenceLabelField([x[1] for x in sent_tasks[task]],
                                                                    tokens, label_namespace=task + '_head_indices')
            elif task2type[task] == "multiseq":
                label_sequence = []
                for raw_label in sent_tasks[task]:
                    label_list = raw_label.split("$")
                    label_sequence.append(label_list)
                fields[task] = SequenceMultiLabelField(label_sequence, tokens, label_namespace=task)
            elif task2type[task] == 'classification':
                fields[task] = LabelField(sent_tasks[task], label_namespace=task)
            elif task2type[task] == 'seq2seq':
                fields[task + '_target'] = TextField(sent_tasks[task], self._target_token_indexers)
                fields[task + '_target_words'] = SequenceLabelField([str(x) for x in sent_tasks[task]],
                                                                    fields[task + '_target'],
                                                                    label_namespace=task + "_target_words")
            else:  
                fields[task] = SequenceLabelField(sent_tasks[task], tokens, label_namespace=task)
        fields['dataset'] = LabelField(dataset, label_namespace='dataset')
        sent_tasks["full_data"] = full_data
        sent_tasks["col_idxs"] = col_idxs
        sent_tasks['is_train'] = is_train
        fields["metadata"] = MetadataField(sent_tasks)
        return Instance(fields)
def text_to_instance ( self , sent_tasks : Dict , full_data : List [ str ] , col_idxs : Dict [ str , int ] , is_train : bool , task2type : Dict [ str , str ] , dataset : str ) -> Instance : fields : Dict [ str , Field ] = { } tokens = TextField ( sent_tasks [ 'tokens' ] , self . token_indexers ) for task in sent_tasks : if task == 'tokens' : fields [ task ] = tokens fields [ 'src_words' ] = SequenceLabelField ( [ str ( x ) for x in sent_tasks [ task ] ] , tokens , label_namespace = "src_tokens" ) elif task2type [ task ] == 'dependency' : fields [ task + '_rels' ] = SequenceLabelField ( [ x [ 0 ] for x in sent_tasks [ task ] ] , tokens , label_namespace = task + '_rels' ) fields [ task + '_head_indices' ] = SequenceLabelField ( [ x [ 1 ] for x in sent_tasks [ task ] ] , tokens , label_namespace = task + '_head_indices' ) elif task2type [ task ] == "multiseq" : label_sequence = [ ] for raw_label in sent_tasks [ task ] : label_list = raw_label . split ( "$" ) label_sequence . append ( label_list ) fields [ task ] = SequenceMultiLabelField ( label_sequence , tokens , label_namespace = task ) elif task2type [ task ] == 'classification' : fields [ task ] = LabelField ( sent_tasks [ task ] , label_namespace = task ) elif task2type [ task ] == 'seq2seq' : fields [ task + '_target' ] = TextField ( sent_tasks [ task ] , self . _target_token_indexers ) fields [ task + '_target_words' ] = SequenceLabelField ( [ str ( x ) for x in sent_tasks [ task ] ] , fields [ task + '_target' ] , label_namespace = task + "_target_words" ) else : fields [ task ] = SequenceLabelField ( sent_tasks [ task ] , tokens , label_namespace = task ) fields [ 'dataset' ] = LabelField ( dataset , label_namespace = 'dataset' ) sent_tasks [ "full_data" ] = full_data sent_tasks [ "col_idxs" ] = col_idxs sent_tasks [ 'is_train' ] = is_train fields [ "metadata" ] = MetadataField ( sent_tasks ) return Instance ( fields )
converts the previously read data into an AllenNLP Instance, containing mainly
a TextField and one or more *LabelField's
converts the previously read data into an AllenNLP Instance containing mainly a TextField and one or more * LabelField ' s
# type: ignore """
        converts the previously read data into an AllenNLP Instance, containing mainly
        a TextField and one or more *LabelField's
        """ # For each token label, check if it is a multilabel and handle it # seq labeling
self
sent_tasks
Dict
full_data
List[str]
col_idxs
Dict[str, int]
is_train
bool
task2type
Dict[str, str]
dataset
str