Skip to content

Instantly share code, notes, and snippets.

wclausen / spacy_cloze_generator
Created Nov 8, 2020
Python code to generate cloze from a sentence using Spacy NLP
View spacy_cloze_generator
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