Skip to content
Browse files uses open(file_path) where file_path is a URL (#2654)

Running the tutorial from the command line will cause a `FileNotFoundError`, so I added `cached_path`.
  • Loading branch information...
bpshaver authored and DeNeutoy committed Mar 28, 2019
1 parent 263d340 commit 6e1ee2e1b7d958a93e2444b2a5293ae094fe6d41
Showing with 3 additions and 2 deletions.
  1. +3 −2 tutorials/tagger/
@@ -9,6 +9,7 @@

from allennlp.commands.train import train_model
from allennlp.common.params import Params
from allennlp.common.file_utils import cached_path
from import Instance
from import DatasetReader
from import TextField, SequenceLabelField
@@ -42,7 +43,7 @@ def text_to_instance(self, tokens: List[Token], tags: List[str] = None) -> Insta
return Instance(fields)

def _read(self, file_path: str) -> Iterator[Instance]:
with open(file_path) as f:
with open(cached_file(file_path) as f:
for line in f:
pairs = line.strip().split()
sentence, tags = zip(*(pair.split("###") for pair in pairs))
@@ -82,7 +83,7 @@ def get_metrics(self, reset: bool = False) -> Dict[str, float]:
return {"accuracy": self.accuracy.get_metric(reset)}

# In practice you'd probably do this from the command line:
# $ allennlp train tutorials/tagger/experiment.jsonnet -s /tmp/serialization_dir
# $ allennlp train tutorials/tagger/experiment.jsonnet -s /tmp/serialization_dir --include-package tutorials.tagger.config_allennlp
if __name__ == "__main__":
params = Params.from_file('tutorials/tagger/experiment.jsonnet')

2 comments on commit 6e1ee2e


This comment has been minimized.

Copy link

replied Mar 28, 2019

Missed a closing paren


This comment has been minimized.

Copy link

replied Mar 28, 2019

Thanks @eaubin! #2661

Please sign in to comment.
You can’t perform that action at this time.