from typing import Counter


def bag_of_ngrams(msg, n):
    """
    Extract a bag of word ngrams from a message, with fixed n
    :param msg: input string
    :param n: size of ngram
    :return: bag of features, as a Counter
    """
    if n == 0:
        raise ValueError('n must be a positive integer')
    words = msg.split()
    if n > len(words):
        return Counter()
    else:
        return Counter(('ngram', tuple(words[i:i+n])) for i in range(len(words)-n+1))