AbeBhatti commited on
Commit
d51f1a3
Β·
1 Parent(s): b0b4c78

HF Hub fallback for bluff classifier

Browse files
Files changed (2) hide show
  1. agent/bluff_detector.py +17 -4
  2. session_progress.md +28 -0
agent/bluff_detector.py CHANGED
@@ -14,6 +14,8 @@ from dataclasses import dataclass
14
  from pathlib import Path
15
  from typing import Any, Dict, List, Mapping, Optional, Sequence
16
 
 
 
17
  # Lazy-loaded learned classifier (only on first use)
18
  _bluff_classifier_model = None
19
  _bluff_classifier_tokenizer = None
@@ -33,15 +35,26 @@ def _get_bluff_classifier():
33
  elif default_pt.exists():
34
  pt_path = default_pt
35
  else:
36
- return None, None
 
 
 
 
 
 
 
 
 
37
 
38
  tok_dir = checkpoints_dir / "bluff_classifier_tokenizer"
39
- if not tok_dir.exists():
40
- return None, None
41
  try:
42
  import torch
43
  from transformers import AutoTokenizer, AutoModel
44
- _bluff_classifier_tokenizer = AutoTokenizer.from_pretrained(str(tok_dir))
 
 
 
 
45
 
46
  class _BluffClassifierModule(torch.nn.Module):
47
  def __init__(self):
 
14
  from pathlib import Path
15
  from typing import Any, Dict, List, Mapping, Optional, Sequence
16
 
17
+ from huggingface_hub import hf_hub_download
18
+
19
  # Lazy-loaded learned classifier (only on first use)
20
  _bluff_classifier_model = None
21
  _bluff_classifier_tokenizer = None
 
35
  elif default_pt.exists():
36
  pt_path = default_pt
37
  else:
38
+ # HF Hub fallback: try to download negotiation checkpoint from the Spaces repo.
39
+ try:
40
+ downloaded = hf_hub_download(
41
+ repo_id="Abeee32t/ArbitrAgent",
42
+ filename="bluff_classifier_negotiation.pt",
43
+ repo_type="space",
44
+ )
45
+ pt_path = Path(downloaded)
46
+ except Exception:
47
+ return None, None
48
 
49
  tok_dir = checkpoints_dir / "bluff_classifier_tokenizer"
 
 
50
  try:
51
  import torch
52
  from transformers import AutoTokenizer, AutoModel
53
+ if tok_dir.exists():
54
+ _bluff_classifier_tokenizer = AutoTokenizer.from_pretrained(str(tok_dir))
55
+ else:
56
+ # Fallback: use base DistilBERT tokenizer when local tokenizer dir is missing.
57
+ _bluff_classifier_tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
58
 
59
  class _BluffClassifierModule(torch.nn.Module):
60
  def __init__(self):
session_progress.md CHANGED
@@ -435,6 +435,34 @@ At the end of your session, append a block in this format:
435
 
436
  ---
437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
  ## Session β€” Negotiation bluff data + classifier wiring β€” March 8, 2026
439
 
440
  **Status:** Complete
 
435
 
436
  ---
437
 
438
+ ## Session β€” HF Hub fallback for bluff classifier β€” March 8, 2026
439
+
440
+ **Status:** Complete
441
+
442
+ ### What Was Built
443
+ - `agent/bluff_detector.py`: Updated `_get_bluff_classifier()` to:
444
+ - Prefer local `training/checkpoints/bluff_classifier_negotiation.pt` and then `training/checkpoints/bluff_classifier.pt` as before.
445
+ - If neither exists locally, fall back to downloading `bluff_classifier_negotiation.pt` from the HF Hub Space `Abeee32t/ArbitrAgent` using `hf_hub_download` and load the checkpoint from that path.
446
+ - When `training/checkpoints/bluff_classifier_tokenizer/` does not exist locally, fall back to `AutoTokenizer.from_pretrained("distilbert-base-uncased")` instead of failing.
447
+
448
+ ### What Was Tested
449
+ - Static inspection of `_get_bluff_classifier()` to confirm the load order (negotiation β†’ default β†’ HF Hub) and that tokenizer loading now has a safe base-model fallback without changing any other detector behavior.
450
+
451
+ ### Decisions Made
452
+ - Centralized the HF Hub fallback inside `_get_bluff_classifier()` so the rest of the agent and env code can remain unchanged while still benefiting from a remote negotiation-trained classifier when local checkpoints are missing.
453
+
454
+ ### Blockers / Known Issues
455
+ - The HF Hub fallback assumes that `Abeee32t/ArbitrAgent` exposes `bluff_classifier_negotiation.pt` in the Space; if that file is missing or the environment lacks network/HF credentials, the detector will gracefully revert to pure rule-based scoring (existing behavior).
456
+
457
+ ### Files Modified
458
+ - `agent/bluff_detector.py`
459
+ - `session_progress.md`
460
+
461
+ ### Next Session Entry Point
462
+ - (Optional) Validate the HF fallback path in a networked environment by removing local bluff classifier checkpoints and confirming that `_get_bluff_classifier()` successfully downloads and loads `bluff_classifier_negotiation.pt` from the Space.
463
+
464
+ ---
465
+
466
  ## Session β€” Negotiation bluff data + classifier wiring β€” March 8, 2026
467
 
468
  **Status:** Complete