Your fourth-place embedding winning the full combo is a great example of why picking the best model at each stage can mislead you. Stage metrics measure each piece alone, but the classifier and threshold only see what the embedding hands them.
What tends to work for me is a middle path: use stage-level metrics only to prune the clearly bad options (keep the top few, not the top one), then do a joint search over what's left. With MLflow nested runs that stays readable:
import itertools, mlflow, numpy as np
from sklearn.metrics import f1_score
with mlflow.start_run(run_name="pipeline_search"):
for emb, clf_name in itertools.product(top_embeddings, classifiers):
with mlflow.start_run(run_name=f"{emb}+{clf_name}", nested=True):
X_tr, X_val = embed(emb, train_texts), embed(emb, val_texts)
clf = make_clf(clf_name).fit(X_tr, Y_tr) # e.g. OneVsRest, returns (n, n_labels) probs
probs = clf.predict_proba(X_val)
t, f1 = max(((t, f1_score(Y_val, probs >= t, average="micro"))
for t in np.arange(0.1, 0.9, 0.05)), key=lambda x: x[1])
mlflow.log_params({"embedding": emb, "classifier": clf_name, "threshold": round(t, 2)})
mlflow.log_metric("val_micro_f1", f1)Two things I'd add to your list:
- Tune the threshold per combination on validation data, then report the final number on a separate test split. Otherwise the threshold quietly overfits.
- For the label vocabulary problem, save the exact label order with the model, e.g. mlflow.log_dict({"labels": list(mlb.classes_)}, "labels.json"), or wrap binarizer, classifier and threshold into one pyfunc so inference can't rebuild it differently.