Prgrmmer commited on
Commit
d899566
·
verified ·
1 Parent(s): 640f88e

predict.py: skip content-free input (empty/zero-width/emoji) to prevent unrelated tags on empty input

Browse files
Files changed (1) hide show
  1. predict.py +3 -1
predict.py CHANGED
@@ -27,7 +27,9 @@ def load():
27
 
28
 
29
  def predict(text, thresh=CONCEPT_THRESHOLD, model=None):
30
- tok, enc, head, mlb, names = model or load() # ponytail: reloads per call; pass model= in a loop
 
 
31
  b = tok(text, truncation=True, max_length=2048, return_tensors="pt")
32
  with torch.no_grad():
33
  h = enc(**b).last_hidden_state
 
27
 
28
 
29
  def predict(text, thresh=CONCEPT_THRESHOLD, model=None):
30
+ if not any(c.isalnum() for c in text): # no letters/digits in any script: only special tokens would
31
+ return [] # be pooled, which yields hundreds of spurious tags. Skip it.
32
+ tok, enc, head, mlb, names = model or load() # reloads per call; pass model= in a loop
33
  b = tok(text, truncation=True, max_length=2048, return_tensors="pt")
34
  with torch.no_grad():
35
  h = enc(**b).last_hidden_state