We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
FileNotFoundError when running WoW in interactive
**Bug description**
I am running the following command: `parlai interactive -mf models:wizard_of_wikipedia/end2end_generator/model -t wizard_of_wikipedia`. At the step when "loading topics" there is a missing file error: `FileNotFoundError: [Errno 2] No such file or directory: '/mnt/disks/disk-huge/melody/parlai/data/wizard_of_wikipedia/topic_splits.json'`

**Reproduction steps**
Run `parlai interactive -mf models:wizard_of_wikipedia/end2end_generator/model -t wizard_of_wikipedia`

**Expected behavior**
The file is automatically downloaded, topics are loaded and the interactive session begins.

**Logs**
Please paste the command line output:

```
14:49:06 | creating task(s): wizard_of_wikipedia
[ loading topics.. ]
Traceback (most recent call last):
  File "/home/melody/anaconda3/envs/parlai/bin/parlai", line 33, in <module>
    sys.exit(load_entry_point('parlai', 'console_scripts', 'parlai')())
  File "/mnt/disks/disk-huge/melody/parlai/parlai/core/script.py", line 272, in superscript_main
    SCRIPT_REGISTRY[cmd].klass._run_from_parser_and_opt(opt, parser)
  File "/mnt/disks/disk-huge/melody/parlai/parlai/core/script.py", line 88, in _run_from_parser_and_opt
    return script.run()
  File "/mnt/disks/disk-huge/melody/parlai/parlai/scripts/interactive.py", line 117, in run
    return interactive(self.opt)
  File "/mnt/disks/disk-huge/melody/parlai/parlai/scripts/interactive.py", line 88, in interactive
    world = create_task(opt, [human_agent, agent])
  File "/mnt/disks/disk-huge/melody/parlai/parlai/core/worlds.py", line 1262, in create_task
    world = create_task_world(opt, user_agents, default_world=default_world)
  File "/mnt/disks/disk-huge/melody/parlai/parlai/core/worlds.py", line 1235, in create_task_world
    return world_class(opt, task_agents + user_agents)
  File "/mnt/disks/disk-huge/melody/parlai/parlai/tasks/wizard_of_wikipedia/worlds.py", line 53, in __init__
    self._load_topics(opt)
  File "/mnt/disks/disk-huge/melody/parlai/parlai/tasks/wizard_of_wikipedia/worlds.py", line 82, in _load_topics
    self.topic_list = json.load(open(topics_path, 'rb'))[datatype]
FileNotFoundError: [Errno 2] No such file or directory: '/mnt/disks/disk-huge/melody/parlai/data/wizard_of_wikipedia/topic_splits.json'
```

**Additional context**
Add any other context about the problem here. (like proxy settings, network setup, overall goals, etc.)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `parlai/tasks/wizard_of_wikipedia/worlds.py`
Content:
```
1 #!/usr/bin/env python3
2 
3 # Copyright (c) Facebook, Inc. and its affiliates.
4 # This source code is licensed under the MIT license found in the
5 # LICENSE file in the root directory of this source tree.
6 
7 from copy import deepcopy
8 import json
9 import random
10 import os
11 import string
12 
13 
14 from parlai.core.agents import create_agent
15 from parlai.core.message import Message
16 from parlai.core.worlds import DialogPartnerWorld, validate
17 from parlai.tasks.wizard_of_wikipedia.agents import TOKEN_KNOWLEDGE, TOKEN_END_KNOWLEDGE
18 from parlai.tasks.self_chat.worlds import SelfChatWorld as SelfChatBaseWorld
19 from parlai.utils.misc import warn_once
20 
21 from projects.wizard_of_wikipedia.knowledge_retriever.knowledge_retriever import (
22     KnowledgeRetrieverAgent,
23 )
24 
25 
26 NO_TOPIC = '[NO TOPIC]'
27 
28 
29 class InteractiveWorld(DialogPartnerWorld):
30     """
31     Interactive world for wizard of wikipedia.
32 
33     Used for models trained on the task `-t wizard_of_wikipedia`. Automatically
34     retrieves knowledge from Wikipedia based on the conversation history using a TF-IDF
35     retriever. Then uses a Transformer-based model to select a checked sentence from
36     these retrieved passages.
37     """
38 
39     @staticmethod
40     def add_cmdline_args(argparser):
41         parser = argparser.add_argument_group('WoW Interactive World Args')
42         parser.add_argument(
43             '--print-checked-sentence',
44             type='bool',
45             default=True,
46             help='Print sentence that the model checks.',
47         )
48 
49     def __init__(self, opt, agents, shared=None):
50         super().__init__(opt, agents, shared)
51         print('[ loading topics.. ]')
52         self.opt = opt
53         self._load_topics(opt)
54         self.num_topics = opt['num_topics']
55         self.cnt = 0
56         self.human_agent = self.agents[0]
57         self.model_agent = self.agents[1]
58 
59         self._set_up_knowledge_agent(opt.get('add_token_knowledge', False))
60 
61         self.print_checked_sentence = opt['print_checked_sentence']
62 
63     def _set_up_knowledge_agent(self, add_token_knowledge=False):
64         from parlai.core.params import ParlaiParser
65 
66         parser = ParlaiParser(False, False)
67         KnowledgeRetrieverAgent.add_cmdline_args(parser)
68         parser.set_params(
69             model='projects:wizard_of_wikipedia:knowledge_retriever',
70             add_token_knowledge=add_token_knowledge,
71         )
72         knowledge_opt = parser.parse_args([])
73         self.knowledge_agent = create_agent(knowledge_opt)
74 
75     def _load_topics(self, opt):
76         # Load possible chosen topics
77         topics_path = os.path.join(
78             opt['datapath'], 'wizard_of_wikipedia', 'topic_splits.json'
79         )
80         # Get training set topics
81         datatype = opt['datatype'].split(':')[0]
82         self.topic_list = json.load(open(topics_path, 'rb'))[datatype]
83 
84     def _get_new_topic(self):
85         random.seed()
86         topics = random.sample(self.topic_list, self.num_topics - 1)
87         topics.append(NO_TOPIC)
88         letters = list(string.ascii_uppercase)[: self.num_topics]
89         topic_list = {x: y for x, y in zip(letters, topics)}
90         topic_text = '\n'.join(['{}: {}'.format(k, v) for k, v in topic_list.items()])
91 
92         done = False
93         while not done:
94             self.human_agent.observe(
95                 {
96                     'text': '\nPlease choose one of the following topics by typing '
97                     'A, B, C, ..., etc. : \n\n{}\n'.format(topic_text)
98                 }
99             )
100             topic_act = self.human_agent.act()
101             choice = topic_act['text'][0].upper()
102             if choice in topic_list:
103                 done = True
104             else:
105                 self.human_agent.observe(
106                     {'text': 'Invalid response, please try again.'}
107                 )
108 
109         chosen_topic = topic_list[choice]
110         print('[ Your chosen topic is: {} ]'.format(chosen_topic))
111         return chosen_topic
112 
113     def _add_knowledge_to_act(self, act):
114         self.knowledge_agent.observe(act, actor_id='apprentice')
115         knowledge_act = self.knowledge_agent.act()
116         act['knowledge'] = knowledge_act['text']
117         act['checked_sentence'] = knowledge_act['checked_sentence']
118         if self.print_checked_sentence:
119             print(
120                 '[ Using chosen sentence from Wikpedia ]: {}'.format(
121                     knowledge_act['checked_sentence']
122                 )
123             )
124         act['title'] = knowledge_act['title']
125         return act
126 
127     def parley(self):
128         """
129         Loop between wizard and apprentice.
130 
131         Adds knowledge to the wizard observations. Assumes that the model agent is the
132         wizard model.
133         """
134 
135         if self.cnt == 0:
136             self.topic = self._get_new_topic()
137             self.acts = [None, None]
138             self.human_first = random.choice([0, 1])
139 
140         # possibly get human act first
141         if self.cnt == 0 and not self.human_first:
142             self.acts[0] = act = Message({'text': '', 'episode_done': False})
143             act = self.acts[0]
144         else:
145             self.acts[0] = self.human_agent.act()
146             act = deepcopy(self.acts[0])
147 
148         # model agent observe
149         if self.cnt == 0 and self.topic != NO_TOPIC:
150             # add the chosen_topic to the message
151             act['chosen_topic'] = self.topic
152             act.force_set('text', '\n'.join([self.topic, act.get('text', 'hi')]))
153 
154         # add knowledge to the model observation
155         act = self._add_knowledge_to_act(act)
156 
157         # model observes knowledge and human (apprentice) act
158         self.model_agent.observe(validate(act))
159 
160         # model agent act
161         self.acts[1] = self.model_agent.act()
162 
163         # add the model reply to the knowledge retriever's dialogue history
164         self.knowledge_agent.observe(self.acts[1], actor_id='wizard')
165 
166         # human (apprentice) agent observes model act
167         self.human_agent.observe(validate(self.acts[1]))
168 
169         self.update_counters()
170         self.cnt += 1
171 
172         if self.episode_done():
173             print('[ CHAT DONE ]')
174             print('\n[ Preparing new chat... ]\n')
175             self.cnt = 0
176             self.model_agent.reset()
177 
178 
179 class InteractiveGeneratorWorld(InteractiveWorld):
180     """
181     Interactive world for generative models.
182 
183     Specifically a world for models trained on the task `-t wizard_of_wikipedia
184     generator`.
185     """
186 
187     def __init__(self, opt, agents, shared=None):
188         super().__init__(opt, agents, shared)
189         print('[ loading topics.. ]')
190         self.opt = opt
191         self._load_topics(opt)
192         self.num_topics = opt['num_topics']
193         self.cnt = 0
194         self.human_agent = self.agents[0]
195         self.model_agent = self.agents[1]
196 
197         self._set_up_knowledge_agent(add_token_knowledge=True)
198 
199     def _add_knowledge_to_act(self, act):
200         act = super()._add_knowledge_to_act(act)
201         if self.opt.get('prepend_gold_knowledge', False):
202             warn_once(
203                 'Prepending selected knowledge to dialogue input.'
204                 'If this was not intended behavior, please run with the '
205                 'flag --prepend-gold-knowledge False'
206             )
207             knowledge_text = ' '.join(
208                 [TOKEN_KNOWLEDGE, act['checked_sentence'], TOKEN_END_KNOWLEDGE]
209             )
210             new_text = '\n'.join([knowledge_text, act['text']])
211             act.force_set('text', new_text)
212         else:
213             warn_once(
214                 'Not prepending selected knowledge to dialogue input.'
215                 'If this was not intended behavior, please run with the '
216                 'flag --prepend-gold-knowledge True'
217             )
218         return act
219 
220 
221 class SelfChatWorld(SelfChatBaseWorld):
222     def init_contexts(self, shared=None):
223         print('[ loading topics.. ]')
224         # Load possible chosen topics
225         topics_path = os.path.join(
226             self.opt['datapath'], 'wizard_of_wikipedia', 'topic_splits.json'
227         )
228         # Get training set topics
229         datatype = self.opt['datatype'].split(':')[0]
230         self.topic_list = json.load(open(topics_path, 'rb'))[datatype]
231 
232     def get_contexts(self):
233         random.seed()
234         topic = random.choice(self.topic_list)
235         return [topic, topic]
236
```
--- 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/parlai/tasks/wizard_of_wikipedia/worlds.py b/parlai/tasks/wizard_of_wikipedia/worlds.py
--- a/parlai/tasks/wizard_of_wikipedia/worlds.py
+++ b/parlai/tasks/wizard_of_wikipedia/worlds.py
@@ -18,6 +18,8 @@
 from parlai.tasks.self_chat.worlds import SelfChatWorld as SelfChatBaseWorld
 from parlai.utils.misc import warn_once
 
+from .build import build
+
 from projects.wizard_of_wikipedia.knowledge_retriever.knowledge_retriever import (
     KnowledgeRetrieverAgent,
 )
@@ -74,6 +76,7 @@
 
     def _load_topics(self, opt):
         # Load possible chosen topics
+        build(opt)
         topics_path = os.path.join(
             opt['datapath'], 'wizard_of_wikipedia', 'topic_splits.json'
         )

{"golden_diff": "diff --git a/parlai/tasks/wizard_of_wikipedia/worlds.py b/parlai/tasks/wizard_of_wikipedia/worlds.py\n--- a/parlai/tasks/wizard_of_wikipedia/worlds.py\n+++ b/parlai/tasks/wizard_of_wikipedia/worlds.py\n@@ -18,6 +18,8 @@\n from parlai.tasks.self_chat.worlds import SelfChatWorld as SelfChatBaseWorld\n from parlai.utils.misc import warn_once\n \n+from .build import build\n+\n from projects.wizard_of_wikipedia.knowledge_retriever.knowledge_retriever import (\n     KnowledgeRetrieverAgent,\n )\n@@ -74,6 +76,7 @@\n \n     def _load_topics(self, opt):\n         # Load possible chosen topics\n+        build(opt)\n         topics_path = os.path.join(\n             opt['datapath'], 'wizard_of_wikipedia', 'topic_splits.json'\n         )\n", "issue": "FileNotFoundError when running WoW in interactive\n**Bug description**\r\nI am running the following command: `parlai interactive -mf models:wizard_of_wikipedia/end2end_generator/model -t wizard_of_wikipedia`. At the step when \"loading topics\" there is a missing file error: `FileNotFoundError: [Errno 2] No such file or directory: '/mnt/disks/disk-huge/melody/parlai/data/wizard_of_wikipedia/topic_splits.json'`\r\n\r\n**Reproduction steps**\r\nRun `parlai interactive -mf models:wizard_of_wikipedia/end2end_generator/model -t wizard_of_wikipedia`\r\n\r\n**Expected behavior**\r\nThe file is automatically downloaded, topics are loaded and the interactive session begins.\r\n\r\n**Logs**\r\nPlease paste the command line output:\r\n\r\n```\r\n14:49:06 | creating task(s): wizard_of_wikipedia\r\n[ loading topics.. ]\r\nTraceback (most recent call last):\r\n  File \"/home/melody/anaconda3/envs/parlai/bin/parlai\", line 33, in <module>\r\n    sys.exit(load_entry_point('parlai', 'console_scripts', 'parlai')())\r\n  File \"/mnt/disks/disk-huge/melody/parlai/parlai/core/script.py\", line 272, in superscript_main\r\n    SCRIPT_REGISTRY[cmd].klass._run_from_parser_and_opt(opt, parser)\r\n  File \"/mnt/disks/disk-huge/melody/parlai/parlai/core/script.py\", line 88, in _run_from_parser_and_opt\r\n    return script.run()\r\n  File \"/mnt/disks/disk-huge/melody/parlai/parlai/scripts/interactive.py\", line 117, in run\r\n    return interactive(self.opt)\r\n  File \"/mnt/disks/disk-huge/melody/parlai/parlai/scripts/interactive.py\", line 88, in interactive\r\n    world = create_task(opt, [human_agent, agent])\r\n  File \"/mnt/disks/disk-huge/melody/parlai/parlai/core/worlds.py\", line 1262, in create_task\r\n    world = create_task_world(opt, user_agents, default_world=default_world)\r\n  File \"/mnt/disks/disk-huge/melody/parlai/parlai/core/worlds.py\", line 1235, in create_task_world\r\n    return world_class(opt, task_agents + user_agents)\r\n  File \"/mnt/disks/disk-huge/melody/parlai/parlai/tasks/wizard_of_wikipedia/worlds.py\", line 53, in __init__\r\n    self._load_topics(opt)\r\n  File \"/mnt/disks/disk-huge/melody/parlai/parlai/tasks/wizard_of_wikipedia/worlds.py\", line 82, in _load_topics\r\n    self.topic_list = json.load(open(topics_path, 'rb'))[datatype]\r\nFileNotFoundError: [Errno 2] No such file or directory: '/mnt/disks/disk-huge/melody/parlai/data/wizard_of_wikipedia/topic_splits.json'\r\n```\r\n\r\n**Additional context**\r\nAdd any other context about the problem here. (like proxy settings, network setup, overall goals, etc.)\r\n\n", "before_files": [{"content": "#!/usr/bin/env python3\n\n# Copyright (c) Facebook, Inc. and its affiliates.\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nfrom copy import deepcopy\nimport json\nimport random\nimport os\nimport string\n\n\nfrom parlai.core.agents import create_agent\nfrom parlai.core.message import Message\nfrom parlai.core.worlds import DialogPartnerWorld, validate\nfrom parlai.tasks.wizard_of_wikipedia.agents import TOKEN_KNOWLEDGE, TOKEN_END_KNOWLEDGE\nfrom parlai.tasks.self_chat.worlds import SelfChatWorld as SelfChatBaseWorld\nfrom parlai.utils.misc import warn_once\n\nfrom projects.wizard_of_wikipedia.knowledge_retriever.knowledge_retriever import (\n    KnowledgeRetrieverAgent,\n)\n\n\nNO_TOPIC = '[NO TOPIC]'\n\n\nclass InteractiveWorld(DialogPartnerWorld):\n    \"\"\"\n    Interactive world for wizard of wikipedia.\n\n    Used for models trained on the task `-t wizard_of_wikipedia`. Automatically\n    retrieves knowledge from Wikipedia based on the conversation history using a TF-IDF\n    retriever. Then uses a Transformer-based model to select a checked sentence from\n    these retrieved passages.\n    \"\"\"\n\n    @staticmethod\n    def add_cmdline_args(argparser):\n        parser = argparser.add_argument_group('WoW Interactive World Args')\n        parser.add_argument(\n            '--print-checked-sentence',\n            type='bool',\n            default=True,\n            help='Print sentence that the model checks.',\n        )\n\n    def __init__(self, opt, agents, shared=None):\n        super().__init__(opt, agents, shared)\n        print('[ loading topics.. ]')\n        self.opt = opt\n        self._load_topics(opt)\n        self.num_topics = opt['num_topics']\n        self.cnt = 0\n        self.human_agent = self.agents[0]\n        self.model_agent = self.agents[1]\n\n        self._set_up_knowledge_agent(opt.get('add_token_knowledge', False))\n\n        self.print_checked_sentence = opt['print_checked_sentence']\n\n    def _set_up_knowledge_agent(self, add_token_knowledge=False):\n        from parlai.core.params import ParlaiParser\n\n        parser = ParlaiParser(False, False)\n        KnowledgeRetrieverAgent.add_cmdline_args(parser)\n        parser.set_params(\n            model='projects:wizard_of_wikipedia:knowledge_retriever',\n            add_token_knowledge=add_token_knowledge,\n        )\n        knowledge_opt = parser.parse_args([])\n        self.knowledge_agent = create_agent(knowledge_opt)\n\n    def _load_topics(self, opt):\n        # Load possible chosen topics\n        topics_path = os.path.join(\n            opt['datapath'], 'wizard_of_wikipedia', 'topic_splits.json'\n        )\n        # Get training set topics\n        datatype = opt['datatype'].split(':')[0]\n        self.topic_list = json.load(open(topics_path, 'rb'))[datatype]\n\n    def _get_new_topic(self):\n        random.seed()\n        topics = random.sample(self.topic_list, self.num_topics - 1)\n        topics.append(NO_TOPIC)\n        letters = list(string.ascii_uppercase)[: self.num_topics]\n        topic_list = {x: y for x, y in zip(letters, topics)}\n        topic_text = '\\n'.join(['{}: {}'.format(k, v) for k, v in topic_list.items()])\n\n        done = False\n        while not done:\n            self.human_agent.observe(\n                {\n                    'text': '\\nPlease choose one of the following topics by typing '\n                    'A, B, C, ..., etc. : \\n\\n{}\\n'.format(topic_text)\n                }\n            )\n            topic_act = self.human_agent.act()\n            choice = topic_act['text'][0].upper()\n            if choice in topic_list:\n                done = True\n            else:\n                self.human_agent.observe(\n                    {'text': 'Invalid response, please try again.'}\n                )\n\n        chosen_topic = topic_list[choice]\n        print('[ Your chosen topic is: {} ]'.format(chosen_topic))\n        return chosen_topic\n\n    def _add_knowledge_to_act(self, act):\n        self.knowledge_agent.observe(act, actor_id='apprentice')\n        knowledge_act = self.knowledge_agent.act()\n        act['knowledge'] = knowledge_act['text']\n        act['checked_sentence'] = knowledge_act['checked_sentence']\n        if self.print_checked_sentence:\n            print(\n                '[ Using chosen sentence from Wikpedia ]: {}'.format(\n                    knowledge_act['checked_sentence']\n                )\n            )\n        act['title'] = knowledge_act['title']\n        return act\n\n    def parley(self):\n        \"\"\"\n        Loop between wizard and apprentice.\n\n        Adds knowledge to the wizard observations. Assumes that the model agent is the\n        wizard model.\n        \"\"\"\n\n        if self.cnt == 0:\n            self.topic = self._get_new_topic()\n            self.acts = [None, None]\n            self.human_first = random.choice([0, 1])\n\n        # possibly get human act first\n        if self.cnt == 0 and not self.human_first:\n            self.acts[0] = act = Message({'text': '', 'episode_done': False})\n            act = self.acts[0]\n        else:\n            self.acts[0] = self.human_agent.act()\n            act = deepcopy(self.acts[0])\n\n        # model agent observe\n        if self.cnt == 0 and self.topic != NO_TOPIC:\n            # add the chosen_topic to the message\n            act['chosen_topic'] = self.topic\n            act.force_set('text', '\\n'.join([self.topic, act.get('text', 'hi')]))\n\n        # add knowledge to the model observation\n        act = self._add_knowledge_to_act(act)\n\n        # model observes knowledge and human (apprentice) act\n        self.model_agent.observe(validate(act))\n\n        # model agent act\n        self.acts[1] = self.model_agent.act()\n\n        # add the model reply to the knowledge retriever's dialogue history\n        self.knowledge_agent.observe(self.acts[1], actor_id='wizard')\n\n        # human (apprentice) agent observes model act\n        self.human_agent.observe(validate(self.acts[1]))\n\n        self.update_counters()\n        self.cnt += 1\n\n        if self.episode_done():\n            print('[ CHAT DONE ]')\n            print('\\n[ Preparing new chat... ]\\n')\n            self.cnt = 0\n            self.model_agent.reset()\n\n\nclass InteractiveGeneratorWorld(InteractiveWorld):\n    \"\"\"\n    Interactive world for generative models.\n\n    Specifically a world for models trained on the task `-t wizard_of_wikipedia\n    generator`.\n    \"\"\"\n\n    def __init__(self, opt, agents, shared=None):\n        super().__init__(opt, agents, shared)\n        print('[ loading topics.. ]')\n        self.opt = opt\n        self._load_topics(opt)\n        self.num_topics = opt['num_topics']\n        self.cnt = 0\n        self.human_agent = self.agents[0]\n        self.model_agent = self.agents[1]\n\n        self._set_up_knowledge_agent(add_token_knowledge=True)\n\n    def _add_knowledge_to_act(self, act):\n        act = super()._add_knowledge_to_act(act)\n        if self.opt.get('prepend_gold_knowledge', False):\n            warn_once(\n                'Prepending selected knowledge to dialogue input.'\n                'If this was not intended behavior, please run with the '\n                'flag --prepend-gold-knowledge False'\n            )\n            knowledge_text = ' '.join(\n                [TOKEN_KNOWLEDGE, act['checked_sentence'], TOKEN_END_KNOWLEDGE]\n            )\n            new_text = '\\n'.join([knowledge_text, act['text']])\n            act.force_set('text', new_text)\n        else:\n            warn_once(\n                'Not prepending selected knowledge to dialogue input.'\n                'If this was not intended behavior, please run with the '\n                'flag --prepend-gold-knowledge True'\n            )\n        return act\n\n\nclass SelfChatWorld(SelfChatBaseWorld):\n    def init_contexts(self, shared=None):\n        print('[ loading topics.. ]')\n        # Load possible chosen topics\n        topics_path = os.path.join(\n            self.opt['datapath'], 'wizard_of_wikipedia', 'topic_splits.json'\n        )\n        # Get training set topics\n        datatype = self.opt['datatype'].split(':')[0]\n        self.topic_list = json.load(open(topics_path, 'rb'))[datatype]\n\n    def get_contexts(self):\n        random.seed()\n        topic = random.choice(self.topic_list)\n        return [topic, topic]\n", "path": "parlai/tasks/wizard_of_wikipedia/worlds.py"}], "after_files": [{"content": "#!/usr/bin/env python3\n\n# Copyright (c) Facebook, Inc. and its affiliates.\n# This source code is licensed under the MIT license found in the\n# LICENSE file in the root directory of this source tree.\n\nfrom copy import deepcopy\nimport json\nimport random\nimport os\nimport string\n\n\nfrom parlai.core.agents import create_agent\nfrom parlai.core.message import Message\nfrom parlai.core.worlds import DialogPartnerWorld, validate\nfrom parlai.tasks.wizard_of_wikipedia.agents import TOKEN_KNOWLEDGE, TOKEN_END_KNOWLEDGE\nfrom parlai.tasks.self_chat.worlds import SelfChatWorld as SelfChatBaseWorld\nfrom parlai.utils.misc import warn_once\n\nfrom .build import build\n\nfrom projects.wizard_of_wikipedia.knowledge_retriever.knowledge_retriever import (\n    KnowledgeRetrieverAgent,\n)\n\n\nNO_TOPIC = '[NO TOPIC]'\n\n\nclass InteractiveWorld(DialogPartnerWorld):\n    \"\"\"\n    Interactive world for wizard of wikipedia.\n\n    Used for models trained on the task `-t wizard_of_wikipedia`. Automatically\n    retrieves knowledge from Wikipedia based on the conversation history using a TF-IDF\n    retriever. Then uses a Transformer-based model to select a checked sentence from\n    these retrieved passages.\n    \"\"\"\n\n    @staticmethod\n    def add_cmdline_args(argparser):\n        parser = argparser.add_argument_group('WoW Interactive World Args')\n        parser.add_argument(\n            '--print-checked-sentence',\n            type='bool',\n            default=True,\n            help='Print sentence that the model checks.',\n        )\n\n    def __init__(self, opt, agents, shared=None):\n        super().__init__(opt, agents, shared)\n        print('[ loading topics.. ]')\n        self.opt = opt\n        self._load_topics(opt)\n        self.num_topics = opt['num_topics']\n        self.cnt = 0\n        self.human_agent = self.agents[0]\n        self.model_agent = self.agents[1]\n\n        self._set_up_knowledge_agent(opt.get('add_token_knowledge', False))\n\n        self.print_checked_sentence = opt['print_checked_sentence']\n\n    def _set_up_knowledge_agent(self, add_token_knowledge=False):\n        from parlai.core.params import ParlaiParser\n\n        parser = ParlaiParser(False, False)\n        KnowledgeRetrieverAgent.add_cmdline_args(parser)\n        parser.set_params(\n            model='projects:wizard_of_wikipedia:knowledge_retriever',\n            add_token_knowledge=add_token_knowledge,\n        )\n        knowledge_opt = parser.parse_args([])\n        self.knowledge_agent = create_agent(knowledge_opt)\n\n    def _load_topics(self, opt):\n        # Load possible chosen topics\n        build(opt)\n        topics_path = os.path.join(\n            opt['datapath'], 'wizard_of_wikipedia', 'topic_splits.json'\n        )\n        # Get training set topics\n        datatype = opt['datatype'].split(':')[0]\n        self.topic_list = json.load(open(topics_path, 'rb'))[datatype]\n\n    def _get_new_topic(self):\n        random.seed()\n        topics = random.sample(self.topic_list, self.num_topics - 1)\n        topics.append(NO_TOPIC)\n        letters = list(string.ascii_uppercase)[: self.num_topics]\n        topic_list = {x: y for x, y in zip(letters, topics)}\n        topic_text = '\\n'.join(['{}: {}'.format(k, v) for k, v in topic_list.items()])\n\n        done = False\n        while not done:\n            self.human_agent.observe(\n                {\n                    'text': '\\nPlease choose one of the following topics by typing '\n                    'A, B, C, ..., etc. : \\n\\n{}\\n'.format(topic_text)\n                }\n            )\n            topic_act = self.human_agent.act()\n            choice = topic_act['text'][0].upper()\n            if choice in topic_list:\n                done = True\n            else:\n                self.human_agent.observe(\n                    {'text': 'Invalid response, please try again.'}\n                )\n\n        chosen_topic = topic_list[choice]\n        print('[ Your chosen topic is: {} ]'.format(chosen_topic))\n        return chosen_topic\n\n    def _add_knowledge_to_act(self, act):\n        self.knowledge_agent.observe(act, actor_id='apprentice')\n        knowledge_act = self.knowledge_agent.act()\n        act['knowledge'] = knowledge_act['text']\n        act['checked_sentence'] = knowledge_act['checked_sentence']\n        if self.print_checked_sentence:\n            print(\n                '[ Using chosen sentence from Wikpedia ]: {}'.format(\n                    knowledge_act['checked_sentence']\n                )\n            )\n        act['title'] = knowledge_act['title']\n        return act\n\n    def parley(self):\n        \"\"\"\n        Loop between wizard and apprentice.\n\n        Adds knowledge to the wizard observations. Assumes that the model agent is the\n        wizard model.\n        \"\"\"\n\n        if self.cnt == 0:\n            self.topic = self._get_new_topic()\n            self.acts = [None, None]\n            self.human_first = random.choice([0, 1])\n\n        # possibly get human act first\n        if self.cnt == 0 and not self.human_first:\n            self.acts[0] = act = Message({'text': '', 'episode_done': False})\n            act = self.acts[0]\n        else:\n            self.acts[0] = self.human_agent.act()\n            act = deepcopy(self.acts[0])\n\n        # model agent observe\n        if self.cnt == 0 and self.topic != NO_TOPIC:\n            # add the chosen_topic to the message\n            act['chosen_topic'] = self.topic\n            act.force_set('text', '\\n'.join([self.topic, act.get('text', 'hi')]))\n\n        # add knowledge to the model observation\n        act = self._add_knowledge_to_act(act)\n\n        # model observes knowledge and human (apprentice) act\n        self.model_agent.observe(validate(act))\n\n        # model agent act\n        self.acts[1] = self.model_agent.act()\n\n        # add the model reply to the knowledge retriever's dialogue history\n        self.knowledge_agent.observe(self.acts[1], actor_id='wizard')\n\n        # human (apprentice) agent observes model act\n        self.human_agent.observe(validate(self.acts[1]))\n\n        self.update_counters()\n        self.cnt += 1\n\n        if self.episode_done():\n            print('[ CHAT DONE ]')\n            print('\\n[ Preparing new chat... ]\\n')\n            self.cnt = 0\n            self.model_agent.reset()\n\n\nclass InteractiveGeneratorWorld(InteractiveWorld):\n    \"\"\"\n    Interactive world for generative models.\n\n    Specifically a world for models trained on the task `-t wizard_of_wikipedia\n    generator`.\n    \"\"\"\n\n    def __init__(self, opt, agents, shared=None):\n        super().__init__(opt, agents, shared)\n        print('[ loading topics.. ]')\n        self.opt = opt\n        self._load_topics(opt)\n        self.num_topics = opt['num_topics']\n        self.cnt = 0\n        self.human_agent = self.agents[0]\n        self.model_agent = self.agents[1]\n\n        self._set_up_knowledge_agent(add_token_knowledge=True)\n\n    def _add_knowledge_to_act(self, act):\n        act = super()._add_knowledge_to_act(act)\n        if self.opt.get('prepend_gold_knowledge', False):\n            warn_once(\n                'Prepending selected knowledge to dialogue input.'\n                'If this was not intended behavior, please run with the '\n                'flag --prepend-gold-knowledge False'\n            )\n            knowledge_text = ' '.join(\n                [TOKEN_KNOWLEDGE, act['checked_sentence'], TOKEN_END_KNOWLEDGE]\n            )\n            new_text = '\\n'.join([knowledge_text, act['text']])\n            act.force_set('text', new_text)\n        else:\n            warn_once(\n                'Not prepending selected knowledge to dialogue input.'\n                'If this was not intended behavior, please run with the '\n                'flag --prepend-gold-knowledge True'\n            )\n        return act\n\n\nclass SelfChatWorld(SelfChatBaseWorld):\n    def init_contexts(self, shared=None):\n        print('[ loading topics.. ]')\n        # Load possible chosen topics\n        topics_path = os.path.join(\n            self.opt['datapath'], 'wizard_of_wikipedia', 'topic_splits.json'\n        )\n        # Get training set topics\n        datatype = self.opt['datatype'].split(':')[0]\n        self.topic_list = json.load(open(topics_path, 'rb'))[datatype]\n\n    def get_contexts(self):\n        random.seed()\n        topic = random.choice(self.topic_list)\n        return [topic, topic]\n", "path": "parlai/tasks/wizard_of_wikipedia/worlds.py"}]}