Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

[RareF1] Check for null inputs #3592

Merged
merged 2 commits into from
Apr 14, 2021
Merged
Changes from all commits
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
15 changes: 9 additions & 6 deletions parlai/tasks/wizard_of_wikipedia/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""

from __future__ import annotations
from typing import List, Optional, Tuple
from typing import Iterable, Optional, Tuple
from parlai.core.message import Message
from parlai.core.metrics import AverageMetric, normalize_answer, F1Metric
from parlai.core.params import ParlaiParser
Expand Down Expand Up @@ -141,7 +141,9 @@ def _filter(freq_dist, cutoff: int, text: str) -> str:
words = normalize_answer(text).split()
return " ".join([w for w in words if freq_dist.get(w, cutoff) < cutoff])

def compute(self, guess: str, answers: List[str]) -> F1Metric:
def compute(self, guess: str, answers: Iterable[str]) -> F1Metric:
if guess is None or answers is None:
return F1Metric(0, 0)
guess = RareWordF1Calculator._filter(self._freq_dist, self._cutoff_count, guess)
answers = [
RareWordF1Calculator._filter(self._freq_dist, self._cutoff_count, a)
Expand Down Expand Up @@ -462,10 +464,11 @@ def custom_evaluation(
model_response['text'], [teacher_action['checked_sentence']]
),
)
self.metrics.add(
'rare_word_f1',
self.rare_word_f1.compute(model_response['text'], labels),
)
if labels:
self.metrics.add(
'rare_word_f1',
self.rare_word_f1.compute(model_response['text'], labels),
)
elif (
self.label_type == 'chosen_sent'
and TOKEN_KNOWLEDGE in model_response['text']
Expand Down