def __init__(self, data=None, dataset=None, device=None):
        """Create a Batch from a list of examples."""
        if data is not None:
            self.batch_size = len(data)
            self.dataset = dataset
            self.fields = dataset.fields.keys()  # copy field names
            self.input_fields = [k for k, v in dataset.fields.items() if
                                 v is not None and not v.is_target]
            self.target_fields = [k for k, v in dataset.fields.items() if
                                  v is not None and v.is_target]

            for (name, field) in dataset.fields.items():
                if field is not None:
                    batch = [getattr(x, name) for x in data]
                    setattr(self, name, field.process(batch, device=device))
def __init__ ( self , data = None , dataset = None , device = None ) : if data is not None : self . batch_size = len ( data ) self . dataset = dataset self . fields = dataset . fields . keys ( ) self . input_fields = [ k for k , v in dataset . fields . items ( ) if v is not None and not v . is_target ] self . target_fields = [ k for k , v in dataset . fields . items ( ) if v is not None and v . is_target ] for ( name , field ) in dataset . fields . items ( ) : if field is not None : batch = [ getattr ( x , name ) for x in data ] setattr ( self , name , field . process ( batch , device = device ) )
Create a Batch from a list of examples.