Skip to content

[NodeJS] Error to predict using text features #2523

@tavlima

Description

@tavlima

I'm trying to use my model from NodeJS, via the catboost NPM package, but can't figure out a way to provide the text features to the predict method. Can someone please help?

import { Model } from "catboost"
const myModel = new Model('./mymodel.bin')
const prediction = myModel.predict([[-358.48]], [['Some Description', 'false']])

The predict call errors like this:

Error: NCB::NModelEvaluation::NDetail::TCpuEvaluator::Calc(TArrayRef<TArrayRef<float const> const>, TArrayRef<TArrayRef<TBasicStringBuf<char, std::__y1::char_traits<char> > const> const>, unsigned long, unsigned long, TArrayRef<double>, NCB::NModelEvaluation::TFeatureLayout const*) const+430 (0x11E88547E)
TFullModel::Calc(TArrayRef<TArrayRef<float const> const>, TArrayRef<TVector<TBasicStringBuf<char, std::__y1::char_traits<char> >, std::__y1::allocator<TBasicStringBuf<char, std::__y1::char_traits<char> > > > const>, unsigned long, unsigned long, TArrayRef<double>, NCB::NModelEvaluation::TFeatureLayout const*) const+419 (0x11EC3C903)
CalcModelPrediction+894 (0x11E8BADBE)
NNodeCatBoost::TModel::CalcPredictionString(Napi::Env, TVector<float, std::__1::allocator<float> > const&, Napi::Array const&)+2506 (0x115E3B6BA)
NNodeCatBoost::TModel::CalcPrediction(Napi::CallbackInfo const&)+2447 (0x115E3985F)
Napi::ObjectWrap<NNodeCatBoost::TModel>::InstanceMethodCallbackWrapper(napi_env__*, napi_callback_info__*)::'lambda'()::operator()() const+133 (0x115E3C955)
Napi::ObjectWrap<NNodeCatBoost::TModel>::InstanceMethodCallbackWrapper(napi_env__*, napi_callback_info__*)+42 (0x115E3C87A)
v8impl::(anonymous namespace)::FunctionCallbackWrapper::Invoke(v8::FunctionCallbackInfo<v8::Value> const&)+140 (0x104A1CBCC)
v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo)+216 (0x104C60CD8)
v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments)+555 (0x104C607AB)
v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*)+255 (0x104C5FEBF)

(TCatBoostException) catboost/libs/model/cpu/formula_evaluator.cpp:356: Model contains text features but they aren't provided
    ...
NCB::NModelEvaluation::NDetail::TCpuEv…ions (node:internal/process/task_queues:95:5)', message: 'NCB::NModelEvaluation::NDetail::TCpuEvaluato…tains text features but they aren't provided'}

FWIW, my model was trained with the following column definition:

0	Text	description
1	Label	category
2	Num	amount
3	Categ	isEnabled

And catboost dependency is locked like this:

"node_modules/catboost": {
      "version": "1.25.1",
      "resolved": "https://registry.npmjs.org/catboost/-/catboost-1.25.1.tgz",
      "integrity": "sha512-Qf0jLkBYIHfHjczkgSk+fZrSszu+foChVPwfhcj+Out6RDqOdorjh5cvv660wM2trr9++4ajwdR8PzfjP8vl1A==",
      "hasInstallScript": true,
      "dependencies": {
        "node-addon-api": "^1.1.0"
      }
    }

Finally, the model was generated using the catboost CLI for arm64:

$ catboost --version 
Git info:
    Commit: ff8f073eea240c11e49e51cb774c2df5249c157c
    Branch: heads/master
    Author: akhropov <akhropov@yandex-team.com>
    Summary: Proper ranges in parameters description
    git-svn info:
    Last Changed Rev: 9293085

Other info:
    Build by: zomb-ml-platform-msk
    Top src dir: /Users/zomb-ml-platform-msk/go-agent-21.2.0/pipelines/BuildMaster/catboost.git

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions