Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the EvaluationStore to match prediction and target entities #6419

Merged

Conversation

davidezanella
Copy link
Contributor

@davidezanella davidezanella commented Aug 14, 2020

Proposed changes:

  • Fix the EvaluationStore serialise method: the prediction and target entities were not aligned. Previously, they were aligned only by adding 'None' at the end of the smaller list instead of looking where they should be placed.

Practical example:

target entities: [
   {'text': 'hi, how are you', 'start': 0, 'end': 2, entity: 'verb' },
   {'text': 'hi, how are you', 'start': 4, 'end': 7, entity: 'noun' }
]
predicted entities: [
   {'text': 'hi, how are you', 'start': 4, 'end': 7, entity: 'noun' }
]

Adding 'None' at the end, as done originally, leads to wrong metrics because even the right prediction was marked as wrong.

Status (please check what you already did):

  • added some tests for the functionality
  • updated the documentation
  • updated the changelog (please check changelog for instructions)
  • reformat files using black (please check Readme for instructions)

@davidezanella davidezanella force-pushed the fix-EvaluationStore-predicted-entities branch from 04cbacd to c052e5b Compare August 14, 2020 21:41
@sara-tagger sara-tagger requested a review from degiz August 17, 2020 06:00
@sara-tagger
Copy link
Collaborator

Thanks for submitting a pull request 🚀 @degiz will take a look at it as soon as possible ✨

@davidezanella
Copy link
Contributor Author

@tabergma can you review this pr?

Copy link
Contributor

@degiz degiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @davidezanella

Thanks a lot for the PR! Could you please also write a unit for the change? I believe you can use existing tests/test_test.py file.

@davidezanella davidezanella requested a review from degiz August 24, 2020 21:31
@tabergma
Copy link
Contributor

@davidezanella Thanks for addressing this. I think your concern is valid and should be fixed, but I am not sure if your method fixes the complete problem. Currently you just iterating over the gold entities to see if there are matching predicted entities and you are adding None in case no matching entity could be found. That way we ensure that the size of the gold end predicted entities is the same. However, i think we also need to consider the case when we have more predicted entities than gold entities. For example, you have a sentence like "Tanja is currently in Munich, but she lives in Berlin" and the annotator made a mistake and just annotate "Tanja" as person, but forgot to tag "Munich" and "Berlin" as city. However, the model predicts all three of them. If I understand your code correctly, you would just consider the gold entity "Tanja" and you would ignore the two additional entities "Munich" and "Berlin", which is not correct as those are false positive predictions in this case. What do you think?

@davidezanella
Copy link
Contributor Author

Hey @tabergma, you are right! I've fixed the code and the tests.
Let me know what do you think about it

@degiz degiz requested review from tabergma and degiz and removed request for degiz August 27, 2020 12:20
Copy link
Contributor

@degiz degiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't seem I can cancel my "changes requested" 😞
@tabergma will review the code.

@tabergma
Copy link
Contributor

tabergma commented Sep 1, 2020

@davidezanella Sorry for the late reply, I was offline a couple of days. Will take a look at the PR today. Can you please resolve the conflicts in the meantime? Thanks.

Copy link
Contributor

@tabergma tabergma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great 🚀 Added a few comments. Can you please also add a changelog entry? Thanks.

rasa/core/test.py Show resolved Hide resolved
rasa/core/test.py Outdated Show resolved Hide resolved
rasa/core/test.py Outdated Show resolved Hide resolved
rasa/core/test.py Outdated Show resolved Hide resolved
rasa/core/test.py Outdated Show resolved Hide resolved
Copy link
Contributor

@tabergma tabergma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great 💯 Thanks for fixing this!

key=lambda x: x.get("start"),
)

i_pred, i_target = 0, 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: We try to not use abbreviations in names. I would rename this to index_prediction and index_target.

i_pred, i_target = 0, 0

while i_pred < len(entity_predictions) or i_target < len(entity_targets):
cmp = self._compare_entities(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: I would rename this to comparison_result.

def _compare_entities(
entity_predictions: List[Dict[Text, Any]],
entity_targets: List[Dict[Text, Any]],
i_pred: int,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Rename to index_prediction.

entity_predictions: List[Dict[Text, Any]],
entity_targets: List[Dict[Text, Any]],
i_pred: int,
i_target: int,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Rename to index_target.

@tabergma
Copy link
Contributor

tabergma commented Sep 2, 2020

@degiz I think you need to update your review otherwise we are not able to merge this PR.

@degiz degiz merged commit be72c78 into RasaHQ:master Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants