-
Notifications
You must be signed in to change notification settings - Fork 0
Improve evaluation output by add more info : MaRefactor metrics computation with structured outputso & Micro scores & S… #17
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import warnings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from collections import defaultdict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import Union, List, Literal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import pandas as pd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import numpy as np | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import torch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -24,7 +24,7 @@ def _prf_divide( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result = np.true_divide(numerator, denominator) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result[denominator == 0] = 0.0 if zero_division in ["warn", 0] else 1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if denominator == 0 and zero_division == "warn" and metric in warn_for: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if np.any(denominator == 0) and zero_division == "warn" and metric in warn_for: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| msg_start = f"{metric.title()}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "f-score" in warn_for: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| msg_start += " and F-score" if metric in warn_for else "F-score" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+27
to
30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Rounding in Previously this helper returned raw float/array values and left rounding to the presentation layer. Rounding to 2 decimals here means all downstream uses (including F-score, which already rounds) now operate on truncated values, increasing the risk of compounded rounding errors (e.g., micro scores derived from already-rounded per-class metrics) and reducing reusability for callers that need full precision. It would be safer to return the unrounded Suggested implementation: return resultTo fully follow your suggestion, you will also need to:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -36,7 +36,7 @@ def _prf_divide( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result_size=len(result), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return result | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return np.round(result,decimals=2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _warn_prf(average: str, modifier: str, msg_start: str, result_size: int): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -84,19 +84,44 @@ def flatten_for_eval(y_true, y_pred): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return all_true, all_pred | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def compute_prf(y_true, y_pred, average="micro"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def compute_prf(y_true:List, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| y_pred:List, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| all_metrics = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| y_true, y_pred = flatten_for_eval(y_true, y_pred) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pred_sum, tp_sum, true_sum, target_names = extract_tp_actual_correct(y_true, y_pred) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if average == "micro": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tp_sum = np.array([tp_sum.sum()]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pred_sum = np.array([pred_sum.sum()]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| true_sum = np.array([true_sum.sum()]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Calculate macro metric (divide by classes number) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| per_class_dico,metrics_macro = _calculate_metrics(tp_sum,pred_sum,true_sum,"macro") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| all_metrics["macro"] = metrics_macro | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # # Calculate performance per class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| all_metrics["per_class"] = {target_names[i]:{"precision":per_class_dico["precision"][i], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "recall":per_class_dico["recall"][i], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "f_score":per_class_dico["f_score"][i]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in range(len(target_names)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Calculate micro metric (divide by all sum-up values of all classes ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tp_sum_micro = np.array([tp_sum.sum()]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pred_sum_micro = np.array([pred_sum.sum()]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| true_sum_micro = np.array([true_sum.sum()]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metrics_micro = _calculate_metrics(tp_sum_micro,pred_sum_micro,true_sum_micro,"micro") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| all_metrics["micro"] = metrics_micro | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return all_metrics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _calculate_metrics(tp, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pred, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| average : Literal["micro","macro"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| precision = _prf_divide( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| numerator=tp_sum, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| denominator=pred_sum, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| numerator=tp, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| denominator=pred, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metric="precision", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| modifier="predicted", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+117
to
126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Macro averages are simple means over all classes, which may be skewed by classes with zero support. In the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| average=average, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -105,20 +130,30 @@ def compute_prf(y_true, y_pred, average="micro"): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| recall = _prf_divide( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| numerator=tp_sum, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| denominator=true_sum, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| numerator=tp, # TODO check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| denominator=true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metric="recall", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| modifier="true", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| average=average, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| warn_for=["precision", "recall", "f-score"], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| zero_division="warn", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| denominator = precision + recall | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| denominator[denominator == 0.0] = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f_score = 2 * (precision * recall) / denominator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| denominator_fscore = precision + recall | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| denominator_fscore[denominator_fscore== 0.0] = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f_score = np.round(2 * (precision* recall) / denominator_fscore, decimals=2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if average == "micro" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {"precision": precision[0], "recall": recall[0], "f_score": f_score[0]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| per_class_array = {"precision": precision, "recall": recall, "f_score": f_score} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| macro_precision = np.round(precision.sum()/len(precision),decimals=2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| macro_recall = np.round(recall.sum()/len(recall),decimals=2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| macro_f_score = np.round(f_score.sum()/ len(f_score), decimals=2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+152
to
+154
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These calculations can lead to a
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return per_class_array,{"precision": macro_precision, "recall": macro_recall, "f_score": macro_f_score} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+150
to
+155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle empty label sets to avoid ZeroDivisionError. 🛠️ Suggested guard for empty metrics else :
per_class_array = {"precision": precision, "recall": recall, "f_score": f_score}
- macro_precision = np.round(precision.sum()/len(precision),decimals=2)
- macro_recall = np.round(recall.sum()/len(recall),decimals=2)
- macro_f_score = np.round(f_score.sum()/ len(f_score), decimals=2)
+ if len(precision) == 0:
+ return per_class_array, {"precision": 0.0, "recall": 0.0, "f_score": 0.0}
+ macro_precision = np.round(precision.sum()/len(precision),decimals=2)
+ macro_recall = np.round(recall.sum()/len(recall),decimals=2)
+ macro_f_score = np.round(f_score.sum()/ len(f_score), decimals=2)
return per_class_array,{"precision": macro_precision, "recall": macro_recall, "f_score": macro_f_score}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {"precision": precision[0], "recall": recall[0], "f_score": f_score[0]} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class Evaluator: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -150,10 +185,20 @@ def transform_data(self): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @torch.no_grad() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def evaluate(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| output : { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "per_class":{"tag1":{"precision":int, "recall":int,"f_score":int}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "tag2":{}... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "micro":{"precision":int, "recall":int,"f_score":int}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "macro":{"precision":int, "recall":int,"f_score":int}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+188
to
+197
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docstring incorrectly specifies
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| all_true_typed, all_outs_typed = self.transform_data() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| precision, recall, f1 = compute_prf(all_true_typed, all_outs_typed).values() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| output_str = f"P: {precision:.2%}\tR: {recall:.2%}\tF1: {f1:.2%}\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return output_str, f1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| results_all = compute_prf(all_true_typed, all_outs_typed) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # output_str = f"P: {precision:.2%}\tR: {recall:.2%}\tF1: {f1:.2%}\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return results_all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+188
to
+201
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the docstring to reflect float metrics and dict output. ✏️ Docstring tweak- "per_class":{"tag1":{"precision":int, "recall":int,"f_score":int},
+ "per_class":{"tag1":{"precision":float, "recall":float,"f_score":float},
"tag2":{}...
},
- "micro":{"precision":int, "recall":int,"f_score":int},
- "macro":{"precision":int, "recall":int,"f_score":int},
+ "micro":{"precision":float, "recall":float,"f_score":float},
+ "macro":{"precision":float, "recall":float,"f_score":float},📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def is_nested(idx1, idx2): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||||||
| import re | ||||||||||||||||||||||||||||||||||||||||||||||
| import warnings | ||||||||||||||||||||||||||||||||||||||||||||||
| import pandas as pd | ||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Locate common dependency manifests and check for pandas.
echo "=== Searching for dependency manifests and pandas ==="
files=$(find . -maxdepth 3 -type f \( -name 'requirements*.txt' -o -name 'pyproject.toml' -o -name 'setup.cfg' -o -name 'setup.py' -o -name 'Pipfile' -o -name 'environment.yml' \) 2>/dev/null)
if [ -n "$files" ]; then
echo "Found manifest files:"
echo "$files"
echo ""
echo "=== Checking for pandas in these files ==="
rg -n 'pandas' $files
else
echo "No dependency manifest files found."
fiRepository: arthrod/GLiNER Length of output: 213 🏁 Script executed: #!/bin/bash
# Check the actual import in gliner/model.py and the beautiful_df_print function
echo "=== First 20 lines of gliner/model.py ==="
head -20 gliner/model.py
echo ""
echo "=== Lines 663-676 of gliner/model.py (beautiful_df_print function) ==="
sed -n '663,676p' gliner/model.py
echo ""
echo "=== Check for all imports of pandas in gliner/model.py ==="
rg -n 'import.*pandas\|from.*pandas' gliner/model.pyRepository: arthrod/GLiNER Length of output: 1318 🏁 Script executed: #!/bin/bash
echo "=== pyproject.toml ==="
cat pyproject.toml
echo ""
echo "=== requirements.txt ==="
cat requirements.txtRepository: arthrod/GLiNER Length of output: 1533 Add pandas to dependencies or move the import inside Pandas is imported at module scope (line 5) but not declared in Option: lazy-import inside the method def beautiful_df_print(self, eval_results:Dict):
+ try:
+ import pandas as pd
+ except ModuleNotFoundError as exc:
+ raise ModuleNotFoundError(
+ "pandas is required for beautiful_df_print. Please install it (e.g., pip install pandas)."
+ ) from exc
"""🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| from tqdm import tqdm | ||||||||||||||||||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||||||||||||||||||
| from typing import Dict, List, Optional, Union | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -652,10 +653,42 @@ def evaluate( | |||||||||||||||||||||||||||||||||||||||||||||
| all_trues.extend(batch["entities"]) | ||||||||||||||||||||||||||||||||||||||||||||||
| # Evaluate the predictions | ||||||||||||||||||||||||||||||||||||||||||||||
| evaluator = Evaluator(all_trues, all_preds) | ||||||||||||||||||||||||||||||||||||||||||||||
| out, f1 = evaluator.evaluate() | ||||||||||||||||||||||||||||||||||||||||||||||
| # out, f1 = evaluator.evaluate() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return out, f1 | ||||||||||||||||||||||||||||||||||||||||||||||
| # return out, f1 | ||||||||||||||||||||||||||||||||||||||||||||||
| all_results = evaluator.evaluate() | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return all_results | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+656
to
+661
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update evaluate() docs to match the new return type. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| def beautiful_df_print(self, eval_results:Dict): | ||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||
| eval_results : | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| "per_class":{"tag1":{"precision":int, "recall":int,"f_score":int}, | ||||||||||||||||||||||||||||||||||||||||||||||
| "tag2":{}... | ||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||
| "micro":{"precision":int, "recall":int,"f_score":int}, | ||||||||||||||||||||||||||||||||||||||||||||||
| "macro":{"precision":int, "recall":int,"f_score":int}, | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+664
to
+674
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The docstring indicates that the metric values (
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
| # add mico and macro metrics | ||||||||||||||||||||||||||||||||||||||||||||||
| df_metrics = pd.DataFrame() | ||||||||||||||||||||||||||||||||||||||||||||||
| df_metrics["MICRO_AVG"] = eval_results["micro"] | ||||||||||||||||||||||||||||||||||||||||||||||
| df_metrics["MACRO_AVG"] = eval_results["macro"] | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # add seperator line | ||||||||||||||||||||||||||||||||||||||||||||||
| df_metrics = df_metrics.transpose() | ||||||||||||||||||||||||||||||||||||||||||||||
| df_metrics.loc["-------"]= {'precision': '---', 'recall': '---', 'f_score': '---'} | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # add results per class | ||||||||||||||||||||||||||||||||||||||||||||||
| df_per_class = pd.DataFrame(eval_results["per_class"]) | ||||||||||||||||||||||||||||||||||||||||||||||
| df_per_class = df_per_class.transpose().sort_values(by='f_score',ascending=False) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| df = pd.concat([df_metrics,df_per_class]) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return df | ||||||||||||||||||||||||||||||||||||||||||||||
| def encode_labels(self, labels: List[str], batch_size: int = 8) -> torch.FloatTensor: | ||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||
| Embedding of labels. | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
pandaslibrary is imported here but it is not used within this file. It appears to be used ingliner/model.pyfor thebeautiful_df_printfunction, where it is also correctly imported. To maintain clean code and avoid unnecessary dependencies in this module, this import should be removed.