Implementation:Norrrrrrr lyn WAInjectBench joblib dump
| Knowledge Sources | |
|---|---|
| Domains | Machine_Learning, Model_Management |
| Last Updated | 2026-02-14 16:00 GMT |
Overview
Concrete tool for serializing trained LogisticRegression classifiers to .pkl files, provided by the joblib library as used in the WAInjectBench embedding trainers.
Description
Both text and image embedding trainers use joblib.dump(clf, save_path) to persist the fitted classifier. The save path is constructed as {output_dir}/{jsonl_stem}_logreg.pkl. The text variant also optionally saves embeddings to a separate JSONL file (save_emb=True by default).
Usage
Called as the final step of train_single_classifier after fitting the LogisticRegression model.
Code Reference
Source Location
- Repository: WAInjectBench
- File: train/embedding-t.py (L38), train/embedding-i.py (L59-60)
Signature
# Text variant (train/embedding-t.py:L36-38)
model_name = Path(jsonl_file).stem + "_logreg.pkl"
save_path = os.path.join(output_dir, model_name)
joblib.dump(clf, save_path)
# Image variant (train/embedding-i.py:L58-60)
model_name = Path(jsonl_file).stem + "_logreg.pkl"
save_path = os.path.join(output_dir, model_name)
joblib.dump(clf, save_path)
Import
import joblib
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| clf | LogisticRegression | Yes | Fitted classifier object |
| save_path | str | Yes | Output file path ({output_dir}/{stem}_logreg.pkl) |
Outputs
| Name | Type | Description |
|---|---|---|
| .pkl file | File | Serialized classifier at the specified path |
Usage Examples
Saving and Loading a Classifier
import joblib
from sklearn.linear_model import LogisticRegression
# Train classifier
clf = LogisticRegression(max_iter=1000)
clf.fit(embeddings, labels)
# Save
joblib.dump(clf, "models/dataset_logreg.pkl")
# Load for inference
loaded_clf = joblib.load("models/dataset_logreg.pkl")
predictions = loaded_clf.predict(new_embeddings)