Flair: Issue with cache root

Created on 13 Apr 2021  路  3Comments  路  Source: flairNLP/flair

Describe the bug
A clear and concise description of what the bug is.

It seems the cache root is wrong if it is defined in the environment instead of the default

To Reproduce
Steps to reproduce the behavior (e.g. which model did you train? what parameters did you use? etc.).

Create test.py:

from flair.data import Sentence
from flair.models import SequenceTagger

# make a sentence
sentence = Sentence('I love Berlin .')

# load the NER tagger
tagger = SequenceTagger.load('ner')

# run NER over sentence
tagger.predict(sentence)

and run
FLAIR_CACHE_ROOT=$HOME/.cache/ python test.py

Expected behavior
A clear and concise description of what you expected to happen.

Example should work out of th box

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS [e.g. iOS, Linux]: ubuntu
  • Version [e.g. flair-0.3.2]: 0.8.1 (or master)

Additional context
Add any other context about the problem here.

Simple fix is to cast to Path too when coming from env.

bug

All 3 comments

I also looked into this and can reproduce the bug. In this context I searched every occurrence of flair.cache_root, which holds the env value. And every time it is used to construct a Path object.

What I therefore would propose is to initially construct the Path object in the flair/__init__.py and remove every other construction of it in the source code.

Otherwise only a Path construction in flair/models/sequence_tagger.py has to be added.

I could do a PR for both.

Note: There are 237 occurrences of Path(flair.cache_root)

@HallerPatrick thanks for looking into this - a PR would be great! I guess it would be easier to construct it once in the init.

This can be closed :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stefan-it picture stefan-it  路  3Comments

ChessMateK picture ChessMateK  路  3Comments

jewl123 picture jewl123  路  3Comments

happypanda5 picture happypanda5  路  3Comments

mittalsuraj18 picture mittalsuraj18  路  3Comments