6 Question & Answer
The implementation of question-and-answer (Q&A) queries is another valuable functionality provided by the HistText library. This feature enables researchers to target and extract specific content from natural-language texts based on user-defined queries. By formulating questions or prompts, researchers can use the Q&A feature to extract data from documents in natural language. Q&A functions in HistText are particularly effective for retrieving biographical information.
Two models are currently available in HistText: one for Chinese and one for English. You can use the list_qa_models() to list the available models:
::list_qa_models() histtext
6.1 Basic usage
The most basic use is to ask a single question:
<- histtext::search_documents('"member of party"', "imh-en")
imh_en_df
::qa_on_corpus(imh_en_df, "What is his full name?", "imh-en") histtext
Alternatively, you can ask multiple variants of a question:
::qa_on_corpus(imh_en_df, c("What is his full name?", "What name?"), "imh-en") histtext
6.2 More complex usage
A more advanced usage of Q&A can be achieved when questions depend on previous questions:
<- list("name:full" = c("What is his full name?", "What name?"),
questions "education:location" = c("Where {name:full} study at?", "Where study at?"))
::qa_on_corpus(imh_en_df, questions, "imh-en") histtext
ou can also specify the number of answers that a question should be allowed to produce:
::qa_on_corpus(imh_en_df, questions, "imh-en", max_answers = list("education:location" = 2)) histtext
Examples of questions on which models where trained with can be accessed using the following functions:
::biography_questions("en")
histtext::biography_questions("zh") histtext