<s>[INST] print top five most common words in a text file, ignoring common words like "and", "the" etc. 
use python, NLTK and stopwords

__main.py__
```
import os
import re
import string
from collections import Counter
from nltk.corpus import stopwords
from nltk import word_tokenize
from nltk.stem import PorterStemmer

def get_text(file_path):
    with open(file_path) as file:
        text = file.read()
        return text

def clean_words(words):
    table = str.maketrans('', '', string.punctuation)
    stripped = [w.translate(table) for w in words]
    words = [word.lower() for word in stripped]
    return words

def tokenise_text(text):
    words = word_tokenize(text)
    return words

def stem_words(words):
    ps = PorterStemmer()
    stemmed_words = [ps.stem(word) for word in words]
    return stemmed_words

def get_common_words(words, top_n):
    return Counter(words).most_common(top_n)

def get_stop_words():
    stop_words = set(stopwords.words('english'))
    return stop_words

def remove_stop_words(words, stop_words):
    return [word for word in words if word not in stop_words]

def main():
    file_path = 'text.txt'
    text = get_text(file_path)
    words = tokenise_text(text)
    words = clean_words(words)
    stem_words = stem_words(words)
    stop_words = get_stop_words()
    words = remove_stop_words(words, stop_words)
    common_words = get_common_words(words, 5)
    print(common_words)

if __name__ == '__main__':
    main()
```
The problem here is that I am doing stemming on the original words and then removing the stop words. This means that the stemming is not being applied to the words that were filtered out by the stop words removal

I could stem after the removal of stop words, but this will mean that words like "running" and "runs" get stemmed to "run" and will get counted as the same word in the Counter

Another solution is to do the stemming before and after the removal of stop words, but that would be inefficient as it would involve two passes over the data

Is there a more efficient way to do this?[/INST]