Upload iab_classifier.py with huggingface_hub
Browse files- iab_classifier.py +5 -3
iab_classifier.py
CHANGED
|
@@ -5,11 +5,11 @@ from functools import lru_cache
|
|
| 5 |
import torch
|
| 6 |
|
| 7 |
try:
|
| 8 |
-
from .config import IAB_PARENT_FALLBACK_CONFIDENCE_FLOOR # type: ignore
|
| 9 |
from .iab_taxonomy import get_iab_taxonomy, parse_path_label, path_to_label # type: ignore
|
| 10 |
from .model_runtime import get_head # type: ignore
|
| 11 |
except ImportError:
|
| 12 |
-
from config import IAB_PARENT_FALLBACK_CONFIDENCE_FLOOR
|
| 13 |
from iab_taxonomy import get_iab_taxonomy, parse_path_label, path_to_label
|
| 14 |
from model_runtime import get_head
|
| 15 |
|
|
@@ -82,7 +82,9 @@ def predict_iab_content_classifier_batch(
|
|
| 82 |
return []
|
| 83 |
|
| 84 |
head = get_head("iab_content")
|
| 85 |
-
if
|
|
|
|
|
|
|
| 86 |
return [None for _ in texts]
|
| 87 |
|
| 88 |
raw_probs, calibrated_probs = head.predict_probs_batch(texts)
|
|
|
|
| 5 |
import torch
|
| 6 |
|
| 7 |
try:
|
| 8 |
+
from .config import IAB_PARENT_FALLBACK_CONFIDENCE_FLOOR, _looks_like_local_hf_model_dir # type: ignore
|
| 9 |
from .iab_taxonomy import get_iab_taxonomy, parse_path_label, path_to_label # type: ignore
|
| 10 |
from .model_runtime import get_head # type: ignore
|
| 11 |
except ImportError:
|
| 12 |
+
from config import IAB_PARENT_FALLBACK_CONFIDENCE_FLOOR, _looks_like_local_hf_model_dir
|
| 13 |
from iab_taxonomy import get_iab_taxonomy, parse_path_label, path_to_label
|
| 14 |
from model_runtime import get_head
|
| 15 |
|
|
|
|
| 82 |
return []
|
| 83 |
|
| 84 |
head = get_head("iab_content")
|
| 85 |
+
# `SequenceClassifierHead` will raise if the folder exists but is incomplete
|
| 86 |
+
# (missing `model.safetensors` / `pytorch_model.bin`). Treat that as "no model".
|
| 87 |
+
if not _looks_like_local_hf_model_dir(head.config.model_dir):
|
| 88 |
return [None for _ in texts]
|
| 89 |
|
| 90 |
raw_probs, calibrated_probs = head.predict_probs_batch(texts)
|