def _ngrams(segment, n):
ngram_counts = Counter()<EOL>for i in range(<NUM_LIT:0>, len(segment) - n + <NUM_LIT:1>):<EOL><INDENT>ngram = tuple(segment[i:i + n])<EOL>ngram_counts[ngram] += <NUM_LIT:1><EOL><DEDENT>return ngram_counts<EOL>
Extracts n-grams from an input segment.

    Parameters
    ----------
    segment: list
        Text segment from which n-grams will be extracted.
    n: int
        Order of n-gram.

    Returns
    -------
    ngram_counts: Counter
        Contain all the nth n-grams in segment with a count of how many times each n-gram occurred.