import re from collections import Counter class WordFrequencyModel: def get_top_n_words(self, text, top_n=10): words = re.findall(r'\b\w+\b', text) word_counts = Counter(words) return word_counts.most_common(top_n)