Skip to content

Instantly share code, notes, and snippets.

@skrater
Last active August 3, 2020 18:39
Show Gist options
  • Save skrater/6c3532822cd32bb1307262152e4f7e8a to your computer and use it in GitHub Desktop.
Save skrater/6c3532822cd32bb1307262152e4f7e8a to your computer and use it in GitHub Desktop.
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