Flair: AttributeError when use regressor.predict()

Created on 4 Jan 2021  路  10Comments  路  Source: flairNLP/flair

Hi,

I am getting this error when calling the predict function in regressor.

AttributeError Traceback (most recent call last)
in
----> 1 regressor.predict(corpus.test[0:3])

~/anaconda3/envs/torch/lib/python3.8/site-packages/flair/models/text_regression_model.py in predict(self, sentences, mini_batch_size, embedding_storage_mode)
67
68 for (sentence, score) in zip(batch, scores.tolist()):
---> 69 sentence.labels = [Label(value=str(score[0]))]
70
71 # clearing token embeddings to save memory

AttributeError: can't set attribute

referring to
https://github.com/flairNLP/flair/blob/4aa77cbc62720a8f0e5a595ab264f82aaaad10dc/flair/models/text_regression_model.py#L69

Should it be sentence.set_labels() here?

Thanks

Most helpful comment

Should be fixed now! If you install directly from master, you can test.
~
pip install --upgrade git+https://github.com/flairNLP/flair.git
~

All 10 comments

Hi,
I received the exact same error.
@heukirne Any insights here?
Thanks

@aditya-malte , I help this project a long time ago, can't remeber this error.
Do you have the Traceback?

The traceback is exactly the same as the one mentioned by the author of this issue
`AttributeError Traceback (most recent call last)
in
----> 1 regressor.predict(corpus.test[0:3])

~/anaconda3/envs/torch/lib/python3.8/site-packages/flair/models/text_regression_model.py in predict(self, sentences, mini_batch_size, embedding_storage_mode)
67
68 for (sentence, score) in zip(batch, scores.tolist()):
---> 69 sentence.labels = [Label(value=str(score[0]))]
70
71 # clearing token embeddings to save memory

AttributeError: can't set attribute`

Also tried the solution suggested earlier in this thread by @cpuyyp . I think the issue might be that the sentence object is immutable. Trying an alternate approach where a new object gets created.

We're running in to the same issue; feel free to keep us posted @aditya-malte

Sure :)

Have you tried to run your code similarly to the regression tests?
https://github.com/flairNLP/flair/blob/master/tests/test_text_regressor.py

Yes you're right, its an error in the way the labels are set. I'll put in a PR to fix this!

Should be fixed now! If you install directly from master, you can test.
~
pip install --upgrade git+https://github.com/flairNLP/flair.git
~

Great! The problem appears to be solved now. Thanks for such a quick resolution.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prematurelyoptimized picture prematurelyoptimized  路  3Comments

mittalsuraj18 picture mittalsuraj18  路  3Comments

jewl123 picture jewl123  路  3Comments

ciaochiaociao picture ciaochiaociao  路  3Comments

Aditya715 picture Aditya715  路  3Comments