Import Dictionary from gensim.corpora.dictionary. Initialize a gensim Dictionary with the tokens in articles. Obtain the

动态 未结 0 82
小小草
小小草 LV1 2023年9月23日 23:40 发表
Here's the completed code: ``` # Import Dictionary from gensim.corpora.dictionary import Dictionary # Create a Dictionary from the articles: dictionary dictionary = Dictionary(articles) # Select the id for "computer": computer_id computer_id = dictionary.token2id.get("computer") # Use computer_id with the dictionary to print the word print(dictionary.get(computer_id)) # Create a MmCorpus: corpus corpus = [dictionary.doc2bow(article) for article in articles] # Print the first 10 word ids with their frequency counts from the fifth document print(corpus[4][:10]) ``` The code imports `Dictionary` from `gensim.corpora.dictionary`. It creates a `Dictionary` object called `dictionary` by passing in `articles`. It obtains the id for "computer" using the `token2
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复