Spaces:
Sleeping
Sleeping
explicit config modification
Browse files- tasks/text.py +27 -18
tasks/text.py
CHANGED
@@ -62,24 +62,38 @@ async def evaluate_text(request: TextEvaluationRequest):
|
|
62 |
model_name = "Tonic/climate-guard-toxic-agent"
|
63 |
tokenizer_name = "answerdotai/ModernBERT-base"
|
64 |
|
65 |
-
#
|
66 |
config = AutoConfig.from_pretrained(model_name)
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
# Load tokenizer
|
80 |
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
|
81 |
|
82 |
-
# Load model with
|
83 |
model = AutoModelForSequenceClassification.from_pretrained(
|
84 |
model_name,
|
85 |
config=config,
|
@@ -124,14 +138,9 @@ async def evaluate_text(request: TextEvaluationRequest):
|
|
124 |
predictions = []
|
125 |
with torch.no_grad():
|
126 |
for batch in test_loader:
|
127 |
-
# Move batch to device
|
128 |
batch = {k: v.to(device) for k, v in batch.items()}
|
129 |
-
|
130 |
-
# Get model outputs
|
131 |
outputs = model(**batch)
|
132 |
preds = torch.argmax(outputs.logits, dim=-1)
|
133 |
-
|
134 |
-
# Add batch predictions to list
|
135 |
predictions.extend(preds.cpu().numpy().tolist())
|
136 |
|
137 |
# Clean up GPU memory
|
|
|
62 |
model_name = "Tonic/climate-guard-toxic-agent"
|
63 |
tokenizer_name = "answerdotai/ModernBERT-base"
|
64 |
|
65 |
+
# Load base config
|
66 |
config = AutoConfig.from_pretrained(model_name)
|
67 |
+
|
68 |
+
# Remove problematic bias configurations
|
69 |
+
config_dict = config.to_dict()
|
70 |
+
bias_keys = ['attention_bias', 'classifier_bias', 'decoder_bias', 'mlp_bias', 'norm_bias']
|
71 |
+
for key in bias_keys:
|
72 |
+
if key in config_dict:
|
73 |
+
del config_dict[key]
|
74 |
+
|
75 |
+
# Set essential configurations
|
76 |
+
config_dict.update({
|
77 |
+
"architectures": ["ModernBertForSequenceClassification"],
|
78 |
+
"model_type": "modernbert",
|
79 |
+
"num_labels": 8,
|
80 |
+
"problem_type": "single_label_classification",
|
81 |
+
"hidden_size": 768,
|
82 |
+
"num_attention_heads": 12,
|
83 |
+
"num_hidden_layers": 22,
|
84 |
+
"intermediate_size": 1152,
|
85 |
+
"max_position_embeddings": 8192,
|
86 |
+
"layer_norm_eps": 1e-05,
|
87 |
+
"classifier_dropout": 0.0
|
88 |
+
})
|
89 |
+
|
90 |
+
# Create new config from cleaned dict
|
91 |
+
config = AutoConfig.from_dict(config_dict)
|
92 |
|
93 |
# Load tokenizer
|
94 |
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
|
95 |
|
96 |
+
# Load model with cleaned config
|
97 |
model = AutoModelForSequenceClassification.from_pretrained(
|
98 |
model_name,
|
99 |
config=config,
|
|
|
138 |
predictions = []
|
139 |
with torch.no_grad():
|
140 |
for batch in test_loader:
|
|
|
141 |
batch = {k: v.to(device) for k, v in batch.items()}
|
|
|
|
|
142 |
outputs = model(**batch)
|
143 |
preds = torch.argmax(outputs.logits, dim=-1)
|
|
|
|
|
144 |
predictions.extend(preds.cpu().numpy().tolist())
|
145 |
|
146 |
# Clean up GPU memory
|