Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- explainability.py +10 -2
explainability.py
CHANGED
|
@@ -148,9 +148,17 @@ class ExplainabilityEngine:
|
|
| 148 |
last_hidden_state = vision_outputs.last_hidden_state
|
| 149 |
|
| 150 |
# Text Features (Prompts, Dim)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
text_outputs = self.model.text_model(
|
| 152 |
-
input_ids=
|
| 153 |
-
attention_mask=
|
| 154 |
)
|
| 155 |
text_embeds = text_outputs.pooler_output
|
| 156 |
text_embeds = text_embeds / text_embeds.norm(p=2, dim=-1, keepdim=True)
|
|
|
|
| 148 |
last_hidden_state = vision_outputs.last_hidden_state
|
| 149 |
|
| 150 |
# Text Features (Prompts, Dim)
|
| 151 |
+
# Text Features (Prompts, Dim)
|
| 152 |
+
# FIX: Robustly handle attention_mask (some processors don't return it for text-only inputs if irrelevant)
|
| 153 |
+
text_inputs_ids = inputs["input_ids"]
|
| 154 |
+
text_attention_mask = inputs.get("attention_mask")
|
| 155 |
+
|
| 156 |
+
if text_attention_mask is None:
|
| 157 |
+
text_attention_mask = torch.ones_like(text_inputs_ids)
|
| 158 |
+
|
| 159 |
text_outputs = self.model.text_model(
|
| 160 |
+
input_ids=text_inputs_ids,
|
| 161 |
+
attention_mask=text_attention_mask
|
| 162 |
)
|
| 163 |
text_embeds = text_outputs.pooler_output
|
| 164 |
text_embeds = text_embeds / text_embeds.norm(p=2, dim=-1, keepdim=True)
|