Skip to content

A programming framework for agentic AI

trying to fix the indexerror for ner (#596)

Xueqing Liu7740cd346645
diff --git a/flaml/ml.py b/flaml/ml.py
index 81301db88..8e5e2df6d 100644
--- a/flaml/ml.py
+++ b/flaml/ml.py
@@ -176,12 +176,16 @@ def metric_loss_score(
].mid.fmeasure
elif metric_name.startswith("seqeval"):
+ label_len = len(labels)
zip_pred_true = [
[(p, lb) for (p, lb) in zip(prediction, label) if lb != -100]
for (prediction, label) in zip(y_predict, y_true)
]
y_pred = [
- [labels[p] for (p, l) in each_list]
+ [
+ labels[p] if 0 <= p < label_len else -1
+ for (p, l) in each_list
+ ]
for each_list in zip_pred_true
] # To compute precision and recall, y_pred and y_true must be converted to string labels
# (B-PER, I-PER, etc.), so that the category-based precision/recall (i.e., PER, LOC, etc.) scores can be computed