"TextCompletion" (Question Interface Type)
"TextCompletion"
provides a fill-in-the-blank interface with textual input fields.
Properties
- In QuestionInterface["TextCompletion",props], props is an Association that supports the following keys in addition to the options supported by InputField:
-
"Prompt" None text asking the user a question "Template" (required) string template with slots to be filled FieldSize Automatic size of input fields - The "Template" should be a string of the type used in StringTemplate. Template slots denoted by backticks `` define locations for blanks in the question interface.
- Additionally, options for InputField are supported including:
-
Background Automatic input field background color FieldHint Null expression to display when the input field is empty FieldSize {{{{5,Infinity},{1,Infinity}}}} the size of the menu field - For an InputField setting optvalue, the following forms of value are supported:
-
expr use expr for all fields {expr1, expr2, …} use the expri in order for each field, then use defaults {expr1, expr2,…,{c},exprm,…,exprn} use the sequence of expri, then repeatedly use c, then use the last sequence of expri at the end {i1->v1,i2->v2,…} specify what to use at positions ik {spec,rules} use rules to override specifications in spec
Corresponding AssessmentFunction
- "TextCompletion" is not an automatically assigned interface type for an AssessmentFunction. It must be specified in QuestionInterface.
- The values vali in AssessmentFunction[{val1,…},…] should be strings containing the answers for each slot in order.
Examples
open all close allBasic Examples (3)
Create a text completion interface without assessment:
QuestionObject[QuestionInterface["TextCompletion", <|"Prompt" -> "Fill in the form", "Template" -> "Name ``"|>]]Define a text completion question with assessment:
QuestionObject[QuestionInterface["TextCompletion", <|"Prompt" -> "Fill in the countries", "Template" -> "Shanghai is in `` and London is in ``"|>], AssessmentFunction[{{"China", "England"}}]]Create a text completion question providing a full TemplateObject:
cellularRespiration = TemplateObject[{"SubscriptBox[C, 6]SubscriptBox[H, 12]SubscriptBox[O, 6]+", TemplateSlot[1], "SubscriptBox[O, 2]->", TemplateSlot[2], "SubscriptBox[CO, 2]+", TemplateSlot[3], "SubscriptBox[H, 2]O"}]QuestionObject[QuestionInterface["TextCompletion", <|"Prompt" -> "Complete the mass balance of the following reaction", "Template" -> cellularRespiration|>], AssessmentFunction[{{"6", "6", "6"} -> 1}]]Scope (3)
A question with multiple possible correct answers:
QuestionObject[QuestionInterface["TextCompletion", <|"Prompt" -> "Give the correct color", "Template" -> "Apples are ``"|>], AssessmentFunction[{{"red"}, {"green"}}]]Specify an interpreter to standardize input as well as an image to include in the prompt:
QuestionObject[QuestionInterface["TextCompletion", <|"Prompt" -> Column[{"Identify the animal", [image]}], "Template" -> "This is a `` ", "Interpreter" -> "Species"|>], AssessmentFunction[{Entity["TaxonomicSpecies", "Ursidae::46k8d"]}, <|"Comparator" -> (First[#1]["Family"] === #2["Family"]&)|>]
]QuestionObject[QuestionInterface["TextCompletion", <|"Prompt" -> "Complete the sentence using proper grammar", "Template" -> "I arrived `` Chicago `` Monday "|>], AssessmentFunction[{{"in", "on"}}]]Generalizations & Extensions (1)
Customize the input fields' color and include hints:
QuestionObject[QuestionInterface["TextCompletion", <|"Prompt" -> "Fill in the right words", "Template" -> "During the archery contest, `` Hood amazed the `` by ``
an `` with such precision that it `` the bullseye.", FieldHint -> {"R ", "cr ", "sh ", "rr ", "st k"}, DefaultFieldHintStyle -> GrayLevel[0.6], Background -> {{Blue}, 1 -> Cyan, 3 -> Yellow, 5 -> Yellow}|>], AssessmentFunction[{{"Robin", "crowd", "shooting", "arrow", "struck"}}]]Applications (1)
Create a question generator for a fill-in-the-blank question:
gen = QuestionGenerator[{"a" :> RandomInteger[10], "b" :> RandomInteger[10]}, QuestionObject[QuestionInterface["TextCompletion", <|"Prompt" -> "Fill in the blank", "Template" -> StringTemplate["`a` plus `b` equals "][#] <> "``?"|>], AssessmentFunction[{ToString[#a + #b]} -> 1]]&]Create three instances of the question:
Table[gen[], {3}]Possible Issues (2)
The values in the AssessmentFunction should be lists:
QuestionObject[QuestionInterface["TextCompletion", <|"Prompt" -> "Fill in the blank", "Template" -> "apples are ``"|>], AssessmentFunction["red" -> 1]]Specify the values as a list instead:
QuestionObject[QuestionInterface["TextCompletion", <|"Prompt" -> "Fill in the blank", "Template" -> "apples are ``"|>], AssessmentFunction[{"red"} -> 1]]The TemplateObject created by StringTemplate contains options incompatible with "TextCompletion":
fromStringTemplate = StringTemplate["`` and Juliet"]Options[fromStringTemplate]Attempting to use this template will create a broken interface:
QuestionObject[QuestionInterface["TextCompletion", <|"Prompt" -> "Fill in the blank", "Template" -> fromStringTemplate|>], AssessmentFunction[{{"Romeo"}}]]withoutOptions = TemplateObject[First@fromStringTemplate]Now the template works in "TextCompletion":
QuestionObject[QuestionInterface["TextCompletion", <|"Prompt" -> "Fill in the blank", "Template" -> withoutOptions|>], AssessmentFunction[{{"Romeo"}}]]Alternatively, use TemplateObject directly instead of StringTemplate:
directTemplate = TemplateObject[{TemplateSlot[1], " and Juliet"}];This template does not have any options settings:
Options[directTemplate]It works in "TextCompletion":
QuestionObject[QuestionInterface["TextCompletion", <|"Prompt" -> "Fill in the blank", "Template" -> directTemplate|>], AssessmentFunction[{{"Romeo"}}]]See Also
QuestionObject QuestionInterface TemplateObject
Question Interface Types: DragCompletion SelectCompletion DragCategorize MultipleShortAnswers
Comparison Methods: Expression