from flair.embeddings import FlairEmbeddings, BertEmbeddings
flair_forward_embedding = FlairEmbeddings('multi-forward')
flair_backward_embedding = FlairEmbeddings('multi-backward')
bert_embedding = BertEmbeddings('bert-base-multilingual-cased')
AttributeError Traceback (most recent call last)
2
3 # init Flair embeddings
----> 4 flair_forward_embedding = FlairEmbeddings('multi-forward')
5 flair_backward_embedding = FlairEmbeddings('multi-backward')
6
C:\Anaconda3\lib\site-packages\flair\embeddings.py in __init__(self, model, detach, use_cache, cache_directory)
562 self.static_embeddings = detach
563
--> 564 from flair.models import LanguageModel
565 self.lm = LanguageModel.load_language_model(model)
566 self.detach = detach
C:\Anaconda3\lib\site-packages\flair__init__.py in
1 from . import data
----> 2 from . import models
3 from . import visual
4 from . import trainers
5
C:\Anaconda3\lib\site-packages\flair\models__init__.py in
----> 1 from .sequence_tagger_model import SequenceTagger
2 from .language_model import LanguageModel
3 from .text_classification_model import TextClassifier
C:\Anaconda3\lib\site-packages\flair\models\sequence_tagger_model.py in
64
65
---> 66 class SequenceTagger(flair.nn.Model):
67
68 def __init__(self,
AttributeError: module 'flair' has no attribute 'nn'
Which version of Flair are you using? Did you install through pip or using the master branch?
0.14, Yes Installed through pip
Hm very strange. I just ran this on a fresh Python 3 instance on Google CoLab and everything runs:
!pip install flair
from flair.embeddings import FlairEmbeddings, BertEmbeddings
flair_forward_embedding = FlairEmbeddings('multi-forward')
flair_backward_embedding = FlairEmbeddings('multi-backward')
Perhaps there is an issue with your installation? Could you setting it up in a new virtual environment or a colab instance?
Thanks ! Will try that
Still no luck


Now getting a different error

This typically occurs if the download of the model was interrupted. You can delete the model in the cache directory ~/.flair/models and run it again to trigger another download. Does that work?
It worked. Thanks
Can we please re-open this topic?
@shadylpstan sure, do you have a related problem? Could you share a description of your problem?
@alanakbik exactly the same problem
AttributeError: module 'flair' has no attribute 'nn'
@sp3234 it looks like @shadylpstan is getting the same error you got initially. Could you share what you did to resolve it?
Hello!
I am trying to import some methods from flair, such as "from flair.data import Sentence" and my IPython console "freezes" (actually it happens for any flair import). It never loads, and if I stop the load, the console never gets back and I need to restart it. I am using Spyder 3.3.3 and flair 0.4.2 / Windows 10.
Any idea why it would be happening?
FYI: It was working a few days ago. Then the problem happened once when loading
"from flair.data import Sentence", I tried to load "from flair import data" and it worked, but not anymore.
Hello!
I am trying to import some methods from flair, such as "from flair.data import Sentence" and my IPython console "freezes" (actually it happens for any flair import). It never loads, and if I stop the load, the console never gets back and I need to restart it. I am using Spyder 3.3.3 and flair 0.4.2 / Windows 10.
Any idea why it would be happening?
FYI: It was working a few days ago. Then the problem happened once when loading
"from flair.data import Sentence", I tried to load "from flair import data" and it worked, but not anymore.
Well, it worked as "import flair", still, it would be good to load small parts of it.
Hi,
I could reproduce the same error in a Python 3.7 notebook. Google Colab btw. uses Python 3.6.
I'll re-open the issue now :)
The error occurs, when using the following imports:
import flair
from flair.data import Sentence
However, the error is gone by not using import flair :)
Hm very strange, I'll try to reproduce as well.
I am facing the same issue in Google Colab. No "import flair" but still doesn't work. I have to kill the session to overcome it. Thank you btw for such a beautiful library!
Same here. Getting this error even without import flair.
Got the same error in Windows 10 and python 3.6.7
Resolved through using flair-0.4.3 and numpy-1.16.1
I have something related to this issue...I want to load CamembertEmbeddings.
from flair.embeddings import CamembertEmbeddings
I got the following error
ImportError: cannot import name 'CamembertEmbeddings'
import flair
import flair.embeddings
from flair.embeddings import TransformerDocumentEmbeddings
Traceback (most recent call last):
File "
from flair.embeddings import TransformerDocumentEmbeddings
ImportError: cannot import name 'TransformerDocumentEmbeddings' from 'flair.embeddings' (C:\Program Files\Python37\lib\site-packages\flair\embeddings.py)
@coolsubbu these embeddings were added in Flair 0.5 Do you have the newest version?
@sp3234 it looks like @shadylpstan is getting the same error you got initially. Could you share what you did to resolve it?
I too had a similar error. I was trying to install a forked package from huggingface.
So, what I did was delete all the previously installed packages of huggingface and flair and reinstall them.
It worked as a charm!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Currently also struggling with:
AttributeError: partially initialized module 'flair' has no attribute 'nn' (most likely due to a circular import)
But none of the suggested above worked for me.