Train a classifier
curl --request POST \
--url https://api-dev.narrative.io/v1/model-training/train-classifier \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"dataset_id": 123,
"feature_inputs": [
{
"feature_type": "text",
"field_path": "description",
"name": "description_text"
},
{
"feature_type": "categorical",
"field_path": "data['merchant']",
"field_type": "string",
"name": "merchant"
}
],
"label_column": "category",
"model_name": "product_category_classifier"
}
EOFimport requests
url = "https://api-dev.narrative.io/v1/model-training/train-classifier"
payload = {
"dataset_id": 123,
"feature_inputs": [
{
"feature_type": "text",
"field_path": "description",
"name": "description_text"
},
{
"feature_type": "categorical",
"field_path": "data['merchant']",
"field_type": "string",
"name": "merchant"
}
],
"label_column": "category",
"model_name": "product_category_classifier"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
dataset_id: 123,
feature_inputs: [
{feature_type: 'text', field_path: 'description', name: 'description_text'},
{
feature_type: 'categorical',
field_path: 'data[\'merchant\']',
field_type: 'string',
name: 'merchant'
}
],
label_column: 'category',
model_name: 'product_category_classifier'
})
};
fetch('https://api-dev.narrative.io/v1/model-training/train-classifier', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-dev.narrative.io/v1/model-training/train-classifier",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'dataset_id' => 123,
'feature_inputs' => [
[
'feature_type' => 'text',
'field_path' => 'description',
'name' => 'description_text'
],
[
'feature_type' => 'categorical',
'field_path' => 'data[\'merchant\']',
'field_type' => 'string',
'name' => 'merchant'
]
],
'label_column' => 'category',
'model_name' => 'product_category_classifier'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-dev.narrative.io/v1/model-training/train-classifier"
payload := strings.NewReader("{\n \"dataset_id\": 123,\n \"feature_inputs\": [\n {\n \"feature_type\": \"text\",\n \"field_path\": \"description\",\n \"name\": \"description_text\"\n },\n {\n \"feature_type\": \"categorical\",\n \"field_path\": \"data['merchant']\",\n \"field_type\": \"string\",\n \"name\": \"merchant\"\n }\n ],\n \"label_column\": \"category\",\n \"model_name\": \"product_category_classifier\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-dev.narrative.io/v1/model-training/train-classifier")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"dataset_id\": 123,\n \"feature_inputs\": [\n {\n \"feature_type\": \"text\",\n \"field_path\": \"description\",\n \"name\": \"description_text\"\n },\n {\n \"feature_type\": \"categorical\",\n \"field_path\": \"data['merchant']\",\n \"field_type\": \"string\",\n \"name\": \"merchant\"\n }\n ],\n \"label_column\": \"category\",\n \"model_name\": \"product_category_classifier\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-dev.narrative.io/v1/model-training/train-classifier")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"dataset_id\": 123,\n \"feature_inputs\": [\n {\n \"feature_type\": \"text\",\n \"field_path\": \"description\",\n \"name\": \"description_text\"\n },\n {\n \"feature_type\": \"categorical\",\n \"field_path\": \"data['merchant']\",\n \"field_type\": \"string\",\n \"name\": \"merchant\"\n }\n ],\n \"label_column\": \"category\",\n \"model_name\": \"product_category_classifier\"\n}"
response = http.request(request)
puts response.read_body{
"job_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}Model Training
Train a classifier
Create a job that trains a text classifier on a dataset. Only supported for datasets on Snowflake data planes.
The training data is referenced by dataset_id; the backing table is resolved server-side. Every column
reference in the request (label_column, id_column, and each feature’s field_path) is validated against the
dataset’s schema before the job is created.
POST
/
v1
/
model-training
/
train-classifier
Train a classifier
curl --request POST \
--url https://api-dev.narrative.io/v1/model-training/train-classifier \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"dataset_id": 123,
"feature_inputs": [
{
"feature_type": "text",
"field_path": "description",
"name": "description_text"
},
{
"feature_type": "categorical",
"field_path": "data['merchant']",
"field_type": "string",
"name": "merchant"
}
],
"label_column": "category",
"model_name": "product_category_classifier"
}
EOFimport requests
url = "https://api-dev.narrative.io/v1/model-training/train-classifier"
payload = {
"dataset_id": 123,
"feature_inputs": [
{
"feature_type": "text",
"field_path": "description",
"name": "description_text"
},
{
"feature_type": "categorical",
"field_path": "data['merchant']",
"field_type": "string",
"name": "merchant"
}
],
"label_column": "category",
"model_name": "product_category_classifier"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
dataset_id: 123,
feature_inputs: [
{feature_type: 'text', field_path: 'description', name: 'description_text'},
{
feature_type: 'categorical',
field_path: 'data[\'merchant\']',
field_type: 'string',
name: 'merchant'
}
],
label_column: 'category',
model_name: 'product_category_classifier'
})
};
fetch('https://api-dev.narrative.io/v1/model-training/train-classifier', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api-dev.narrative.io/v1/model-training/train-classifier",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'dataset_id' => 123,
'feature_inputs' => [
[
'feature_type' => 'text',
'field_path' => 'description',
'name' => 'description_text'
],
[
'feature_type' => 'categorical',
'field_path' => 'data[\'merchant\']',
'field_type' => 'string',
'name' => 'merchant'
]
],
'label_column' => 'category',
'model_name' => 'product_category_classifier'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api-dev.narrative.io/v1/model-training/train-classifier"
payload := strings.NewReader("{\n \"dataset_id\": 123,\n \"feature_inputs\": [\n {\n \"feature_type\": \"text\",\n \"field_path\": \"description\",\n \"name\": \"description_text\"\n },\n {\n \"feature_type\": \"categorical\",\n \"field_path\": \"data['merchant']\",\n \"field_type\": \"string\",\n \"name\": \"merchant\"\n }\n ],\n \"label_column\": \"category\",\n \"model_name\": \"product_category_classifier\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-dev.narrative.io/v1/model-training/train-classifier")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"dataset_id\": 123,\n \"feature_inputs\": [\n {\n \"feature_type\": \"text\",\n \"field_path\": \"description\",\n \"name\": \"description_text\"\n },\n {\n \"feature_type\": \"categorical\",\n \"field_path\": \"data['merchant']\",\n \"field_type\": \"string\",\n \"name\": \"merchant\"\n }\n ],\n \"label_column\": \"category\",\n \"model_name\": \"product_category_classifier\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-dev.narrative.io/v1/model-training/train-classifier")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"dataset_id\": 123,\n \"feature_inputs\": [\n {\n \"feature_type\": \"text\",\n \"field_path\": \"description\",\n \"name\": \"description_text\"\n },\n {\n \"feature_type\": \"categorical\",\n \"field_path\": \"data['merchant']\",\n \"field_type\": \"string\",\n \"name\": \"merchant\"\n }\n ],\n \"label_column\": \"category\",\n \"model_name\": \"product_category_classifier\"\n}"
response = http.request(request)
puts response.read_body{
"job_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}{
"error": "Unauthorized",
"error_description": "You are not authorized to use this endpoint."
}Authorizations
Body
application/json

