Function Repository Resource:

GenerateQuestionsFromSentence

Source Notebook

Generate a set of questions from the given sentence

Contributed by: Harshal Gajjar

ResourceFunction["GenerateQuestionsFromSentence"][string]

attempts to create quiz-type questions from the information present in string.

Details and Options

ResourceFunction["GenerateQuestionsFromSentence"] finds all entities, dates, quantities and other content-related elements in the given text and generates fill-in-the-blank-style questions using those elements.
ResourceFunction["GenerateQuestionsFromSentence"] returns a Dataset with columns "Question", "Hint" and "Answer". The "Question" value is the sentence with words or phrases replaced by underscore (blank) characters.
The blanks in the resulting question have the same length as the answer.
ResourceFunction["GenerateQuestionsFromSentence"] takes the following option:
MaxItemsInfinityset an upper bound on the number of questions

Examples

Basic Examples (2) 

Generate questions from a sentence:

In[1]:=
ResourceFunction[
 "GenerateQuestionsFromSentence"]["Following his PhD, Wolfram joined \
the faculty at Caltech and became the youngest recipient of the \
MacArthur Fellowships in 1981, at age 21."]
Out[1]=

See the first question in textual format:

In[2]:=
%[1, "Question"]
Out[2]=

List at most 2 questions:

In[3]:=
ResourceFunction[
 "GenerateQuestionsFromSentence"]["The French Revolution was a period \
of social and political upheaval in France and its colonies beginning \
in 1789 and ending in 1799.", "MaxItems" -> 2]
Out[3]=

Options (1) 

MaxItems (1) 

Number of questions generated can be bounded:

In[4]:=
ResourceFunction[
 "GenerateQuestionsFromSentence"]["Following his PhD, Wolfram joined \
the faculty at Caltech and became the youngest recipient of the \
MacArthur Fellowships in 1981, at age 21.", MaxItems -> 2]
Out[4]=

Properties and Relations (1) 

Though the function can take in multiple sentences, extracting sentences using TextCases would give better (and shorter) questions:

In[5]:=
text = "Stephen Wolfram (born 29 August 1959) is a British-American \
computer scientist, physicist, and businessman. He is known for his \
work in computer science, mathematics, and in theoretical physics. In \
2012, he was named an inaugural fellow of the American Mathematical \
Society.";
sentences = TextCases[text, "Sentence"];
In[6]:=
ResourceFunction["GenerateQuestionsFromSentence"][text, "MaxItems" -> 1][[1]]["Question"]
Out[6]=
In[7]:=
ResourceFunction["GenerateQuestionsFromSentence"][
   RandomChoice@sentences, "MaxItems" -> 1][[1]]["Question"]
Out[7]=

Possible Issues (2) 

The function might fail to find questions due to absence of any entities, dates, quantities and other content-related elements:

In[8]:=
ResourceFunction["GenerateQuestionsFromSentence"]["It was good.", "MaxItems" -> 1]
Out[8]=

TextContents does not find any elements:

In[9]:=
TextContents["It was good."]
Out[9]=

Publisher

Harshal Gajjar

Version History

  • 1.0.0 – 24 August 2020

Related Resources

License Information