Last active
August 3, 2020 18:39
-
-
Save skrater/6c3532822cd32bb1307262152e4f7e8a to your computer and use it in GitHub Desktop.
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 re | |
from collections import Counter | |
def term_frequency_featurization(texts): | |
for text in texts: | |
words = re.findall(r'\w+', text.lower()) | |
yield dict(Counter(words)) | |
def main(): | |
result = term_frequency_featurization(["He likes my dog", "Dog likes cat", "My cat cat"]) | |
print(list(result)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment