Last active
June 6, 2018 22:46
-
-
Save thomwolf/61c0dcfe76525ef4be50cfb26a28314f to your computer and use it in GitHub Desktop.
Example of Python loop to count the occurrences of the word "run" tagged as noun by spaCy in a portion of Wikitext2
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 slow_loop(doc_list, word, tag): | |
n_out = 0 | |
for doc in doc_list: | |
for tok in doc: | |
if tok.lower_ == word and tok.tag_ == tag: | |
n_out += 1 | |
return n_out | |
def main_nlp_slow(doc_list): | |
n_out = slow_loop(doc_list, 'run', 'NN') | |
print(n_out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment