Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions applications/Chat/evaluate/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def distinct_score(preds: List[str], language: str) -> Dict[str, float]:
count_segs = len(pred_seg_list)
unique_segs = set(pred_seg_list)
count_unique_chars = len(unique_segs)

cumulative_distinct.append(count_unique_chars / count_segs)
# prevent denominator from being 0
cumulative_distinct.append(count_unique_chars / (count_segs + 1e-6))
Comment thread
MichelleMa8 marked this conversation as resolved.
elif language == "en":
# calculate distinct 1-gram, 2-gram, 3-gram
unique_ngram = [set() for _ in range(0, 3)]
Expand Down
3 changes: 2 additions & 1 deletion applications/Chat/evaluate/unieval/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def evaluate(self, data, category, dims=None, overall=True):
start_idx = 0
score = []
for cur_n_sent in n_sents:
score.append(sum(sent_score[start_idx:start_idx + cur_n_sent]) / cur_n_sent)
# prevent denominator from being 0
score.append(sum(sent_score[start_idx:start_idx + cur_n_sent]) / (cur_n_sent + 1e-6))
start_idx += cur_n_sent

# Calculate summary-level score for 'coherence' and 'relevance'
Expand Down
13 changes: 1 addition & 12 deletions applications/Chat/evaluate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ def get_data_per_category(data, categories):
return data_per_category


def remove_articles(text: str) -> str:
"""
Remove articles "a, an, the" in the given text.
It is used in evaluation of automatic metrics.

"""

pattern = re.compile(r"\b(a|an|the)\b", re.UNICODE)
return re.sub(pattern, " ", text)


Comment thread
MichelleMa8 marked this conversation as resolved.
def remove_punctuations(text: str) -> str:
"""
Remove punctuations in the given text.
Expand Down Expand Up @@ -121,7 +110,7 @@ def preprocessing_text(text: str) -> str:

"""

return remove_redundant_space(remove_articles(remove_punctuations(text.lower())))
return remove_redundant_space(remove_punctuations(text.lower()))


def save_automatic_results(model_name: str, automatic_metric_stats: Dict[str, Dict], save_path: str) -> None:
Expand Down