Large language model numerical problem solution architecture
A method includes obtaining a sequence of instructions for generating a final result of a computation from a large language model by processing a user prompt requesting the computation. The method further includes converting the sequence of instructions to a sequence of mathematical expressions. The method further includes evaluating, by a numerical solver, the sequence of mathematical expressions to obtain a corresponding set of intermediate results. The method further includes evaluating the final result using the corresponding set of intermediate results, and presenting the final result.
1 . A method comprising:
receiving a user prompt from a user application comprising a set of operands and an instruction in natural language requesting a computation referencing the set of operands;
transmitting, by a structured reasoning framework to a large language model (LLM), a machine-readable prompt from a prompt template, the machine-readable prompt comprising the user prompt and a second instruction directing the LLM to generate a sequence of instructions according to a structured reasoning process, wherein the LLM is a foundation artificial intelligence (AI) model having a transformer architecture, fine-tuned on a document corpus;
obtaining, from the LLM processing the machine-readable prompt, the sequence of instructions, each instruction comprising a directive specifying an operation to be performed and an explanation providing a natural language rationale for the operation, wherein the sequence of instructions describes generating a final result of the computation;
converting, by a computation artificial intelligence (AI) agent separate from the LLM, the sequence of instructions to a sequence of mathematical expressions;
evaluating, by a numerical solver, the sequence of mathematical expressions to obtain a corresponding set of intermediate results;
evaluating the final result using the corresponding set of intermediate results;
performing, by a precision check engine, operations comprising:
performing a semantic similarity analysis to compare respective explanations of the sequence of instructions with a plurality of domain-specific reference explanations, using an embedding-based similarity function, and
comparing the set of intermediate results and the final result with expected values,
wherein the LLM resides on a first node of a network, and the precision check engine resides on a second node of the network; and
presenting the final result.
2 . The method of claim 1 ,
wherein successive instructions of the sequence of instructions comprise mathematical expressions corresponding to successive steps of the computation, a mathematical expression comprising a partial computation of the set of operands and producing an intermediate result.
3 . The method of claim 2 , further comprising:
processing, by the LLM, the machine-readable prompt to generate the sequence of instructions, wherein the machine-readable prompt further comprises a mathematical expression template, and the successive instructions of the sequence of instructions comprise corresponding mathematical expressions in a format defined by the mathematical expression template.
4 . The method of claim 1 , wherein converting the sequence of instructions further comprises:
extracting a first mathematical expression of a first instruction of the sequence of instructions; and
adding the first mathematical expression to the sequence of mathematical expressions, to obtain the sequence of mathematical expressions.
5 . The method of claim 1 , wherein evaluating the sequence of mathematical expressions further comprises:
evaluating, by the numerical solver, a first mathematical expression of the sequence of mathematical expressions, wherein the first mathematical expression references a first set of operands, to obtain a first intermediate result value,
wherein the first set of operands is obtained from a first instruction of the sequence of instructions, the first instruction corresponding to the first mathematical expression;
extracting a first intermediate result name corresponding to the first mathematical expression from the first instruction; and
adding the first intermediate result name and the first intermediate result value to the corresponding set of intermediate results, wherein a first intermediate result of the corresponding set of intermediate results comprises the first intermediate result name and the first intermediate result value.
6 . The method of claim 1 , wherein evaluating the sequence of mathematical expressions further comprises:
evaluating, by the numerical solver, a first mathematical expression of the sequence of mathematical expressions, wherein the first mathematical expression references a first set of operands and the corresponding set of intermediate results, to obtain a new intermediate result value,
wherein the first set of operands is obtained from a first instruction of the sequence of instructions corresponding to the first mathematical expression, and
an intermediate result of the corresponding set of intermediate results comprises an intermediate result name and an intermediate result value;
extracting a new intermediate result name corresponding to the first mathematical expression from a corresponding first instruction of the sequence of instructions; and
adding the new intermediate result name and the new intermediate result value to the corresponding set of intermediate results.
7 . The method of claim 1 , further comprising:
extracting a final mathematical expression of a final instruction of the sequence of instructions, wherein the final mathematical expression references the corresponding set of intermediate results; and
evaluating, by the numerical solver, the final mathematical expression to obtain the final result.
8 . The method of claim 1 , further comprising:
validating, by the precision check engine, the corresponding set of intermediate results and the final result; and
adding, by the precision check engine, the sequence of instructions, the sequence of mathematical expressions, and the corresponding set of intermediate results to a computation log.
9 . The method of claim 1 , wherein presenting the final result further comprises:
presenting the sequence of instructions, the corresponding set of intermediate results, and the final result, wherein an instruction of the sequence of instructions further comprises an explanation of a mathematical expression of the instruction.
10 . A system, comprising:
at least one computer processor;
a user application, executing on the at least one computer processor;
a computation artificial intelligence (AI) agent, executing on the at least one computer processor; and
a large language model (an LLM) that is separate from the computation AI agent, executing on the at least one computer processor,
wherein the computation AI agent is configured for:
receiving a user prompt from the user application comprising a set of operands and an instruction in natural language requesting a computation referencing the set of operands,
instantiating a machine-readable prompt from a prompt template, comprising the user prompt, and a second instruction directing the LLM to generate a sequence of instructions according to a structured reasoning process, wherein the LLM is a foundation artificial intelligence (AI) model having a transformer architecture, fine-tuned on a document corpus,
causing the LLM to process the machine-readable prompt to obtain the sequence of instructions, each instruction comprising a directive specifying an operation to be performed and an explanation providing a natural language rationale for the operation, wherein the sequence of instructions describes generating a final result of the computation,
converting the sequence of instructions to a sequence of mathematical expressions,
evaluating, by a numerical solver of the computation AI agent, the sequence of mathematical expressions to obtain a corresponding set of intermediate results,
evaluating, by the numerical solver, the final result using the corresponding set of intermediate results,
causing a precision check engine to perform operations comprising:
performing a semantic similarity analysis to compare respective explanations of the sequence of instructions with a plurality of domain-specific reference explanations, using an embedding-based similarity function, and
comparing the set of intermediate results and the final result with expected values, wherein the LLM resides on a first node of a cloud network, and the precision check engine resides on a second node of the cloud network, and
presenting the final result.
11 . The system of claim 10 ,
wherein successive instructions of the sequence of instructions comprise mathematical expressions corresponding to successive steps of the computation, a mathematical expression comprising a partial computation of the set of operands and producing an intermediate result.
12 . The system of claim 11 , further configured for:
processing, by the LLM, the machine-readable prompt to generate the sequence of instructions, wherein the machine-readable prompt further comprises a mathematical expression template, and the successive instructions of the sequence of instructions comprise corresponding mathematical expressions in a format defined by the mathematical expression template.
13 . The system of claim 10 , further configured for converting the sequence of instructions, comprising:
extracting, by the computation AI agent, a first mathematical expression of a first instruction of the sequence of instructions; and
adding, by the computation AI agent, the first mathematical expression to the sequence of mathematical expressions, to obtain the sequence of mathematical expressions.
14 . The system of claim 10 , further configured for evaluating the sequence of mathematical expressions, comprising:
evaluating, by the numerical solver, a first mathematical expression of the sequence of mathematical expressions, wherein the first mathematical expression references a first set of operands, to obtain a first intermediate result value,
wherein the first set of operands is obtained from a first instruction of the sequence of instructions, the first instruction corresponding to the first mathematical expression;
extracting a first intermediate result name corresponding to the first mathematical expression from the first instruction; and
adding the first intermediate result name and the first intermediate result value to the corresponding set of intermediate results, wherein a first intermediate result of the corresponding set of intermediate results comprises the first intermediate result name and the first intermediate result value.
15 . The system of claim 10 , further configured for evaluating the sequence of mathematical expressions, further comprising:
evaluating, by the numerical solver, a first mathematical expression of the sequence of mathematical expressions, wherein the first mathematical expression references a first set of operands and the corresponding set of intermediate results, to obtain a new intermediate result value,
wherein the first set of operands is obtained from a first instruction of the sequence of instructions corresponding to the first mathematical expression, and
an intermediate result of the corresponding set of intermediate results comprises an intermediate result name and an intermediate result value;
extracting a new intermediate result name corresponding to the first mathematical expression from a corresponding first instruction of the sequence of instructions; and
adding the new intermediate result name and the new intermediate result value to the corresponding set of intermediate results.
16 . The system of claim 10 , further configured for:
extracting a final mathematical expression of a final instruction of the sequence of instructions, wherein the final mathematical expression references the corresponding set of intermediate results; and
evaluating, by the numerical solver, the final mathematical expression to obtain the final result.
17 . The system of claim 10 , further configured for:
validating, by the precision check engine, the corresponding set of intermediate results and the final result; and
adding, by the precision check engine, the sequence of instructions, the sequence of mathematical expressions, and the corresponding set of intermediate results to a computation log.
18 . A method, comprising:
receiving a user prompt from a user application, the user prompt comprising a set of operands, and an instruction in natural language requesting a computation, wherein an operand comprises an operand name and an operand value, and the computation references the set of operands;
transmitting, by a structured reasoning framework to a large language model (LLM), a machine-readable prompt from a prompt template, the machine-readable prompt comprising the user prompt, and a second instruction directing an LLM to generate a sequence of instructions for generating a final result of the computation according to a structured reasoning process,
wherein successive instructions of the sequence of instructions comprise corresponding mathematical expressions corresponding to successive steps of the computation, a mathematical expression comprising a partial computation of the set of operands and producing an intermediate result, and wherein the LLM is a foundation AI model having a transformer architecture fine-tuned on a document corpus;
processing, by the LLM, the machine-readable prompt, to generate the sequence of instructions, each instruction further comprising an explanation providing a natural language rationale for a corresponding mathematical expression, and wherein the sequence of instructions describing generating the final result of the computation;
converting, by a computation artificial intelligence (AI) agent separate from the LLM, the sequence of instructions to a corresponding sequence of mathematical expressions;
evaluating, by a numerical solver, a first mathematical expression of the corresponding sequence of mathematical expressions, wherein the first mathematical expression references a first set of operands, to obtain a first intermediate result value,
wherein the first set of operands is obtained from a first instruction of the sequence of instructions, the first instruction corresponding to the first mathematical expression;
adding a first intermediate result name obtained from the first instruction and the first intermediate result value to a set of intermediate results, wherein the set of intermediate results corresponds to the sequence of mathematical expressions;
evaluating, by the numerical solver, a final mathematical expression of the corresponding sequence of mathematical expressions, wherein the final mathematical expression references the set of intermediate results, to obtain the final result;
performing, by a precision check engine, operations comprising:
performing a semantic similarity analysis to compare respective explanations of the sequence of instructions with a plurality of domain-specific reference explanations, using an embedding-based similarity function, and
comparing the set of intermediate results and the final result with expected values, wherein the LLM resides on a first node of a network, and the precision check engine resides on a second node of the network; and
presenting the final result.