> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stateset.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Train the NSR Machine on examples

> Trains the neural-symbolic system using input-output pairs. The system learns to map inputs to outputs through both neural perception and symbolic program…

Trains the neural-symbolic system using input-output pairs. The system learns
to map inputs to outputs through both neural perception and symbolic program synthesis.
**Training Process**

1. Neural perception maps inputs to symbol distributions
2. Parser constructs syntactic structures
3. Abductive reasoning synthesizes programs that explain the examples
4. Library learning extracts reusable program components
   **Example**

```bash theme={null}
curl -X POST 'https://api.nsr.stateset.com/api/v1/nsr/train' \
-H 'X-API-Key: your-api-key' \
-H 'Content-Type: application/json' \
-d '&#123;
'examples': [
&#123;'inputs': [&#123;'type': 'text', 'value': 'walk'&#125;], 'output': &#123;'type': 'list', 'value': [&#123;'type': 'string', 'value': 'WALK'&#125;]&#125;&#125;,
&#123;'inputs': [&#123;'type': 'text', 'value': 'run'&#125;], 'output': &#123;'type': 'list', 'value': [&#123;'type': 'string', 'value': 'RUN'&#125;]&#125;&#125;
],
'epochs': 5
&#125;'
```

**Required scope:** `models:manage`

### Request body

`NSRTrainRequest`

<ParamField body="epochs" type="integer">
  Number of epochs (optional, default 1)
</ParamField>

<ParamField body="examples" type="TrainingExampleRequest[]" required>
  Training examples
</ParamField>

### Response

`NSRTrainResponse`

<ResponseField name="final_loss" type="number (double)" required>
  Final training loss
</ResponseField>

<ResponseField name="programs_learned" type="integer" required>
  Programs learned during training
</ResponseField>

<ResponseField name="successful_abductions" type="integer" required>
  Successful abductions
</ResponseField>

<ResponseField name="total_examples" type="integer" required>
  Total examples processed
</ResponseField>

<ResponseField name="training_time_ms" type="integer (int64)" required>
  Training time in milliseconds
</ResponseField>

### Status codes

| Code  | Meaning                                               |
| ----- | ----------------------------------------------------- |
| `200` | Training completed successfully                       |
| `400` | Invalid request - empty examples or validation failed |
| `401` | Unauthorized — missing or invalid credentials         |
| `403` | Forbidden — the key/token lacks the required scope    |
| `429` | Rate limited — see Retry-After / X-RateLimit-Reset    |
| `500` | Internal server error - training failed               |
| `504` | Training budget exhausted before completion           |

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url 'https://api.nsr.stateset.com/api/v1/nsr/train' \
    --header 'X-API-Key: YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{
    "epochs": 5,
    "examples": [
      {
        "inputs": [
          {
            "type": "text",
            "value": "walk"
          }
        ],
        "output": {
          "type": "list",
          "value": [
            {
              "type": "string",
              "value": "WALK"
            }
          ]
        }
      },
      {
        "inputs": [
          {
            "type": "text",
            "value": "run"
          }
        ],
        "output": {
          "type": "list",
          "value": [
            {
              "type": "string",
              "value": "RUN"
            }
          ]
        }
      }
    ]
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "final_loss": 0.023,
    "programs_learned": 3,
    "successful_abductions": 8,
    "total_examples": 10,
    "training_time_ms": 1250
  }
  ```
</ResponseExample>
