prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  A batch object created by fromvars does not have "fields" attribute
  When making a batch object, the value of the `fields` attribute is set in its `__init__` method.
  However, when created with `fromvars` class method, `fields` attribute is not set since the method first creates an empty object and then add information.
  It should be modified to be analogous with the one created by `__init__` method.
  It can be simply done by adding the following after https://github.com/pytorch/text/blob/master/torchtext/data/batch.py#L36:
  ```
  batch.fields = dataset.fields.keys()
  ```
  
  This kind of object creation is found when using BPTT iterator. Without `fields` attribute, printing a batch object is not possible due to https://github.com/pytorch/text/blob/master/torchtext/data/batch.py#L49.
  
  </issue>
  <code>
  [start of torchtext/data/batch.py]
  1 from torch import typename
  2 from torch.tensor import _TensorBase
  3 
  4 
  5 class Batch(object):
  6     """Defines a batch of examples along with its Fields.
  7 
  8     Attributes:
  9         batch_size: Number of examples in the batch.
  10         dataset: A reference to the dataset object the examples come from
  11             (which itself contains the dataset's Field objects).
  12         train: Whether the batch is from a training set.
  13 
  14     Also stores the Variable for each column in the batch as an attribute.
  15     """
  16 
  17     def __init__(self, data=None, dataset=None, device=None, train=True):
  18         """Create a Batch from a list of examples."""
  19         if data is not None:
  20             self.batch_size = len(data)
  21             self.dataset = dataset
  22             self.train = train
  23             self.fields = dataset.fields.keys()  # copy field names
  24 
  25             for (name, field) in dataset.fields.items():
  26                 if field is not None:
  27                     batch = [x.__dict__[name] for x in data]
  28                     setattr(self, name, field.process(batch, device=device, train=train))
  29 
  30     @classmethod
  31     def fromvars(cls, dataset, batch_size, train=True, **kwargs):
  32         """Create a Batch directly from a number of Variables."""
  33         batch = cls()
  34         batch.batch_size = batch_size
  35         batch.dataset = dataset
  36         batch.train = train
  37         for k, v in kwargs.items():
  38             setattr(batch, k, v)
  39         return batch
  40 
  41     def __repr__(self):
  42         return str(self)
  43 
  44     def __str__(self):
  45         if not self.__dict__:
  46             return 'Empty {} instance'.format(typename(self))
  47 
  48         var_strs = '\n'.join(['\t[.' + name + ']' + ":" + _short_str(getattr(self, name))
  49                               for name in self.fields if hasattr(self, name)])
  50 
  51         data_str = (' from {}'.format(self.dataset.name.upper())
  52                     if hasattr(self.dataset, 'name') and
  53                     isinstance(self.dataset.name, str) else '')
  54 
  55         strt = '[{} of size {}{}]\n{}'.format(typename(self),
  56                                               self.batch_size, data_str, var_strs)
  57         return '\n' + strt
  58 
  59     def __len__(self):
  60         return self.batch_size
  61 
  62 
  63 def _short_str(tensor):
  64     # unwrap variable to tensor
  65     if hasattr(tensor, 'data'):
  66         tensor = tensor.data
  67 
  68     # fallback in case of wrong argument type
  69     if issubclass(type(tensor), _TensorBase) is False:
  70         return str(tensor)
  71 
  72     # copied from torch _tensor_str
  73     size_str = 'x'.join(str(size) for size in tensor.size())
  74     device_str = '' if not tensor.is_cuda else \
  75         ' (GPU {})'.format(tensor.get_device())
  76     strt = '[{} of size {}{}]'.format(typename(tensor),
  77                                       size_str, device_str)
  78     return strt
  79
  [end of torchtext/data/batch.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/torchtext/data/batch.py b/torchtext/data/batch.py
  --- a/torchtext/data/batch.py
  +++ b/torchtext/data/batch.py
  @@ -34,6 +34,7 @@
           batch.batch_size = batch_size
           batch.dataset = dataset
           batch.train = train
  +        batch.fields = dataset.fields.keys()
           for k, v in kwargs.items():
               setattr(batch, k, v)
           return batch
  
verification_info: {"golden_diff": "diff --git a/torchtext/data/batch.py b/torchtext/data/batch.py\n--- a/torchtext/data/batch.py\n+++ b/torchtext/data/batch.py\n@@ -34,6 +34,7 @@\n         batch.batch_size = batch_size\n         batch.dataset = dataset\n         batch.train = train\n+        batch.fields = dataset.fields.keys()\n         for k, v in kwargs.items():\n             setattr(batch, k, v)\n         return batch\n", "issue": "A batch object created by fromvars does not have \"fields\" attribute\nWhen making a batch object, the value of the `fields` attribute is set in its `__init__` method.\r\nHowever, when created with `fromvars` class method, `fields` attribute is not set since the method first creates an empty object and then add information.\r\nIt should be modified to be analogous with the one created by `__init__` method.\r\nIt can be simply done by adding the following after https://github.com/pytorch/text/blob/master/torchtext/data/batch.py#L36:\r\n```\r\nbatch.fields = dataset.fields.keys()\r\n```\r\n\r\nThis kind of object creation is found when using BPTT iterator. Without `fields` attribute, printing a batch object is not possible due to https://github.com/pytorch/text/blob/master/torchtext/data/batch.py#L49.\n", "before_files": [{"content": "from torch import typename\nfrom torch.tensor import _TensorBase\n\n\nclass Batch(object):\n    \"\"\"Defines a batch of examples along with its Fields.\n\n    Attributes:\n        batch_size: Number of examples in the batch.\n        dataset: A reference to the dataset object the examples come from\n            (which itself contains the dataset's Field objects).\n        train: Whether the batch is from a training set.\n\n    Also stores the Variable for each column in the batch as an attribute.\n    \"\"\"\n\n    def __init__(self, data=None, dataset=None, device=None, train=True):\n        \"\"\"Create a Batch from a list of examples.\"\"\"\n        if data is not None:\n            self.batch_size = len(data)\n            self.dataset = dataset\n            self.train = train\n            self.fields = dataset.fields.keys()  # copy field names\n\n            for (name, field) in dataset.fields.items():\n                if field is not None:\n                    batch = [x.__dict__[name] for x in data]\n                    setattr(self, name, field.process(batch, device=device, train=train))\n\n    @classmethod\n    def fromvars(cls, dataset, batch_size, train=True, **kwargs):\n        \"\"\"Create a Batch directly from a number of Variables.\"\"\"\n        batch = cls()\n        batch.batch_size = batch_size\n        batch.dataset = dataset\n        batch.train = train\n        for k, v in kwargs.items():\n            setattr(batch, k, v)\n        return batch\n\n    def __repr__(self):\n        return str(self)\n\n    def __str__(self):\n        if not self.__dict__:\n            return 'Empty {} instance'.format(typename(self))\n\n        var_strs = '\\n'.join(['\\t[.' + name + ']' + \":\" + _short_str(getattr(self, name))\n                              for name in self.fields if hasattr(self, name)])\n\n        data_str = (' from {}'.format(self.dataset.name.upper())\n                    if hasattr(self.dataset, 'name') and\n                    isinstance(self.dataset.name, str) else '')\n\n        strt = '[{} of size {}{}]\\n{}'.format(typename(self),\n                                              self.batch_size, data_str, var_strs)\n        return '\\n' + strt\n\n    def __len__(self):\n        return self.batch_size\n\n\ndef _short_str(tensor):\n    # unwrap variable to tensor\n    if hasattr(tensor, 'data'):\n        tensor = tensor.data\n\n    # fallback in case of wrong argument type\n    if issubclass(type(tensor), _TensorBase) is False:\n        return str(tensor)\n\n    # copied from torch _tensor_str\n    size_str = 'x'.join(str(size) for size in tensor.size())\n    device_str = '' if not tensor.is_cuda else \\\n        ' (GPU {})'.format(tensor.get_device())\n    strt = '[{} of size {}{}]'.format(typename(tensor),\n                                      size_str, device_str)\n    return strt\n", "path": "torchtext/data/batch.py"}]}