GaetanoParente commited on
Commit
76955f7
Β·
1 Parent(s): 03a98ed

aggiunto recupero modello bert da HF hub

Browse files
.gitignore CHANGED
@@ -1 +1 @@
1
- __pycache__/data/model/bpo_bert_model/*.safetensors
 
1
+ __pycache__/
README.md CHANGED
@@ -77,8 +77,6 @@ ngt-ai-platform/
77
  β”œβ”€β”€ modules/ # Logica di business
78
  └── data/
79
  β”œβ”€β”€ model/ # CARTELLA MODELLI (Non versionata)
80
- β”‚ β”œβ”€β”€ bpo_bert_model/ # Cartella del modello BERT addestrato
81
- β”‚ └── ... # modelli addestrati da noi
82
  β”œβ”€β”€ gallery/ # Immagini di esempio per la Demo
83
  └── tokenizer/ # tokenizer per la BinaryClassification e MultiClassification
84
 
 
77
  β”œβ”€β”€ modules/ # Logica di business
78
  └── data/
79
  β”œβ”€β”€ model/ # CARTELLA MODELLI (Non versionata)
 
 
80
  β”œβ”€β”€ gallery/ # Immagini di esempio per la Demo
81
  └── tokenizer/ # tokenizer per la BinaryClassification e MultiClassification
82
 
data/model/bpo_bert_model/config.json DELETED
@@ -1,39 +0,0 @@
1
- {
2
- "activation": "gelu",
3
- "architectures": [
4
- "DistilBertForSequenceClassification"
5
- ],
6
- "attention_dropout": 0.1,
7
- "bos_token_id": null,
8
- "dim": 768,
9
- "dropout": 0.1,
10
- "dtype": "float32",
11
- "eos_token_id": null,
12
- "hidden_dim": 3072,
13
- "id2label": {
14
- "0": "LABEL_0",
15
- "1": "LABEL_1",
16
- "2": "LABEL_2"
17
- },
18
- "initializer_range": 0.02,
19
- "label2id": {
20
- "LABEL_0": 0,
21
- "LABEL_1": 1,
22
- "LABEL_2": 2
23
- },
24
- "max_position_embeddings": 512,
25
- "model_type": "distilbert",
26
- "n_heads": 12,
27
- "n_layers": 6,
28
- "output_past": true,
29
- "pad_token_id": 0,
30
- "problem_type": "single_label_classification",
31
- "qa_dropout": 0.1,
32
- "seq_classif_dropout": 0.2,
33
- "sinusoidal_pos_embds": false,
34
- "tie_weights_": true,
35
- "tie_word_embeddings": true,
36
- "transformers_version": "5.0.0",
37
- "use_cache": false,
38
- "vocab_size": 119547
39
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
data/model/bpo_bert_model/tokenizer.json DELETED
The diff for this file is too large to render. See raw diff
 
data/model/bpo_bert_model/tokenizer_config.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "backend": "tokenizers",
3
- "cls_token": "[CLS]",
4
- "do_lower_case": false,
5
- "is_local": false,
6
- "mask_token": "[MASK]",
7
- "model_max_length": 512,
8
- "pad_token": "[PAD]",
9
- "sep_token": "[SEP]",
10
- "strip_accents": null,
11
- "tokenize_chinese_chars": true,
12
- "tokenizer_class": "DistilBertTokenizer",
13
- "unk_token": "[UNK]"
14
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
modules/bpo_dispatcher.py CHANGED
@@ -17,23 +17,29 @@ LABELS_MAP = {
17
  2: "Retention / Churn Risk"
18
  }
19
 
 
 
20
  class BPODispatcher:
21
- def __init__(self, model_path="data/model/bpo_bert_model"):
22
  self.model = None
23
  self.tokenizer = None
24
  self.nlp = None
25
- self.device = "cpu"
26
 
27
- # 1. BERT
28
- if os.path.exists(model_path):
29
- try:
30
- self.tokenizer = DistilBertTokenizerFast.from_pretrained(model_path)
31
- self.model = DistilBertForSequenceClassification.from_pretrained(model_path)
32
- self.model.to(self.device)
33
- self.model.eval()
34
- print("βœ… Modello BERT caricato.")
35
- except Exception as e:
36
- print(f"❌ Errore BERT: {e}")
 
 
 
 
37
 
38
  # 2. spaCy
39
  try:
 
17
  2: "Retention / Churn Risk"
18
  }
19
 
20
+ MODEL_REPO_ID = "NextGenTech/bpo-bert-model"
21
+
22
  class BPODispatcher:
23
+ def __init__(self, model_id=MODEL_REPO_ID):
24
  self.model = None
25
  self.tokenizer = None
26
  self.nlp = None
27
+ self.device = "cpu" # In uno Space CPU basic, usa "cuda" solo se hai GPU
28
 
29
+ # 1. BERT (Caricamento da Hugging Face Hub)
30
+ print(f"πŸ”„ Tentativo di caricamento modello da: {model_id}...")
31
+ try:
32
+ # token=True usa automaticamente il Secret 'HF_TOKEN' dello Space
33
+ self.tokenizer = DistilBertTokenizerFast.from_pretrained(model_id, token=True)
34
+ self.model = DistilBertForSequenceClassification.from_pretrained(model_id, token=True)
35
+ self.model.to(self.device)
36
+ self.model.eval()
37
+ print("βœ… Modello BERT scaricato e caricato con successo.")
38
+ except OSError as e:
39
+ print(f"❌ Errore: Impossibile scaricare il modello. Verifica il Token e il Repo ID.")
40
+ print(f"Dettagli: {e}")
41
+ except Exception as e:
42
+ print(f"❌ Errore generico BERT: {e}")
43
 
44
  # 2. spaCy
45
  try: