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

Implement Context Matching #2293

Merged
merged 22 commits into from
Mar 21, 2022
Merged

Implement Context Matching #2293

merged 22 commits into from
Mar 21, 2022

Conversation

tstadel
Copy link
Member

@tstadel tstadel commented Mar 9, 2022

Proposed changes:

  • Implement methods calculate_context_similarity and match_context

Status (please check what you already did):

  • First draft (up for discussions & feedback)
  • Final code
  • Added tests
  • Updated documentation

closes #2265

@tstadel tstadel marked this pull request as ready for review March 15, 2022 20:29
@tstadel
Copy link
Member Author

tstadel commented Mar 15, 2022

Tests to be added...

Copy link
Member

@ArzelaAscoIi ArzelaAscoIi left a comment

Choose a reason for hiding this comment

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

Awesome :) Thanks for also adding match_contexts !

Copy link
Member

@julian-risch julian-risch left a comment

Choose a reason for hiding this comment

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

Looks very good already. Looking forward to some tests. Maybe it's better to rename matching.py to context_matching.py. Otherwise it's too generic. For now utils is fine but I could imagine the code also under modeling/evaluation. Don't forget to add labels to the PR. 😉


:param context: The context to match.
:param candidate: The candidate to match the context.
:param min_words: The minimum number of words context and candidate need to have in order to be scored.
Copy link
Member

Choose a reason for hiding this comment

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

Just wondering whether we want to call this words or tokens. Could also be min_seq_len (minimum number of tokens) in reference to max_seq_len of the reader models.

Copy link
Member Author

Choose a reason for hiding this comment

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

words should be generally better understandable then tokens by most people. Also min_seq_len refers to a sequence of "whatever" because it totally depends on the tokenizer what you're dealing with (words, wordpieces, bytes, etc.). Here we're actually dealing with words. So I'd leave it like that.

@tstadel
Copy link
Member Author

tstadel commented Mar 17, 2022

@julian-risch @ArzelaAscoIi
First version should be complete now:

  • tests added
  • changed min_words into min_length param, so we work on string length now which should be more generic and produce less edge cases than words
  • added boost_split_overlaps param to control whether boosting partial split overlaps resulting from preprocessing should be boosted/matched
  • added non-parallel (num_processes<=1) versions of match_context and match_contexts for easier debugging

Copy link
Member

@ArzelaAscoIi ArzelaAscoIi left a comment

Choose a reason for hiding this comment

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

Quite complex! Looks good! 🚀

Copy link
Member

@julian-risch julian-risch left a comment

Choose a reason for hiding this comment

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

LGTM! 👍 There is just a small typo to be fixed before merging. Further, let's keep an eye on whether boost_split_overlaps increases the number of false positive matches. In that case, we might not want to use by default and set boost_split_overlaps=False by default.

grouped_matches = groupby(group_sorted_matches, key=lambda candidate: candidate.context_id)
for context_id, group in grouped_matches:
sorted_group = sorted(group, key=lambda candidate: candidate.score, reverse=True)
match_list = list((candiate_score.candidate_id, candiate_score.score) for candiate_score in sorted_group)
Copy link
Member

Choose a reason for hiding this comment

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

typo in candiate_score

@tstadel
Copy link
Member Author

tstadel commented Mar 21, 2022

I agree the boost_split_overlaps flag needs further empirical testing. So far it does its job pretty good regarding the tests. So for now, I leave it with default value True.

@tstadel tstadel merged commit e13df4b into master Mar 21, 2022
@tstadel tstadel deleted the context_matching branch March 21, 2022 09:35
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.

Implement Context matching
3 participants