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

Add switch to QA pred head for ranking by confidence scores #836

Merged
merged 3 commits into from
Aug 18, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add switch to QA pred head for ranking by confidence scores
  • Loading branch information
julian-risch committed Aug 17, 2021
commit 5aa94e69afeea0d2f20f90ac99b044e8cfc42a62
4 changes: 3 additions & 1 deletion farm/modeling/prediction_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ def __init__(self, layer_dims=[768,2],
n_best_per_sample=None,
duplicate_filtering=-1,
temperature_for_confidence=1.0,
use_confidence_scores_for_ranking=False,
**kwargs):
"""
:param layer_dims: dimensions of Feed Forward block, e.g. [768,2], for adjusting to BERT embedding. Output should be always 2
Expand Down Expand Up @@ -988,6 +989,7 @@ def __init__(self, layer_dims=[768,2],
self.duplicate_filtering = duplicate_filtering
self.generate_config()
self.temperature_for_confidence = nn.Parameter(torch.ones(1) * temperature_for_confidence)
self.use_confidence_scores_for_ranking = use_confidence_scores_for_ranking


@classmethod
Expand Down Expand Up @@ -1472,7 +1474,7 @@ def reduce_preds(self, preds):

# Add no answer to positive answers, sort the order and return the n_best
n_preds = [no_answer_pred] + pos_answer_dedup
n_preds_sorted = sorted(n_preds, key=lambda x: x.score, reverse=True)
n_preds_sorted = sorted(n_preds, key=lambda x: x.confidence if self.use_confidence_scores_for_ranking else x.score, reverse=True)
n_preds_reduced = n_preds_sorted[:self.n_best]
return n_preds_reduced, no_ans_gap

Expand Down