Solve Complex Math Problems with NuminaMath 7B TIR Cognitive Actions

22 Apr 2025
Solve Complex Math Problems with NuminaMath 7B TIR Cognitive Actions

In today's fast-paced world, solving complex mathematical problems accurately and efficiently is essential, especially for developers building applications that require computational intelligence. The NuminaMath 7B TIR Cognitive Actions provide powerful tools for integrating advanced mathematical reasoning into your applications. By leveraging a fine-tuned language model, these actions allow for precise solutions to competition-level math problems through a combination of natural language reasoning and Python code execution.

Prerequisites

Before diving into the integration of Cognitive Actions, ensure you have the following prerequisites in place:

  • API Key: You need a valid API key for accessing the Cognitive Actions platform. This key will be used for authenticating your requests.
  • Basic Knowledge of JSON: Understanding JSON structure will help you format your input and output correctly.

To authenticate, you will typically pass your API key in the headers of your HTTP requests.

Cognitive Actions Overview

Solve Math Problems Using Tool-Integrated Reasoning

Description: This action uses the NuminaMath 7B TIR language model to solve complex math problems with enhanced accuracy. It is specifically designed to tackle competition-level mathematical questions, employing a combination of natural language reasoning and Python code execution to deliver precise solutions.

Category: Math

Input

The input for this action follows the CompositeRequest schema, which includes several parameters to configure the model's output:

  • topK (integer, default: 50): The number of highest probability tokens to consider for generating the output.
  • topP (number, default: 0.9): A probability threshold for generating the output.
  • prompt (string): The initial input text or question guiding the model.
  • maxTokens (integer, default: 512): The maximum number of tokens to generate as output.
  • minTokens (integer, default: 0): The minimum number of tokens to generate as output.
  • temperature (number, default: 0.6): Controls the randomness of token selection; lower values make outputs more deterministic.
  • systemPrompt (string, default: "You are a helpful assistant."): A prompt to guide model behavior.
  • stopSequences (string): A designated list of sequences where generation should terminate.
  • presencePenalty (number, default: 0): A penalty to encourage generating new and diverse tokens.
  • frequencyPenalty (number, default: 0): A penalty to reduce the repetition of previously generated tokens.

Example Input:

{
  "topK": 50,
  "topP": 0.9,
  "prompt": "For how many values of the constant $k$ will the polynomial $x^{2}+kx+36$ have two distinct integer roots?",
  "maxTokens": 512,
  "minTokens": 0,
  "temperature": 0.6,
  "systemPrompt": "You are a helpful assistant.",
  "presencePenalty": 0,
  "frequencyPenalty": 0
}

Output

The action typically returns a structured response that may include detailed mathematical reasoning, intermediate steps, and final answers, as illustrated in the example output below. The output may vary depending on the complexity of the input prompt.

Example Output:

[
  1,
  ".",
  " **",
  "Under",
  "stand",
  " the",
  " Pol",
  "ynomial",
  " and",
  " its",
  " Roots",
  "**:",
  "\n",
  "  ",
  " The",
  " polynomial",
  " given",
  " is",
  " \\(",
  "x",
  "^",
  2,
  " +",
  " k",
  "x",
  " +",
  " ",
  3,
  6,
  "\\).",
  ...
]

Conceptual Usage Example (Python)

Here’s how you can invoke the "Solve Math Problems Using Tool-Integrated Reasoning" action using Python:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "e3723f28-b190-4f3f-9d29-40d364db6b0c"  # Action ID for Solve Math Problems Using Tool-Integrated Reasoning

# Construct the input payload based on the action's requirements
payload = {
    "topK": 50,
    "topP": 0.9,
    "prompt": "For how many values of the constant $k$ will the polynomial $x^{2}+kx+36$ have two distinct integer roots?",
    "maxTokens": 512,
    "minTokens": 0,
    "temperature": 0.6,
    "systemPrompt": "You are a helpful assistant.",
    "presencePenalty": 0,
    "frequencyPenalty": 0
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload}  # Hypothetical structure
    )
    response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this example, you replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. Notice how the action ID and input payload are structured. The endpoint URL and request structure used here are for illustrative purposes.

Conclusion

The NuminaMath 7B TIR Cognitive Actions provide a sophisticated solution for developers seeking to integrate advanced mathematical reasoning into their applications. By utilizing these pre-built actions, you can enhance your application's ability to solve complex problems with high accuracy. Next steps could include experimenting with different prompts and configurations to see how the model responds, or incorporating these actions into larger applications that require mathematical analysis. Start integrating and elevate your application's capabilities today!