Skip to content

Instantly share code, notes, and snippets.

@thomwolf
Last active June 6, 2018 22:46
Show Gist options
  • Save thomwolf/61c0dcfe76525ef4be50cfb26a28314f to your computer and use it in GitHub Desktop.
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
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