Python, NLP, Numpy, Scikit Learn.
import Counter class CountEncoder(SciKitTransformer): def __init__(self, vocab): self.vocab = dict.fromkeys(vocab, 0.0) def count_vector(self, tokens): vec_dict = deepcopy(self.vocab) token_vec = Counter(tokens) doc_length = len(tokens) for token, count in token_vec.items(): if token in self.vocab: