'Create sparse feature matrix, and vocabulary where fixed_vocab=False'

def _count_vocab(self, raw_documents, fixed_vocab):

    if fixed_vocab:
        vocabulary = self.vocabulary_
    else:
        vocabulary = defaultdict()
        vocabulary.default_factory = vocabulary.__len__
    analyze = self.build_analyzer()
    j_indices = []
    indptr = _make_int_array()
    values = _make_int_array()
    indptr.append(0)
    for doc in raw_documents:
        feature_counter = {}
        for feature in analyze(doc):
            try:
                feature_idx = vocabulary[feature]
                if (feature_idx not in feature_counter):
                    feature_counter[feature_idx] = 1
                else:
                    feature_counter[feature_idx] += 1
            except KeyError:
                continue
        j_indices.extend(feature_counter.keys())
        values.extend(feature_counter.values())
        indptr.append(len(j_indices))
    if (not fixed_vocab):
        vocabulary = dict(vocabulary)
        if (not vocabulary):
            raise ValueError(u'empty    vocabulary;    perhaps    the    documents    only    contain    stop    words')
    j_indices = np.asarray(j_indices, dtype=np.intc)
    indptr = np.frombuffer(indptr, dtype=np.intc)
    values = np.frombuffer(values, dtype=np.intc)
    X = sp.csr_matrix((values, j_indices, indptr), shape=((len(indptr) - 1), len(vocabulary)), dtype=self.dtype)
    X.sort_indices()
    return (vocabulary, X)
