We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
TypeError in Python 2.7
https://github.com/pytorch/text/blob/a2795e5731d1b7c0298a1b5087bb8142e1c39d0b/torchtext/datasets/imdb.py#L32

In python 2.7, it will report that `TypeError: 'encoding' is an invalid keyword argument for this function`.

I replace `open` with `io.open` to fix it.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `torchtext/datasets/imdb.py`
Content:
```
1 import os
2 import glob
3 
4 from .. import data
5 
6 
7 class IMDB(data.Dataset):
8 
9     urls = ['http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz']
10     name = 'imdb'
11     dirname = 'aclImdb'
12 
13     @staticmethod
14     def sort_key(ex):
15         return len(ex.text)
16 
17     def __init__(self, path, text_field, label_field, **kwargs):
18         """Create an IMDB dataset instance given a path and fields.
19 
20         Arguments:
21             path: Path to the dataset's highest level directory
22             text_field: The field that will be used for text data.
23             label_field: The field that will be used for label data.
24             Remaining keyword arguments: Passed to the constructor of
25                 data.Dataset.
26         """
27         fields = [('text', text_field), ('label', label_field)]
28         examples = []
29 
30         for label in ['pos', 'neg']:
31             for fname in glob.iglob(os.path.join(path, label, '*.txt')):
32                 with open(fname, 'r', encoding="utf-8") as f:
33                     text = f.readline()
34                 examples.append(data.Example.fromlist([text, label], fields))
35 
36         super(IMDB, self).__init__(examples, fields, **kwargs)
37 
38     @classmethod
39     def splits(cls, text_field, label_field, root='.data',
40                train='train', test='test', **kwargs):
41         """Create dataset objects for splits of the IMDB dataset.
42 
43         Arguments:
44             text_field: The field that will be used for the sentence.
45             label_field: The field that will be used for label data.
46             root: Root dataset storage directory. Default is '.data'.
47             train: The directory that contains the training examples
48             test: The directory that contains the test examples
49             Remaining keyword arguments: Passed to the splits method of
50                 Dataset.
51         """
52         return super(IMDB, cls).splits(
53             root=root, text_field=text_field, label_field=label_field,
54             train=train, validation=None, test=test, **kwargs)
55 
56     @classmethod
57     def iters(cls, batch_size=32, device=0, root='.data', vectors=None, **kwargs):
58         """Creater iterator objects for splits of the IMDB dataset.
59 
60         Arguments:
61             batch_size: Batch_size
62             device: Device to create batches on. Use - 1 for CPU and None for
63                 the currently active GPU device.
64             root: The root directory that contains the imdb dataset subdirectory
65             vectors: one of the available pretrained vectors or a list with each
66                 element one of the available pretrained vectors (see Vocab.load_vectors)
67 
68             Remaining keyword arguments: Passed to the splits method.
69         """
70         TEXT = data.Field()
71         LABEL = data.Field(sequential=False)
72 
73         train, test = cls.splits(TEXT, LABEL, root=root, **kwargs)
74 
75         TEXT.build_vocab(train, vectors=vectors)
76         LABEL.build_vocab(train)
77 
78         return data.BucketIterator.splits(
79             (train, test), batch_size=batch_size, device=device)
80
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/torchtext/datasets/imdb.py b/torchtext/datasets/imdb.py
--- a/torchtext/datasets/imdb.py
+++ b/torchtext/datasets/imdb.py
@@ -1,5 +1,6 @@
 import os
 import glob
+import io
 
 from .. import data
 
@@ -29,7 +30,7 @@
 
         for label in ['pos', 'neg']:
             for fname in glob.iglob(os.path.join(path, label, '*.txt')):
-                with open(fname, 'r', encoding="utf-8") as f:
+                with io.open(fname, 'r', encoding="utf-8") as f:
                     text = f.readline()
                 examples.append(data.Example.fromlist([text, label], fields))

{"golden_diff": "diff --git a/torchtext/datasets/imdb.py b/torchtext/datasets/imdb.py\n--- a/torchtext/datasets/imdb.py\n+++ b/torchtext/datasets/imdb.py\n@@ -1,5 +1,6 @@\n import os\n import glob\n+import io\n \n from .. import data\n \n@@ -29,7 +30,7 @@\n \n         for label in ['pos', 'neg']:\n             for fname in glob.iglob(os.path.join(path, label, '*.txt')):\n-                with open(fname, 'r', encoding=\"utf-8\") as f:\n+                with io.open(fname, 'r', encoding=\"utf-8\") as f:\n                     text = f.readline()\n                 examples.append(data.Example.fromlist([text, label], fields))\n", "issue": "TypeError in Python 2.7\nhttps://github.com/pytorch/text/blob/a2795e5731d1b7c0298a1b5087bb8142e1c39d0b/torchtext/datasets/imdb.py#L32\r\n\r\nIn python 2.7, it will report that `TypeError: 'encoding' is an invalid keyword argument for this function`.\r\n\r\nI replace `open` with `io.open` to fix it.\n", "before_files": [{"content": "import os\nimport glob\n\nfrom .. import data\n\n\nclass IMDB(data.Dataset):\n\n    urls = ['http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz']\n    name = 'imdb'\n    dirname = 'aclImdb'\n\n    @staticmethod\n    def sort_key(ex):\n        return len(ex.text)\n\n    def __init__(self, path, text_field, label_field, **kwargs):\n        \"\"\"Create an IMDB dataset instance given a path and fields.\n\n        Arguments:\n            path: Path to the dataset's highest level directory\n            text_field: The field that will be used for text data.\n            label_field: The field that will be used for label data.\n            Remaining keyword arguments: Passed to the constructor of\n                data.Dataset.\n        \"\"\"\n        fields = [('text', text_field), ('label', label_field)]\n        examples = []\n\n        for label in ['pos', 'neg']:\n            for fname in glob.iglob(os.path.join(path, label, '*.txt')):\n                with open(fname, 'r', encoding=\"utf-8\") as f:\n                    text = f.readline()\n                examples.append(data.Example.fromlist([text, label], fields))\n\n        super(IMDB, self).__init__(examples, fields, **kwargs)\n\n    @classmethod\n    def splits(cls, text_field, label_field, root='.data',\n               train='train', test='test', **kwargs):\n        \"\"\"Create dataset objects for splits of the IMDB dataset.\n\n        Arguments:\n            text_field: The field that will be used for the sentence.\n            label_field: The field that will be used for label data.\n            root: Root dataset storage directory. Default is '.data'.\n            train: The directory that contains the training examples\n            test: The directory that contains the test examples\n            Remaining keyword arguments: Passed to the splits method of\n                Dataset.\n        \"\"\"\n        return super(IMDB, cls).splits(\n            root=root, text_field=text_field, label_field=label_field,\n            train=train, validation=None, test=test, **kwargs)\n\n    @classmethod\n    def iters(cls, batch_size=32, device=0, root='.data', vectors=None, **kwargs):\n        \"\"\"Creater iterator objects for splits of the IMDB dataset.\n\n        Arguments:\n            batch_size: Batch_size\n            device: Device to create batches on. Use - 1 for CPU and None for\n                the currently active GPU device.\n            root: The root directory that contains the imdb dataset subdirectory\n            vectors: one of the available pretrained vectors or a list with each\n                element one of the available pretrained vectors (see Vocab.load_vectors)\n\n            Remaining keyword arguments: Passed to the splits method.\n        \"\"\"\n        TEXT = data.Field()\n        LABEL = data.Field(sequential=False)\n\n        train, test = cls.splits(TEXT, LABEL, root=root, **kwargs)\n\n        TEXT.build_vocab(train, vectors=vectors)\n        LABEL.build_vocab(train)\n\n        return data.BucketIterator.splits(\n            (train, test), batch_size=batch_size, device=device)\n", "path": "torchtext/datasets/imdb.py"}], "after_files": [{"content": "import os\nimport glob\nimport io\n\nfrom .. import data\n\n\nclass IMDB(data.Dataset):\n\n    urls = ['http://ai.stanford.edu/~amaas/data/sentiment/aclImdb_v1.tar.gz']\n    name = 'imdb'\n    dirname = 'aclImdb'\n\n    @staticmethod\n    def sort_key(ex):\n        return len(ex.text)\n\n    def __init__(self, path, text_field, label_field, **kwargs):\n        \"\"\"Create an IMDB dataset instance given a path and fields.\n\n        Arguments:\n            path: Path to the dataset's highest level directory\n            text_field: The field that will be used for text data.\n            label_field: The field that will be used for label data.\n            Remaining keyword arguments: Passed to the constructor of\n                data.Dataset.\n        \"\"\"\n        fields = [('text', text_field), ('label', label_field)]\n        examples = []\n\n        for label in ['pos', 'neg']:\n            for fname in glob.iglob(os.path.join(path, label, '*.txt')):\n                with io.open(fname, 'r', encoding=\"utf-8\") as f:\n                    text = f.readline()\n                examples.append(data.Example.fromlist([text, label], fields))\n\n        super(IMDB, self).__init__(examples, fields, **kwargs)\n\n    @classmethod\n    def splits(cls, text_field, label_field, root='.data',\n               train='train', test='test', **kwargs):\n        \"\"\"Create dataset objects for splits of the IMDB dataset.\n\n        Arguments:\n            text_field: The field that will be used for the sentence.\n            label_field: The field that will be used for label data.\n            root: Root dataset storage directory. Default is '.data'.\n            train: The directory that contains the training examples\n            test: The directory that contains the test examples\n            Remaining keyword arguments: Passed to the splits method of\n                Dataset.\n        \"\"\"\n        return super(IMDB, cls).splits(\n            root=root, text_field=text_field, label_field=label_field,\n            train=train, validation=None, test=test, **kwargs)\n\n    @classmethod\n    def iters(cls, batch_size=32, device=0, root='.data', vectors=None, **kwargs):\n        \"\"\"Creater iterator objects for splits of the IMDB dataset.\n\n        Arguments:\n            batch_size: Batch_size\n            device: Device to create batches on. Use - 1 for CPU and None for\n                the currently active GPU device.\n            root: The root directory that contains the imdb dataset subdirectory\n            vectors: one of the available pretrained vectors or a list with each\n                element one of the available pretrained vectors (see Vocab.load_vectors)\n\n            Remaining keyword arguments: Passed to the splits method.\n        \"\"\"\n        TEXT = data.Field()\n        LABEL = data.Field(sequential=False)\n\n        train, test = cls.splits(TEXT, LABEL, root=root, **kwargs)\n\n        TEXT.build_vocab(train, vectors=vectors)\n        LABEL.build_vocab(train)\n\n        return data.BucketIterator.splits(\n            (train, test), batch_size=batch_size, device=device)\n", "path": "torchtext/datasets/imdb.py"}]}