jefftherover commited on
Commit
9ffa6ae
Β·
verified Β·
1 Parent(s): 0eb9532

Fix: explicit huggingface_hub.login() + hub_token in TrainingArguments

Browse files
Files changed (1) hide show
  1. train_ner_pii_newlabel.py +11 -0
train_ner_pii_newlabel.py CHANGED
@@ -22,9 +22,11 @@ rather than silently dropped.
22
  Run with: uv run train_ner_pii.py
23
  """
24
 
 
25
  import json
26
  import numpy as np
27
  import trackio
 
28
  from datasets import load_dataset
29
  from transformers import (
30
  AutoTokenizer,
@@ -36,6 +38,14 @@ from transformers import (
36
  )
37
  import evaluate
38
 
 
 
 
 
 
 
 
 
39
  # ── Training label map: 56 source types β†’ 17 training categories ─────────────
40
  # At inference, LABEL_MAP_INFER collapses these to 11 policy categories.
41
  LABEL_MAP_TRAIN = {
@@ -275,6 +285,7 @@ args = TrainingArguments(
275
  push_to_hub=True,
276
  hub_model_id=HUB_MODEL_ID,
277
  hub_private_repo=False,
 
278
  hub_strategy="every_save",
279
  report_to="trackio",
280
  run_name="modernbert-pii-mapped-v5",
 
22
  Run with: uv run train_ner_pii.py
23
  """
24
 
25
+ import os
26
  import json
27
  import numpy as np
28
  import trackio
29
+ from huggingface_hub import login
30
  from datasets import load_dataset
31
  from transformers import (
32
  AutoTokenizer,
 
38
  )
39
  import evaluate
40
 
41
+ # Authenticate using the HF_TOKEN secret injected by HF Jobs
42
+ _token = os.environ.get("HF_TOKEN")
43
+ if _token:
44
+ login(token=_token)
45
+ print("Logged in to Hugging Face Hub.")
46
+ else:
47
+ print("WARNING: HF_TOKEN not found in environment β€” hub push will fail.")
48
+
49
  # ── Training label map: 56 source types β†’ 17 training categories ─────────────
50
  # At inference, LABEL_MAP_INFER collapses these to 11 policy categories.
51
  LABEL_MAP_TRAIN = {
 
285
  push_to_hub=True,
286
  hub_model_id=HUB_MODEL_ID,
287
  hub_private_repo=False,
288
+ hub_token=os.environ.get("HF_TOKEN"),
289
  hub_strategy="every_save",
290
  report_to="trackio",
291
  run_name="modernbert-pii-mapped-v5",