Import the WordNetLemmatizer class from nltk.stem. Create a list alpha_only that contains only alphabetical characters.

动态 未结 0 64
小小草
小小草 LV1 2023年9月23日 23:40 发表
Here's the completed code: ``` # Import WordNetLemmatizer from nltk.stem import WordNetLemmatizer # Retain alphabetic words: alpha_only alpha_only = [t for t in tokens if t.isalpha()] # Remove all stop words: no_stops no_stops = [t for t in alpha_only if t not in english_stops] # Instantiate the WordNetLemmatizer wordnet_lemmatizer = WordNetLemmatizer() # Lemmatize all tokens into a new list: lemmatized lemmatized = [wordnet_lemmatizer.lemmatize(t) for t in no_stops] # Create the bag-of-words: bow bow = Counter(lemmatized) # Print the 10 most common tokens print(bow.most_common(10)) ``` The code imports `WordNetLemmatizer` from `nltk.stem`. It then creates a list called `alpha_only` that contains only alphabetical characters
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复