Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
config_allennlp.py uses open(file_path) where file_path is a URL (#2654)
Browse files Browse the repository at this point in the history
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 6e1ee2e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tutorials/tagger/config_allennlp.py
Expand Up @@ -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 allennlp.data import Instance
from allennlp.data.dataset_readers import DatasetReader
from allennlp.data.fields import TextField, SequenceLabelField
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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')
Expand Down

2 comments on commit 6e1ee2e

@eaubin
Copy link

@eaubin eaubin commented on 6e1ee2e Mar 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed a closing paren

@matt-gardner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @eaubin! #2661

Please sign in to comment.