You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When cls_pooling is "mean" or "max", document embeddings fail to be created.
After digging into the codes, I think the issue is: return result is missing in the functions document_mean_pooling and document_max_pooling.
To Reproduce
fromflair.embeddingsimportTransformerDocumentEmbeddingsfromflair.dataimportSentenceembeddings=TransformerDocumentEmbeddings(
model="xlm-roberta-base",
layers="-1",
cls_pooling="mean",
allow_long_sentences=True
)
sentence=Sentence("Today is a good day")
embeddings.embed(sentence)
Expected behavior
Document embeddings using mean pooling are created for the sentence.
Logs and Stack traces
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[4], line 11
4 embeddings = TransformerDocumentEmbeddings(
5 model="xlm-roberta-base",
6 layers="-1",
7 cls_pooling="max",
8 allow_long_sentences=True
9 )
10 sentence = Sentence("Today is a good day")
---> 11 embeddings.embed(sentence)
File /pyzr/active_venv/lib/python3.12/site-packages/flair/embeddings/base.py:50, in Embeddings.embed(self, data_points)
47 data_points = [data_points]
49 if not self._everything_embedded(data_points):
---> 50 self._add_embeddings_internal(data_points)
52 return data_points
File /pyzr/active_venv/lib/python3.12/site-packages/flair/embeddings/transformer.py:709, in TransformerBaseEmbeddings._add_embeddings_internal(self, sentences)
707 if self.document_embedding:
708 document_embedding = embeddings["document_embeddings"]
--> 709 self.__extract_document_embeddings(document_embedding, sentences)
711 if self.token_embedding:
712 token_embedding = embeddings["token_embeddings"]
File /pyzr/active_venv/lib/python3.12/site-packages/flair/embeddings/transformer.py:693, in TransformerBaseEmbeddings.__extract_document_embeddings(self, sentence_hidden_states, sentences)
692 def __extract_document_embeddings(self, sentence_hidden_states, sentences):
--> 693 for document_emb, sentence in zip(sentence_hidden_states, sentences):
694 sentence.set_embedding(self.name, document_emb)
TypeError: 'NoneType' object is not iterable
Screenshots
No response
Additional Context
No response
Environment
Versions:
Flair
0.14.0
Pytorch
2.4.1+cu121
Transformers
4.45.1
GPU
False
The text was updated successfully, but these errors were encountered:
Describe the bug
When
cls_pooling
is"mean"
or"max"
, document embeddings fail to be created.After digging into the codes, I think the issue is:
return result
is missing in the functions document_mean_pooling and document_max_pooling.To Reproduce
Expected behavior
Document embeddings using mean pooling are created for the sentence.
Logs and Stack traces
Screenshots
No response
Additional Context
No response
Environment
Versions:
Flair
0.14.0
Pytorch
2.4.1+cu121
Transformers
4.45.1
GPU
False
The text was updated successfully, but these errors were encountered: