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
The right_context and left_context functions of the Sentence are used to calculate the context for all our best models. However, the behavior of the context expansion is inconsistent due to two bugs.
To Reproduce
fromflair.dataimportSentence# make a sentence without contextsentence=Sentence("Luke and Leia destroyed the Death Star.")
print(sentence)
# print right context: There is none - CORRECT!print(sentence.right_context(4))
# now make a second sentence and set it as contextother_sentence=Sentence("The Death Star then exploded.")
Sentence.set_context_for_sentences([sentence, other_sentence])
# print(sentence.next_sentence()) # verify that next sentence is correctly set (it is: CORRECT)# now print right context. Even though context is set, right_context returns '[]': ERROR!print(sentence.right_context(4))
# now calculate right context for some other random sentenceSentence("Why am I here?").right_context(4)
# print right context again. Now suddenly, the correct context is returned. (ERROR because inconsistent behavior)print(sentence.right_context(4))
@lru_cache(maxsize=1) # cache last context, as training repeats calls
). This is because I assumed that caching is computed here per-instance. But it turns out that caching is computed globally, even though the method is part of Sentence. This is why computing the right_context for some random sentence as in the snippet above results in a different context being computed: The original cache is already lost. -> to fix, set much higher cache size here
The main error is likely a problem with the equality definition of Sentence. Equality is considered only using features of the sentence itself, not its context. This is why setting a context belately and then calling right_context again gives the same result as before -> to fix this, the quality definition of Sentence needs to be changed
Environment
Python 3.8, master branch
The text was updated successfully, but these errors were encountered:
Describe the bug
The
right_context
andleft_context
functions of theSentence
are used to calculate the context for all our best models. However, the behavior of the context expansion is inconsistent due to two bugs.To Reproduce
Expected behaivor
The correct context should always be returned.
Additional Context
There are likely two reasons for this:
lru_cache
ofright_context
to 1 (flair/flair/data.py
Line 830 in 857337d
Sentence
. This is why computing the right_context for some random sentence as in the snippet above results in a different context being computed: The original cache is already lost. -> to fix, set much higher cache size hereSentence
. Equality is considered only using features of the sentence itself, not its context. This is why setting a context belately and then callingright_context
again gives the same result as before -> to fix this, the quality definition ofSentence
needs to be changedEnvironment
Python 3.8, master branch
The text was updated successfully, but these errors were encountered: