Jelajahi Sumber

bugfix: ValueError when prediction list is empty

Summary: in `FastText.py` the line `probs, labels = zip(*predictions)` assumes `predictions` will not empty. When `predictions` is empty, we get a ValueError.

Reviewed By: EdouardGrave

Differential Revision: D17626446

fbshipit-source-id: 80885617d87b284e6cadabb6f85d6f4ce3070e65
Onur Çelebi 6 tahun lalu
induk
melakukan
2936e07ac2
1 mengubah file dengan 4 tambahan dan 1 penghapusan
  1. 4 1
      python/fasttext_module/fasttext/FastText.py

+ 4 - 1
python/fasttext_module/fasttext/FastText.py

@@ -159,7 +159,10 @@ class _FastText(object):
         else:
             text = check(text)
             predictions = self.f.predict(text, k, threshold, on_unicode_error)
-            probs, labels = zip(*predictions)
+            if predictions:
+                probs, labels = zip(*predictions)
+            else:
+                probs, labels = ([], ())
 
             return labels, np.array(probs, copy=False)