def _compute_matrix(cls, sentences, weighting='frequency', norm=None):
        """
        Compute the matrix of term frequencies given a list of sentences
        """

        if norm not in ('l1', 'l2', None):
            raise ValueError('Parameter "norm" can only take values "l1", "l2" or None')

        # Initialise vectorizer to convert text documents into matrix of token counts
        if weighting.lower() == 'binary':
            vectorizer = CountVectorizer(min_df=1, ngram_range=(1, 1), binary=True, stop_words=None)
        elif weighting.lower() == 'frequency':
            vectorizer = CountVectorizer(min_df=1, ngram_range=(1, 1), binary=False, stop_words=None)
        elif weighting.lower() == 'tfidf':
            vectorizer = TfidfVectorizer(min_df=1, ngram_range=(1, 1), stop_words=None)
        else:
            raise ValueError('Parameter "method" must take one of the values "binary", "frequency" or "tfidf".')

        # Extract word features from sentences using sparse vectorizer
        frequency_matrix = vectorizer.fit_transform(sentences).astype(float)

        # Normalize the term vectors (i.e. each row adds to 1)
        if norm in ('l1', 'l2'):
            frequency_matrix = normalize(frequency_matrix, norm=norm, axis=1)
        elif norm is not None:
            raise ValueError('Parameter "norm" can only take values "l1", "l2" or None')

        return frequency_matrix
Compute the matrix of term frequencies given a list of sentences