'Transform a sequence of instances to a scipy.sparse matrix.
Parameters
raw_X : iterable over iterable over raw features, length = n_samples
Samples. Each sample must be iterable an (e.g., a list or tuple)
containing/generating feature names (and optionally values, see
the input_type constructor argument) which will be hashed.
raw_X need not support the len function, so it can be the result
of a generator; n_samples is determined on the fly.
Returns
X : scipy.sparse matrix, shape = (n_samples, self.n_features)
Feature matrix, for use with estimators or further transformers.'

def transform(self, raw_X):

    raw_X = iter(raw_X)
    if (self.input_type == 'dict'):
        raw_X = (_iteritems(d) for d in raw_X)
    elif (self.input_type == 'string'):
        raw_X = (((f, 1) for f in x) for x in raw_X)
    (indices, indptr, values) = _hashing.transform(raw_X, self.n_features, self.dtype, self.alternate_sign)
    n_samples = (indptr.shape[0] - 1)
    if (n_samples == 0):
        raise ValueError('Cannot    vectorize    empty    sequence.')
    X = sp.csr_matrix((values, indices, indptr), dtype=self.dtype, shape=(n_samples, self.n_features))
    X.sum_duplicates()
    if self.non_negative:
        np.abs(X.data, X.data)
    return X
