Last active
August 24, 2020 16:37
-
-
Save purva91/c8bf8e060d2cab90abdcc12dd65c2182 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 nltk | |
nltk.download('punkt') | |
from nltk.tokenize import word_tokenize | |
import numpy as np |
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
sentences = ["I ate dinner.", | |
"We had a three-course meal.", | |
"Brad came to dinner with us.", | |
"He loves fish tacos.", | |
"In the end, we all felt like we ate too much.", | |
"We all agreed; it was a magnificent evening."] |
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
# Tokenization of each document | |
tokenized_sent = [] | |
for s in sentences: | |
tokenized_sent.append(word_tokenize(s.lower())) | |
tokenized_sent |
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
def cosine(u, v): | |
return np.dot(u, v) / (np.linalg.norm(u) * np.linalg.norm(v)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment