Advanced Configuration

The NICLClassifier accepts several configuration parameters to customize the model behavior.

Model selection

The model parameter specifies which NICL model to use for inference:

>>> clf = NICLClassifier(model="nicl-small")

Available models:

  • nicl-flash: Fastest model, optimized for low latency

  • nicl-small: Balanced model (default)

  • nicl-large: Most accurate model, recommended for complex tasks

Server-side preprocessing

The preprocess parameter controls whether the server performs automatic data preprocessing before inference. This is enabled by default (preprocess=True).

>>> clf = NICLClassifier(preprocess=True)   # Default: server-side preprocessing enabled
>>> clf = NICLClassifier(preprocess=False)  # Disable server-side preprocessing

When enabled, the server applies standardization and other transformations to optimize model performance. Disable this option if you want full control over the preprocessing pipeline on the client side.

Deprecated since version 0.1.0: Classifier and OnPremiseClassifier are deprecated and will be removed in a future version. Use NICLClassifier instead.

Error Handling

The SDK raises specific exceptions that you can catch and handle appropriately.

NeuralkException

NeuralkException is raised for API-related errors. It includes:

  • message: Human-readable error description

  • status_code: HTTP status code (e.g., 401, 429, 500)

  • details: Additional information from the server

from neuralk import NICLClassifier, NeuralkException

clf = NICLClassifier()
clf.fit(X_train, y_train)

try:
    predictions = clf.predict(X_test)
except NeuralkException as e:
    print(f"API Error: {e.message}")
    print(f"Status: {e.status_code}")
    print(f"Details: {e.details}")

Common error scenarios:

Status Code

Cause

Solution

401

Invalid or missing API key

Check NEURALK_API_KEY environment variable or api_key parameter

429

Rate limit exceeded

Wait and retry, or contact support for higher limits

500

Server error

Retry the request; if persistent, contact support

504

Request timeout

Reduce dataset size or increase timeout_s parameter

ValueError

Raised for invalid input parameters:

# Missing API key in cloud mode
clf = NICLClassifier()  # Raises ValueError if NEURALK_API_KEY not set

# Invalid model name
clf = NICLClassifier(model="invalid-model")

# Calling predict before fit
clf.predict(X_test)  # Raises error - must call fit() first

Timeout Configuration

For large datasets, you may need to increase the timeout:

# Default is 900 seconds (15 minutes)
clf = NICLClassifier(timeout_s=1800)  # 30 minutes