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

Method transform

numpy_ml/preprocessing/nlp.py:463–482  ·  view source on GitHub ↗

Transform the words in `text` into their Huffman-code representations. Parameters ---------- text: list of `N` strings The list of words to encode Returns ------- codes : list of `N` binary strings The encoded words i

(self, text)

Source from the content-addressed store, hash-verified

461 self._generate_codes()
462
463 def transform(self, text):
464 """
465 Transform the words in `text` into their Huffman-code representations.
466
467 Parameters
468 ----------
469 text: list of `N` strings
470 The list of words to encode
471
472 Returns
473 -------
474 codes : list of `N` binary strings
475 The encoded words in `text`
476 """
477 if isinstance(text, str):
478 text = [text]
479 for token in set(text):
480 if token not in self._item2code:
481 raise Warning("Token '{}' not in Huffman tree. Skipping".format(token))
482 return [self._item2code.get(t, None) for t in text]
483
484 def inverse_transform(self, codes):
485 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected