Repository: facebookresearch/ParlAI

Issue:
FastText embeddings link forbidden (HTTP Error 403)
Trying to evaluate the pretrained End-to-end generative models of Wizard of Wikipedia fails because the FastText word vectors link has become unavailable.

Exact stack trace:

```
python examples/eval_model.py \
>     -bs 64 -t wizard_of_wikipedia:generator:topic_split \
>     -mf models:wizard_of_wikipedia/end2end_generator/model
/home/ubuntu/ParlAI/parlai/agents/transformer/transformer.py:18: UserWarning: Public release transformer models are currently in beta. The name of command line options may change or disappear before a stable release. We welcome your feedback. Please file feedback as issues at https://github.com/facebookresearch/ParlAI/issues/new
  "Public release transformer models are currently in beta. The name of "
[ warning: overriding opt['task'] to wizard_of_wikipedia:generator:topic_split (previously: wizard_of_wikipedia:generator:random_split )]
[ warning: overriding opt['model_file'] to /home/ubuntu/ParlAI/data/models/wizard_of_wikipedia/end2end_generator/model (previously: /tmp/wizard_endtoend_model )]
Dictionary: loading dictionary from /home/ubuntu/ParlAI/data/models/wizard_of_wikipedia/end2end_generator/model.dict
[ num words =  34883 ]
[ Using CUDA ]
/private/home/roller/working/parlai/data/models/fasttext_vectors/wiki.en.vec: 0.00B [00:00, ?B/s]
Traceback (most recent call last):
  File "examples/eval_model.py", line 17, in <module>
    eval_model(opt, print_parser=parser)
  File "/home/ubuntu/ParlAI/parlai/scripts/eval_model.py", line 68, in eval_model
    agent = create_agent(opt, requireModelExists=True)
  File "/home/ubuntu/ParlAI/parlai/core/agents.py", line 552, in create_agent
    model = load_agent_module(opt)
  File "/home/ubuntu/ParlAI/parlai/core/agents.py", line 429, in load_agent_module
    return model_class(new_opt)
  File "/home/ubuntu/ParlAI/projects/wizard_of_wikipedia/generator/agents.py", line 109, in __init__
    super().__init__(opt, shared)
  File "/home/ubuntu/ParlAI/parlai/core/torch_generator_agent.py", line 356, in __init__
    self.build_model()
  File "/home/ubuntu/ParlAI/projects/wizard_of_wikipedia/generator/agents.py", line 315, in build_model
    self.model.embeddings.weight, self.opt['embedding_type']
  File "/home/ubuntu/ParlAI/parlai/core/torch_agent.py", line 890, in _copy_embeddings
    embs, name = self._get_embtype(emb_type)
  File "/home/ubuntu/ParlAI/parlai/core/torch_agent.py", line 832, in _get_embtype
    'models:fasttext_vectors'))
  File "/home/ubuntu/ParlAI/venv/lib/python3.6/site-packages/torchtext/vocab.py", line 411, in __init__
    super(FastText, self).__init__(name, url=url, **kwargs)
  File "/home/ubuntu/ParlAI/venv/lib/python3.6/site-packages/torchtext/vocab.py", line 280, in __init__
    self.cache(name, cache, url=url, max_vectors=max_vectors)
  File "/home/ubuntu/ParlAI/venv/lib/python3.6/site-packages/torchtext/vocab.py", line 313, in cache
    urlretrieve(url, dest, reporthook=reporthook(t))
  File "/home/ubuntu/anaconda3/lib/python3.6/urllib/request.py", line 248, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
  File "/home/ubuntu/anaconda3/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/home/ubuntu/anaconda3/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/home/ubuntu/anaconda3/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/home/ubuntu/anaconda3/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/home/ubuntu/anaconda3/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/home/ubuntu/anaconda3/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
```
The [torchtext function](https://github.com/pytorch/text/blob/edafd9cb284010043d8aba7d8e57f91aaad77e99/torchtext/vocab.py#L410) tries to download it from the [AWS bucket](https://s3-us-west-1.amazonaws.com/fasttext-vectors/wiki.en.vec). The word vectors are also available at [fbaipublicfiles](https://dl.fbaipublicfiles.com/fasttext/vectors-wiki/wiki.en.vec) but the download speed is extremely slow when downloading to AWS US instance (~100KB/s). The torchtext repo doesn't seem to be maintained at a high clip so I opened the issue here (you reply fast:).


Discussion:
Ahh yes. Please file an issue there too.

In the meantime, you can work around this by adding `-emb random` to that command. You’ll still be able to load the pretrained model.
Although I’m very confused as to why the fbaipublicfiles would be slow to download to AWS instances. It’s backed by AWS
Thanks for the fast reply. [PR ](https://github.com/pytorch/text/pull/521) has been submitted to torchtext.

Resolving patch:
diff --git a/parlai/core/torch_agent.py b/parlai/core/torch_agent.py
--- a/parlai/core/torch_agent.py
+++ b/parlai/core/torch_agent.py
@@ -845,18 +845,12 @@ def _get_embtype(self, emb_type):
                                     'models:glove_vectors'))
         elif emb_type.startswith('fasttext_cc'):
             init = 'fasttext_cc'
-            from parlai.zoo.fasttext_cc_vectors.build import url as fasttext_cc_url
-            embs = vocab.Vectors(
-                name='crawl-300d-2M.vec',
-                url=fasttext_cc_url,
-                cache=modelzoo_path(self.opt.get('datapath'),
-                                    'models:fasttext_cc_vectors'))
+            from parlai.zoo.fasttext_cc_vectors.build import download
+            embs = download(self.opt.get('datapath'))
         elif emb_type.startswith('fasttext'):
             init = 'fasttext'
-            embs = vocab.FastText(
-                language='en',
-                cache=modelzoo_path(self.opt.get('datapath'),
-                                    'models:fasttext_vectors'))
+            from parlai.zoo.fasttext_vectors.build import download
+            embs = download(self.opt.get('datapath'))
         else:
             raise RuntimeError('embedding type {} not implemented. check arg, '
                                'submit PR to this function, or override it.'
diff --git a/parlai/zoo/fasttext_cc_vectors/build.py b/parlai/zoo/fasttext_cc_vectors/build.py
--- a/parlai/zoo/fasttext_cc_vectors/build.py
+++ b/parlai/zoo/fasttext_cc_vectors/build.py
@@ -8,13 +8,14 @@
 """
 
 import torchtext.vocab as vocab
+from parlai.core.build_data import modelzoo_path
 
-url = 'https://s3-us-west-1.amazonaws.com/fasttext-vectors/crawl-300d-2M.vec.zip'
+URL = 'https://dl.fbaipublicfiles.com/fasttext/vectors-english/crawl-300d-2M.vec.zip'
 
 
 def download(datapath):
-    vocab.Vectors(
+    return vocab.Vectors(
         name='crawl-300d-2M.vec',
-        url=url,
-        cache=datapath + '/models/fasttext_cc_vectors'
+        url=URL,
+        cache=modelzoo_path(datapath, 'models:fasttext_cc_vectors'),
     )
diff --git a/parlai/zoo/fasttext_vectors/build.py b/parlai/zoo/fasttext_vectors/build.py
--- a/parlai/zoo/fasttext_vectors/build.py
+++ b/parlai/zoo/fasttext_vectors/build.py
@@ -7,7 +7,14 @@
 """
 
 import torchtext.vocab as vocab
+from parlai.core.build_data import modelzoo_path
+
+URL = 'https://dl.fbaipublicfiles.com/fasttext/vectors-wiki/wiki.en.vec'
 
 
 def download(datapath):
-    vocab.FastText(language='en', cache=datapath + '/models/fasttext_vectors')
+    return vocab.Vectors(
+        name='wiki.en.vec',
+        url=URL,
+        cache=modelzoo_path(datapath, 'models:fasttext_vectors'),
+    )


Test patch: