Spaces:
Running
Running
Commit
·
7d2277b
1
Parent(s):
fac8a97
Update
Browse files
app.py
CHANGED
|
@@ -93,16 +93,9 @@ def predict_ner(sentence: str, model, tokenizer, id2label: dict, device="cpu", m
|
|
| 93 |
enc = {k: v.to(device) for k, v in enc.items()}
|
| 94 |
|
| 95 |
with torch.no_grad():
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
except TypeError:
|
| 100 |
-
# fallback for your custom BertSeqTagger-like model
|
| 101 |
-
h = model.transformer(**enc).last_hidden_state
|
| 102 |
-
if hasattr(model, "dropout"):
|
| 103 |
-
h = model.dropout(h)
|
| 104 |
-
logits = model.classification_head(h)
|
| 105 |
-
|
| 106 |
pred_ids = logits.argmax(dim=-1)[0].tolist()
|
| 107 |
|
| 108 |
word_ids = enc["input_ids"].new_zeros(enc["input_ids"].shape[1]).tolist()
|
|
|
|
| 93 |
enc = {k: v.to(device) for k, v in enc.items()}
|
| 94 |
|
| 95 |
with torch.no_grad():
|
| 96 |
+
out = model(**enc)
|
| 97 |
+
logits = out.logits if hasattr(out, "logits") else out
|
| 98 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
pred_ids = logits.argmax(dim=-1)[0].tolist()
|
| 100 |
|
| 101 |
word_ids = enc["input_ids"].new_zeros(enc["input_ids"].shape[1]).tolist()
|