In this post we would look at creating Document Term Matrix (DTM) using the Features generated from Term Frequency(TF) or/and Term Frequency-Inverse Document Frequency(TF-IDF) .This will result in the creation of Data Frame that can be used for any subsequent analyses. This data frame will be called as Document Term Matrix. It has the following Properties:
- First column will represent Document ID (Doc_ID)
- Other columns will represent the Features selected as a result of profiling activity
- Values in the cells will represent either
- Term Frequency (TF)
- Term Frequency-Inverse Document Frequency(TF-IDF)
In the blog, I have covered how to create functions which takes the following things as input:
- Name of the data frame
- Column containing the text data
- select ngram parameter in the form of 1,2,3...
- A list can be passed to ngram. If I pass [1,2], then the function will create unigrams and bigrams summary
It generates the Document ID/Row wise summary of Tokens in the form of frequency or TF-IDF. The following functions have been created:
- Tokenize the text
- Create frequency profile at Document_ID level
- Create TF-IDF profile at Document_ID level
- Clean the text for any punctuation
I have also tested the functions to see how to fair when the records becomes high (~100k). The function performed fairly.
Download Link : https://drive.google.com/drive/folders/1Jn9qygledlxQ0KbHJdqgRl5tW6dJI4ag?usp=sharing
Download the ipynb file,html version and the csv file to understand the flow
Links to my previous blogs on NLP:
No comments:
Post a Comment