0

This question is about the NLP Python module Flair (https://github.com/flairNLP/flair).

The default download folder for models is in the flair cache (~/.flair). However, working on a server I would prefer this download to take place in another location, as the /home directory is really small. Here is a minimal working example.

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')

You can thus see that there is no space left on device with the following error: (...) OSError: [Errno 28] No space left on device: '~/.flair/models/ner-english/tmp8js3y34i' (...)

Orysza
  • 574
  • 1
  • 5
  • 10

2 Answers2

1

Posting an answer in case someone comes here and is stuck as I was.

from pathlib import Path
import flair
#flair.cache_root = "/your/path/.flair" # DOES NOT WORK
flair.cache_root = Path("/your/path/.flair")# WORKS
Orysza
  • 574
  • 1
  • 5
  • 10
0

You can set the environment variable FLAIR_CACHE_ROOT. Found by looking at the root init.py file.

In some older versions of FlairNLP, this will not work. os.getenv function should be pass into Path:

cache_root = Path(os.getenv('FLAIR_CACHE_ROOT', Path(Path.home(), ".flair")))
Jonathan
  • 4,847
  • 3
  • 32
  • 37