def get_ngrams(sent, n=2, bounds=False, as_string=False):
	"""
	Given a sentence (as a string or a list of words), return all ngrams
	of order n in a list of tuples [(w1, w2), (w2, w3), ... ]
	bounds=True includes <start> and <end> tags in the ngram list
	"""

	ngrams = []
	words=sent.split()
	if n==1:
		return words

	if bounds:
		words = ['<start>'] + words + ['<end>']

	N = len(words)
	for i in range(n-1, N):
		ngram = words[i-n+1:i+1]
		if as_string: ngrams.append('_'.join(ngram))
		else: ngrams.append(tuple(ngram))
	return ngrams