Auto assist questionnaire
Auto-fill Questionnaire using Chain of Thought or Few-Shot Examples¶
This notebook showcases the application of few-shot examples in autofilling questionnaires. It utilizes a json file (risk_questionnaire_cot.json) to
provide the LLM with example responses for some use-cases.
By leveraging these few-shot examples, we can enable seamless completion of lengthy questionnaires, minimizing manual effort and improving overall efficiency.
from ai_atlas_nexus.blocks.inference import (
RITSInferenceEngine,
WMLInferenceEngine,
OllamaInferenceEngine,
VLLMInferenceEngine,
)
from ai_atlas_nexus.blocks.inference.params import (
InferenceEngineCredentials,
RITSInferenceEngineParams,
WMLInferenceEngineParams,
OllamaInferenceEngineParams,
VLLMInferenceEngineParams,
)
import os
from ai_atlas_nexus.data import load_resource
from ai_atlas_nexus.library import AIAtlasNexus
AI Atlas Nexus uses Large Language Models (LLMs) to infer risks dimensions. Therefore requires access to LLMs to inference or call the model.¶
Available Inference Engines: WML, Ollama, vLLM, RITS. Please follow the Inference APIs guide before going ahead.
Note: RITS is intended solely for internal IBM use and requires TUNNELALL VPN for access.
inference_engine = OllamaInferenceEngine(
model_name_or_path="granite3.3:8b",
credentials=InferenceEngineCredentials(api_url="http://localhost:11434"),
parameters=OllamaInferenceEngineParams(
num_predict=1000, num_ctx=8192, temperature=0
),
)
# inference_engine = WMLInferenceEngine(
# model_name_or_path="ibm/granite-4-h-small",
# credentials={
# "api_key": os.getenv("WML_API_KEY"),
# "api_url": os.getenv("WML_API_URL"),
# "project_id": os.getenv("WML_PROJECT_ID"),
# },
# parameters=WMLInferenceEngineParams(
# max_new_tokens=1000, decoding_method="greedy"
# ),
# )
# inference_engine = VLLMInferenceEngine(
# model_name_or_path="ibm-granite/granite-3.3-8b-instruct",
# credentials=InferenceEngineCredentials(
# api_url=os.getenv("VLLM_API_URL"), api_key=os.getenv("VLLM_API_KEY")
# ),
# parameters=VLLMInferenceEngineParams(max_tokens=1000, temperature=0),
# )
# inference_engine = RITSInferenceEngine(
# model_name_or_path="ibm-granite/granite-3.3-8b-instruct",
# credentials={
# "api_key": os.getenv("RITS_API_KEY"),
# "api_url": os.getenv("RITS_API_URL"),
# },
# parameters=RITSInferenceEngineParams(max_completion_tokens=1000, temperature=0),
# )
[2026-04-12 18:58:21:998] - INFO - AIAtlasNexus - ✓ Created OLLAMA inference engine for model: granite3.3:8b, backend - DEFAULT
Create an instance of AIAtlasNexus¶
Note: (Optional) You can specify your own directory in AIAtlasNexus(base_dir=<PATH>) to utilize custom AI ontologies. If left blank, the system will use the provided AI ontologies.
ai_atlas_nexus = AIAtlasNexus()
[2026-04-12 18:58:22:492] - INFO - AIAtlasNexus - Created AIAtlasNexus instance. Base_dir: None
Defining Examples for Auto-Assist Functionality¶
The auto-assist feature utilizes few-shot examples defined in the file ai_atlas_nexus/data/templates/risk_questionnaire_cot.json to predict the output of the risk questionnaire.
Customization:
To adapt this auto-assist functionality to custom risk questionnaire, users need to provide their own set of questions, example intents, and corresponding answers in a json file such as in risk_questionnaire_cot.json. This will enable the LLM to learn from these few-shot examples and generate responses for unseen queries.
CoT Template - Zero Shot method
Each question is accompanied by corresponding examples provided as an empty list.
[
{
"question": "In which environment is the system used?",
"cot_examples": []
}
...
]
CoT Template - Few Shot method
Each question is associated with a list of examples, each containing intent, answer, and optional explanation.
[
{
"question": "In which environment is the system used?",
"cot_examples": [
{
"intent": "Find patterns in healthcare insurance claims",
"answer": "Insurance Claims Processing or Risk Management or Data Analytics",
"explanation": "The system might be used by an insurance company's claims processing department to analyze and identify patterns in healthcare insurance claims."
},
{
"intent": "optimize supply chain management in Investment banks",
"answer": "Treasury Departments or Asset Management Divisions or Private Banking Units",
"explanation": null
},
...
]
}
...
]
In this notebook, we're using a simplified template to cover 7 questions from the Airo questionnaire:
- AI Domain
- System environment
- Utilized techniques
- Intended User
- Intended Purpose
- System Application
- AI Subject
Load Risk Questionnaire¶
Note: The cell below loads examples of risk questionnaires from Risk Atlas Master. To load your custom questionnaire, create it according to the specified format and load it instead.
risk_questionnaire = load_resource("risk_questionnaire_cot.json")
risk_questionnaire[0]
{'no': 'Q1',
'question': 'What domain does your use request fall under? Customer service/support, Technical, Information retrieval, Strategy, Code/software engineering, Communications, IT/business automation, Writing assistant, Financial, Talent and Organization including HR, Product, Marketing, Cybersecurity, Healthcare, User Research, Sales, Risk and Compliance, Design, Other',
'cot_examples': [{'intent': 'Optimize supply chain management in Investment banks',
'answer': 'Strategy',
'confidence': 'Likely answer from the intent',
'explanation': 'Since the task is involved in improving the processes to ensure better performance. It is not finance since the task is on supply chain optimization and not on financial aspects even though the application domain is banks.'},
{'intent': 'Ability to create dialog flows and integrations from natural language instructions.',
'answer': 'Customer service/support',
'confidence': 'Likely answer from the intent',
'explanation': 'Since the task relates to human conversations or generating human converstations or support.'},
{'intent': 'Check if a document has grammatical mistakes.',
'answer': 'Writing assitant',
'confidence': 'Likely answer from the intent',
'explanation': 'Since this helps in improving the quality of text. It is not customer service since this on on the quality of text rather than helping in human conversations.'},
{'intent': 'Optimize supply chain management in Investment banks',
'answer': 'Strategy',
'confidence': 'Likely answer from the intent',
'explanation': 'Since the task is involved in improving the processes to ensure better performance. It is not finance since the task is on supply chain optimization and not on financial aspects even though the application domain is banks.'},
{'intent': "In the context of drug repurposing, generative AI can be employed to analyze vast databases of existing drugs and their clinical trials data. By identifying patterns and similarities, the AI can suggest potential new therapeutic indications for existing drugs, based on the chemical structure and pharmacological properties of the APIs. This process can help streamline the drug development pipeline, as it would reduce the need for time-consuming and expensive clinical trials for new indications. For instance, a drug like Atorvastatin, which is currently used to lower cholesterol, could be repurposed for the treatment of diabetic nephropathy, a kidney disease, based on the AI's analysis of similar drugs and their clinical data. This would not only save resources but also provide new treatment options for patients suffering from this debilitating condition. ",
'answer': 'Healthcare and strategy',
'confidence': 'Directly from the input text',
'explanation': 'Since the task is related to healthcare and drug repurposing, which involves analyzing data related to drugs and their clinical trials, this falls under the healthcare domain. It also involves Strategy it talks about using patterns to create new treatment options.'}]}
There are two ways to use the inference engine to get the LLM outputs. generate_zero_shot_risk_questionnaire_output which gives the zero-shot output for the question and generate_few_shot_risk_questionnaire_output which gives the output using few-shot examples defined above.
usecases = load_resource("questionnaire_benchmark.json")
usecase = usecases[2:3][0]["UseCase"]
usecase
'Sentiment Analysis for Social Media Monitoring'
Auto Assist Questionnaire - Zero Shot¶
results = ai_atlas_nexus.generate_zero_shot_risk_questionnaire_output(
usecase, risk_questionnaire, inference_engine
)
# Display Results
for index, (question_data, result) in enumerate(
zip(risk_questionnaire, results), start=1
):
print(
f"\n{index}: "
+ question_data["question"]
+ "\nA: "
+ result.prediction["answer"]
)
Inferring with OLLAMA, backend - DEFAULT: 100%|██████████| 7/7 [00:26<00:00, 3.72s/it]
1: What domain does your use request fall under? Customer service/support, Technical, Information retrieval, Strategy, Code/software engineering, Communications, IT/business automation, Writing assistant, Financial, Talent and Organization including HR, Product, Marketing, Cybersecurity, Healthcare, User Research, Sales, Risk and Compliance, Design, Other
A: Risk and Compliance
2: In which environment is the system used?
A: The system is used in a social media monitoring environment.
3: What techniques are utilised in the system? Multi-modal: {Document Question/Answering, Image and text to text, Video and text to text, visual question answering}, Natural language processing: {feature extraction, fill mask, question answering, sentence similarity, summarization, table question answering, text classification, text generation, token classification, translation, zero shot classification}, computer vision: {image classification, image segmentation, text to image, object detection}, audio:{audio classification, audio to audio, text to speech}, tabular: {tabular classification, tabular regression}, reinforcement learning
A: The system utilizes a variety of techniques including multi-modal approaches such as Document Question/Answering, Image and text to text, Video and text to text, and visual question answering. Natural language processing techniques include feature extraction, fill mask, question answering, sentence similarity, summarization, table question answering, text classification, text generation, token classification, translation, and zero shot classification. Computer vision techniques encompass image classification, image segmentation, text to image, and object detection. Audio processing involves audio classification and text to speech. Tabular data analysis is covered by tabular classification and regression. The system also incorporates reinforcement learning.
4: Who is the intended user of the system?
A: The intended users of the system are compliance officers, legal teams, and social media managers who need to monitor public sentiment about a brand, product, or service.
5: What is the intended purpose of the system?
A: The intended purpose of the system is to monitor social media platforms for public sentiment, enabling organizations to understand public opinion about their brand, products, or services.
6: What is the application of the system?
A: The application of the system is for monitoring social media platforms to gauge public sentiment, identify trends, and ensure compliance with regulations regarding brand reputation, product safety, and adherence to advertising standards.
7: Who is the subject as per the intent?
A: The subject as per the intent is social media content or posts.
Auto Assist Questionnaire - Few Shot¶
results = ai_atlas_nexus.generate_few_shot_risk_questionnaire_output(
usecase,
risk_questionnaire,
inference_engine,
)
# Display Results
for index, (question_data, result) in enumerate(
zip(risk_questionnaire, results), start=1
):
print(
f"\n{index}: "
+ question_data["question"]
+ "\nA: "
+ result.prediction["answer"]
+ "\nC: "
+ result.prediction["confidence"]
)
Inferring with OLLAMA, backend - DEFAULT: 100%|██████████| 7/7 [00:35<00:00, 5.06s/it]
1: What domain does your use request fall under? Customer service/support, Technical, Information retrieval, Strategy, Code/software engineering, Communications, IT/business automation, Writing assistant, Financial, Talent and Organization including HR, Product, Marketing, Cybersecurity, Healthcare, User Research, Sales, Risk and Compliance, Design, Other
A: Marketing
C: Likely answer from the intent
2: In which environment is the system used?
A: Social Media Management Teams or Customer Service Departments
C: Likely answer from the intent
3: What techniques are utilised in the system? Multi-modal: {Document Question/Answering, Image and text to text, Video and text to text, visual question answering}, Natural language processing: {feature extraction, fill mask, question answering, sentence similarity, summarization, table question answering, text classification, text generation, token classification, translation, zero shot classification}, computer vision: {image classification, image segmentation, text to image, object detection}, audio:{audio classification, audio to audio, text to speech}, tabular: {tabular classification, tabular regression}, reinforcement learning
A: Natural language processing: Text Classification and Sentiment Analysis
C: Likely answer from the intent
4: Who is the intended user of the system?
A: Brands, marketing agencies, or research institutions
C: Likely answer from the intent
5: What is the intended purpose of the system?
A: To monitor and analyze public sentiment expressed in social media platforms regarding our brand, products, or industry, enabling us to understand customer perceptions, identify trends, and respond appropriately to maintain a positive brand image.
C: Directly from the input text
6: What is the application of the system?
A: Natural Language Processing (NLP): Analyze social media posts, comments, and mentions to determine public sentiment towards a brand, product, or campaign. This involves categorizing opinions as positive, negative, or neutral.
C: Likely answer from the intent
7: Who is the subject as per the intent?
A: Social media users
C: Directly from the input text