Skip to content

Instantly share code, notes, and snippets.

@wclausen
wclausen / spacy_cloze_generator
Created November 8, 2020 01:00
Python code to generate cloze from a sentence using Spacy NLP
import spacy
def get_clozed_sentence(sentence):
# use basic nlp to identify keyword in sentence to cloze
keywords = get_keywords(sentence)
result = sentence # start with un-clozed sentence as result
for idx, keyword in enumerate(keywords):
result = cloze_out_keyword(keyword, idx, result)
return result