Skip to content

Instantly share code, notes, and snippets.

@Yuktha-Majella
Created August 7, 2021 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yuktha-Majella/e128ca4e11f88db306b0349895c7e0c5 to your computer and use it in GitHub Desktop.
Save Yuktha-Majella/e128ca4e11f88db306b0349895c7e0c5 to your computer and use it in GitHub Desktop.
Creating a dictionary in Gensim
import gensim
from gensim import corpora
text1 = ["""Gensim is a free open-source Python library for representing documents as semantic vectors,
as efficiently and painlessly as possible. Gensim is designed
to process raw, unstructured digital texts using unsupervised machine learning algorithms."""]
tokens1 = [[item for item in line.split()] for line in text1]
g_dict1 = corpora.Dictionary(tokens1)
print("The dictionary has: " +str(len(g_dict1)) + " tokens\n")
print(g_dict1.token2id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment