We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
translate.py error with -n_best option (n > 1)
This happens with **-n_best, n> 1** and **-verbose**.
```
$ python translate.py -model model.pt -src source.txt -n_best 10 -output pred10best.txt -replace_unk -verbose
Loading model parameters.
PRED SCORE: -6.3616

BEST HYP:
Traceback (most recent call last):
  File "translate.py", line 116, in <module>
    main()
  File "translate.py", line 97, in main
    output = trans.log(sent_number)
  File "/home/user/OpenNMT-py/onmt/translate/Translation.py", line 116, in log
    for score, sent in zip(self.pred_score, self.pred_sents):
AttributeError: 'Translation' object has no attribute 'pred_score'
```
translate.py error with -n_best option (n > 1)
This happens with **-n_best, n> 1** and **-verbose**.
```
$ python translate.py -model model.pt -src source.txt -n_best 10 -output pred10best.txt -replace_unk -verbose
Loading model parameters.
PRED SCORE: -6.3616

BEST HYP:
Traceback (most recent call last):
  File "translate.py", line 116, in <module>
    main()
  File "translate.py", line 97, in main
    output = trans.log(sent_number)
  File "/home/user/OpenNMT-py/onmt/translate/Translation.py", line 116, in log
    for score, sent in zip(self.pred_score, self.pred_sents):
AttributeError: 'Translation' object has no attribute 'pred_score'
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `onmt/translate/Translation.py`
Content:
```
1 from __future__ import division, unicode_literals
2 
3 import torch
4 import onmt.io
5 
6 
7 class TranslationBuilder(object):
8     """
9     Build a word-based translation from the batch output
10     of translator and the underlying dictionaries.
11 
12     Replacement based on "Addressing the Rare Word
13     Problem in Neural Machine Translation" :cite:`Luong2015b`
14 
15     Args:
16        data (DataSet):
17        fields (dict of Fields): data fields
18        n_best (int): number of translations produced
19        replace_unk (bool): replace unknown words using attention
20        has_tgt (bool): will the batch have gold targets
21     """
22     def __init__(self, data, fields, n_best, replace_unk, has_tgt):
23         self.data = data
24         self.fields = fields
25         self.n_best = n_best
26         self.replace_unk = replace_unk
27         self.has_tgt = has_tgt
28 
29     def _build_target_tokens(self, src, src_vocab, src_raw, pred, attn):
30         vocab = self.fields["tgt"].vocab
31         tokens = []
32         for tok in pred:
33             if tok < len(vocab):
34                 tokens.append(vocab.itos[tok])
35             else:
36                 tokens.append(src_vocab.itos[tok - len(vocab)])
37             if tokens[-1] == onmt.io.EOS_WORD:
38                 tokens = tokens[:-1]
39                 break
40         if self.replace_unk and (attn is not None) and (src is not None):
41             for i in range(len(tokens)):
42                 if tokens[i] == vocab.itos[onmt.io.UNK]:
43                     _, maxIndex = attn[i].max(0)
44                     tokens[i] = src_raw[maxIndex[0]]
45         return tokens
46 
47     def from_batch(self, translation_batch):
48         batch = translation_batch["batch"]
49         assert(len(translation_batch["gold_score"]) ==
50                len(translation_batch["predictions"]))
51         batch_size = batch.batch_size
52 
53         preds, predScore, attn, gold_score, indices = list(zip(
54             *sorted(zip(translation_batch["predictions"],
55                         translation_batch["scores"],
56                         translation_batch["attention"],
57                         translation_batch["gold_score"],
58                         batch.indices.data),
59                     key=lambda x: x[-1])))
60 
61         # Sorting
62         inds, perm = torch.sort(batch.indices.data)
63         data_type = self.data.data_type
64         if data_type == 'text':
65             src = batch.src[0].data.index_select(1, perm)
66         else:
67             src = None
68 
69         if self.has_tgt:
70             tgt = batch.tgt.data.index_select(1, perm)
71         else:
72             tgt = None
73 
74         translations = []
75         for b in range(batch_size):
76             if data_type == 'text':
77                 src_vocab = self.data.src_vocabs[inds[b]]
78                 src_raw = self.data.examples[inds[b]].src
79             else:
80                 src_vocab = None
81                 src_raw = None
82             pred_sents = [self._build_target_tokens(
83                 src[:, b] if src is not None else None,
84                 src_vocab, src_raw,
85                 preds[b][n], attn[b][n])
86                           for n in range(self.n_best)]
87             gold_sent = None
88             if tgt is not None:
89                 gold_sent = self._build_target_tokens(
90                     src[:, b] if src is not None else None,
91                     src_vocab, src_raw,
92                     tgt[1:, b] if tgt is not None else None, None)
93 
94             translation = Translation(src[:, b] if src is not None else None,
95                                       src_raw, pred_sents,
96                                       attn[b], predScore[b], gold_sent,
97                                       gold_score[b])
98             translations.append(translation)
99 
100         return translations
101 
102 
103 class Translation(object):
104     """
105     Container for a translated sentence.
106 
107     Attributes:
108         src (`LongTensor`): src word ids
109         src_raw ([str]): raw src words
110 
111         pred_sents ([[str]]): words from the n-best translations
112         pred_scores ([[float]]): log-probs of n-best translations
113         attns ([`FloatTensor`]) : attention dist for each translation
114         gold_sent ([str]): words from gold translation
115         gold_score ([float]): log-prob of gold translation
116 
117     """
118     def __init__(self, src, src_raw, pred_sents,
119                  attn, pred_scores, tgt_sent, gold_score):
120         self.src = src
121         self.src_raw = src_raw
122         self.pred_sents = pred_sents
123         self.attns = attn
124         self.pred_scores = pred_scores
125         self.gold_sent = tgt_sent
126         self.gold_score = gold_score
127 
128     def log(self, sent_number):
129         """
130         Log translation to stdout.
131         """
132         output = '\nSENT {}: {}\n'.format(sent_number, self.src_raw)
133 
134         best_pred = self.pred_sents[0]
135         best_score = self.pred_scores[0]
136         pred_sent = ' '.join(best_pred)
137         output += 'PRED {}: {}\n'.format(sent_number, pred_sent)
138         print("PRED SCORE: {:.4f}".format(best_score))
139 
140         if self.gold_sent is not None:
141             tgt_sent = ' '.join(self.gold_sent)
142             output += 'GOLD {}: {}\n'.format(sent_number, tgt_sent)
143             output += ("GOLD SCORE: {:.4f}".format(self.gold_score))
144 
145         if len(self.pred_sents) > 1:
146             print('\nBEST HYP:')
147             for score, sent in zip(self.pred_score, self.pred_sents):
148                 output += "[{:.4f}] {}\n".format(score, sent)
149 
150         return output
151
```
--- 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/onmt/translate/Translation.py b/onmt/translate/Translation.py
--- a/onmt/translate/Translation.py
+++ b/onmt/translate/Translation.py
@@ -113,7 +113,7 @@
 
         if len(self.pred_sents) > 1:
             print('\nBEST HYP:')
-            for score, sent in zip(self.pred_score, self.pred_sents):
+            for score, sent in zip(self.pred_scores, self.pred_sents):
                 output += "[{:.4f}] {}\n".format(score, sent)
 
         return output

{"golden_diff": "diff --git a/onmt/translate/Translation.py b/onmt/translate/Translation.py\n--- a/onmt/translate/Translation.py\n+++ b/onmt/translate/Translation.py\n@@ -113,7 +113,7 @@\n \n         if len(self.pred_sents) > 1:\n             print('\\nBEST HYP:')\n-            for score, sent in zip(self.pred_score, self.pred_sents):\n+            for score, sent in zip(self.pred_scores, self.pred_sents):\n                 output += \"[{:.4f}] {}\\n\".format(score, sent)\n \n         return output\n", "issue": "translate.py error with -n_best option (n > 1)\nThis happens with **-n_best, n> 1** and **-verbose**.\r\n```\r\n$ python translate.py -model model.pt -src source.txt -n_best 10 -output pred10best.txt -replace_unk -verbose\r\nLoading model parameters.\r\nPRED SCORE: -6.3616\r\n\r\nBEST HYP:\r\nTraceback (most recent call last):\r\n  File \"translate.py\", line 116, in <module>\r\n    main()\r\n  File \"translate.py\", line 97, in main\r\n    output = trans.log(sent_number)\r\n  File \"/home/user/OpenNMT-py/onmt/translate/Translation.py\", line 116, in log\r\n    for score, sent in zip(self.pred_score, self.pred_sents):\r\nAttributeError: 'Translation' object has no attribute 'pred_score'\r\n```\ntranslate.py error with -n_best option (n > 1)\nThis happens with **-n_best, n> 1** and **-verbose**.\r\n```\r\n$ python translate.py -model model.pt -src source.txt -n_best 10 -output pred10best.txt -replace_unk -verbose\r\nLoading model parameters.\r\nPRED SCORE: -6.3616\r\n\r\nBEST HYP:\r\nTraceback (most recent call last):\r\n  File \"translate.py\", line 116, in <module>\r\n    main()\r\n  File \"translate.py\", line 97, in main\r\n    output = trans.log(sent_number)\r\n  File \"/home/user/OpenNMT-py/onmt/translate/Translation.py\", line 116, in log\r\n    for score, sent in zip(self.pred_score, self.pred_sents):\r\nAttributeError: 'Translation' object has no attribute 'pred_score'\r\n```\n", "before_files": [{"content": "from __future__ import division, unicode_literals\n\nimport torch\nimport onmt.io\n\n\nclass TranslationBuilder(object):\n    \"\"\"\n    Build a word-based translation from the batch output\n    of translator and the underlying dictionaries.\n\n    Replacement based on \"Addressing the Rare Word\n    Problem in Neural Machine Translation\" :cite:`Luong2015b`\n\n    Args:\n       data (DataSet):\n       fields (dict of Fields): data fields\n       n_best (int): number of translations produced\n       replace_unk (bool): replace unknown words using attention\n       has_tgt (bool): will the batch have gold targets\n    \"\"\"\n    def __init__(self, data, fields, n_best, replace_unk, has_tgt):\n        self.data = data\n        self.fields = fields\n        self.n_best = n_best\n        self.replace_unk = replace_unk\n        self.has_tgt = has_tgt\n\n    def _build_target_tokens(self, src, src_vocab, src_raw, pred, attn):\n        vocab = self.fields[\"tgt\"].vocab\n        tokens = []\n        for tok in pred:\n            if tok < len(vocab):\n                tokens.append(vocab.itos[tok])\n            else:\n                tokens.append(src_vocab.itos[tok - len(vocab)])\n            if tokens[-1] == onmt.io.EOS_WORD:\n                tokens = tokens[:-1]\n                break\n        if self.replace_unk and (attn is not None) and (src is not None):\n            for i in range(len(tokens)):\n                if tokens[i] == vocab.itos[onmt.io.UNK]:\n                    _, maxIndex = attn[i].max(0)\n                    tokens[i] = src_raw[maxIndex[0]]\n        return tokens\n\n    def from_batch(self, translation_batch):\n        batch = translation_batch[\"batch\"]\n        assert(len(translation_batch[\"gold_score\"]) ==\n               len(translation_batch[\"predictions\"]))\n        batch_size = batch.batch_size\n\n        preds, predScore, attn, gold_score, indices = list(zip(\n            *sorted(zip(translation_batch[\"predictions\"],\n                        translation_batch[\"scores\"],\n                        translation_batch[\"attention\"],\n                        translation_batch[\"gold_score\"],\n                        batch.indices.data),\n                    key=lambda x: x[-1])))\n\n        # Sorting\n        inds, perm = torch.sort(batch.indices.data)\n        data_type = self.data.data_type\n        if data_type == 'text':\n            src = batch.src[0].data.index_select(1, perm)\n        else:\n            src = None\n\n        if self.has_tgt:\n            tgt = batch.tgt.data.index_select(1, perm)\n        else:\n            tgt = None\n\n        translations = []\n        for b in range(batch_size):\n            if data_type == 'text':\n                src_vocab = self.data.src_vocabs[inds[b]]\n                src_raw = self.data.examples[inds[b]].src\n            else:\n                src_vocab = None\n                src_raw = None\n            pred_sents = [self._build_target_tokens(\n                src[:, b] if src is not None else None,\n                src_vocab, src_raw,\n                preds[b][n], attn[b][n])\n                          for n in range(self.n_best)]\n            gold_sent = None\n            if tgt is not None:\n                gold_sent = self._build_target_tokens(\n                    src[:, b] if src is not None else None,\n                    src_vocab, src_raw,\n                    tgt[1:, b] if tgt is not None else None, None)\n\n            translation = Translation(src[:, b] if src is not None else None,\n                                      src_raw, pred_sents,\n                                      attn[b], predScore[b], gold_sent,\n                                      gold_score[b])\n            translations.append(translation)\n\n        return translations\n\n\nclass Translation(object):\n    \"\"\"\n    Container for a translated sentence.\n\n    Attributes:\n        src (`LongTensor`): src word ids\n        src_raw ([str]): raw src words\n\n        pred_sents ([[str]]): words from the n-best translations\n        pred_scores ([[float]]): log-probs of n-best translations\n        attns ([`FloatTensor`]) : attention dist for each translation\n        gold_sent ([str]): words from gold translation\n        gold_score ([float]): log-prob of gold translation\n\n    \"\"\"\n    def __init__(self, src, src_raw, pred_sents,\n                 attn, pred_scores, tgt_sent, gold_score):\n        self.src = src\n        self.src_raw = src_raw\n        self.pred_sents = pred_sents\n        self.attns = attn\n        self.pred_scores = pred_scores\n        self.gold_sent = tgt_sent\n        self.gold_score = gold_score\n\n    def log(self, sent_number):\n        \"\"\"\n        Log translation to stdout.\n        \"\"\"\n        output = '\\nSENT {}: {}\\n'.format(sent_number, self.src_raw)\n\n        best_pred = self.pred_sents[0]\n        best_score = self.pred_scores[0]\n        pred_sent = ' '.join(best_pred)\n        output += 'PRED {}: {}\\n'.format(sent_number, pred_sent)\n        print(\"PRED SCORE: {:.4f}\".format(best_score))\n\n        if self.gold_sent is not None:\n            tgt_sent = ' '.join(self.gold_sent)\n            output += 'GOLD {}: {}\\n'.format(sent_number, tgt_sent)\n            output += (\"GOLD SCORE: {:.4f}\".format(self.gold_score))\n\n        if len(self.pred_sents) > 1:\n            print('\\nBEST HYP:')\n            for score, sent in zip(self.pred_score, self.pred_sents):\n                output += \"[{:.4f}] {}\\n\".format(score, sent)\n\n        return output\n", "path": "onmt/translate/Translation.py"}], "after_files": [{"content": "from __future__ import division, unicode_literals\n\nimport torch\nimport onmt.io\n\n\nclass TranslationBuilder(object):\n    def __init__(self, data, fields, n_best, replace_unk, has_tgt):\n        self.data = data\n        self.fields = fields\n        self.n_best = n_best\n        self.replace_unk = replace_unk\n        self.has_tgt = has_tgt\n\n    def _build_target_tokens(self, src, src_vocab, src_raw, pred, attn):\n        vocab = self.fields[\"tgt\"].vocab\n        tokens = []\n        for tok in pred:\n            if tok < len(vocab):\n                tokens.append(vocab.itos[tok])\n            else:\n                tokens.append(src_vocab.itos[tok - len(vocab)])\n            if tokens[-1] == onmt.io.EOS_WORD:\n                tokens = tokens[:-1]\n                break\n        if self.replace_unk and (attn is not None) and (src is not None):\n            for i in range(len(tokens)):\n                if tokens[i] == vocab.itos[onmt.io.UNK]:\n                    _, maxIndex = attn[i].max(0)\n                    tokens[i] = src_raw[maxIndex[0]]\n        return tokens\n\n    def from_batch(self, translation_batch):\n        batch = translation_batch[\"batch\"]\n        assert(len(translation_batch[\"gold_score\"]) ==\n               len(translation_batch[\"predictions\"]))\n        batch_size = batch.batch_size\n\n        preds, predScore, attn, gold_score, indices = list(zip(\n            *sorted(zip(translation_batch[\"predictions\"],\n                        translation_batch[\"scores\"],\n                        translation_batch[\"attention\"],\n                        translation_batch[\"gold_score\"],\n                        batch.indices.data),\n                    key=lambda x: x[-1])))\n\n        # Sorting\n        inds, perm = torch.sort(batch.indices.data)\n        data_type = self.data.data_type\n        if data_type == 'text':\n            src = batch.src[0].data.index_select(1, perm)\n        else:\n            src = None\n\n        if self.has_tgt:\n            tgt = batch.tgt.data.index_select(1, perm)\n        else:\n            tgt = None\n\n        translations = []\n        for b in range(batch_size):\n            if data_type == 'text':\n                src_vocab = self.data.src_vocabs[inds[b]]\n                src_raw = self.data.examples[inds[b]].src\n            else:\n                src_vocab = None\n                src_raw = None\n            pred_sents = [self._build_target_tokens(\n                src[:, b] if src is not None else None,\n                src_vocab, src_raw,\n                preds[b][n], attn[b][n])\n                          for n in range(self.n_best)]\n            gold_sent = None\n            if tgt is not None:\n                gold_sent = self._build_target_tokens(\n                    src[:, b] if src is not None else None,\n                    src_vocab, src_raw,\n                    tgt[1:, b] if tgt is not None else None, None)\n\n            translation = Translation(src[:, b] if src is not None else None,\n                                      src_raw, pred_sents,\n                                      attn[b], predScore[b], gold_sent,\n                                      gold_score[b])\n            translations.append(translation)\n\n        return translations\n\n\nclass Translation(object):\n    def __init__(self, src, src_raw, pred_sents,\n                 attn, pred_scores, tgt_sent, gold_score):\n        self.src = src\n        self.src_raw = src_raw\n        self.pred_sents = pred_sents\n        self.attns = attn\n        self.pred_scores = pred_scores\n        self.gold_sent = tgt_sent\n        self.gold_score = gold_score\n\n    def log(self, sent_number):\n        output = '\\nSENT {}: {}\\n'.format(sent_number, self.src_raw)\n\n        best_pred = self.pred_sents[0]\n        best_score = self.pred_scores[0]\n        pred_sent = ' '.join(best_pred)\n        output += 'PRED {}: {}\\n'.format(sent_number, pred_sent)\n        print(\"PRED SCORE: {:.4f}\".format(best_score))\n\n        if self.gold_sent is not None:\n            tgt_sent = ' '.join(self.gold_sent)\n            output += 'GOLD {}: {}\\n'.format(sent_number, tgt_sent)\n            output += (\"GOLD SCORE: {:.4f}\".format(self.gold_score))\n\n        if len(self.pred_sents) > 1:\n            print('\\nBEST HYP:')\n            for score, sent in zip(self.pred_scores, self.pred_sents):\n                output += \"[{:.4f}] {}\\n\".format(score, sent)\n\n        return output\n", "path": "onmt/translate/Translation.py"}]}