Created
August 7, 2021 15:54
-
-
Save Yuktha-Majella/e128ca4e11f88db306b0349895c7e0c5 to your computer and use it in GitHub Desktop.
Creating a dictionary in Gensim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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