MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / inverse_transform

Method inverse_transform

numpy_ml/preprocessing/nlp.py:484–503  ·  view source on GitHub ↗

Transform an encoded sequence of bit-strings back into words. Parameters ---------- codes : list of `N` binary strings A list of encoded bit-strings, represented as strings. Returns ------- text: list of `N` strings T

(self, codes)

Source from the content-addressed store, hash-verified

482 return [self._item2code.get(t, None) for t in text]
483
484 def inverse_transform(self, codes):
485 """
486 Transform an encoded sequence of bit-strings back into words.
487
488 Parameters
489 ----------
490 codes : list of `N` binary strings
491 A list of encoded bit-strings, represented as strings.
492
493 Returns
494 -------
495 text: list of `N` strings
496 The decoded text.
497 """
498 if isinstance(codes, str):
499 codes = [codes]
500 for code in set(codes):
501 if code not in self._code2item:
502 raise Warning("Code '{}' not in Huffman tree. Skipping".format(code))
503 return [self._code2item.get(c, None) for c in codes]
504
505 @property
506 def tokens(self):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected