include_text_kernels.h#
-
namespace onnx_light
Alias that makes onnx-light headers compatible with code that references
ONNX_LIGHT_NAMESPACE(the macro used in the standard onnx package).Set to
ONNX_LIGHT_NAMESPACEso both names resolve to the same namespace.Symbol-visibility attribute for the public onnx-light C++ API.
Defined as empty because onnx-light does not require explicit
__declspec(dllexport)or__attribute__((visibility("default")))annotations — visibility is controlled at the shared-library level. The macro is provided so that vendored ONNX headers that decorate their declarations withONNX_APIcompile without modification.Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal
onnxnamespace — rather than theONNX_NAMESPACEmacro — resolves to the onnx-light namespace. The standard onnx package lives innamespace onnx; onnx-light usesonnx_light(via ONNX_LIGHT_NAMESPACE), so this alias keeps onnx-light a true drop-in. It is only introduced when the onnx-light namespace differs fromonnx.-
namespace onnx_kernels
-
namespace kernel
-
class RegexFullMatch : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_text_kernels.h>
Reference implementation of the
RegexFullMatchoperator (ai.onnx, since opset 20).Performs an element-wise full-match regex test on a
tensor(string)input and produces atensor(bool)output with the same shape. The regex pattern is provided either as thepatternattribute on the underlying node or directly tooperator()as astd::string.The ONNX specification references the
RE2 <>_ regex syntax. This reference kernel does not link against RE2; it uses the C++ standard library’s ECMAScript regex grammar (std::regex_match), which is sufficient for the common constructs exercised by the upstream backend tests (anchors, character classes, alternation, quantifiers, and groups). Patterns that rely on RE2-specific syntax not supported bystd::regexwill throwstd::invalid_argument.Public Functions
-
Tensor operator()(const Tensor &x, const std::string &pattern) const#
Allocating overload. Returns a freshly allocated
tensor(bool)with the same shape asx. Each output byte is1when the corresponding input string is fully matched bypatternand0otherwise.
-
void operator()(const Tensor &x, const std::string &pattern, Tensor &output) const#
In-place overload.
outputmust already be atensor(bool)with the same shape asxand a pre-sizeddatabuffer ofx.element_count()bytes.
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output bytes depend on the input contents and on the regex pattern; the output buffer cannot safely alias the input
string_databuffer (different layout / element size).
-
Tensor operator()(const Tensor &x, const std::string &pattern) const#
-
class StringConcat : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_text_kernels.h>
Element-wise concatenation of two
tensor(string)inputs with NumPy-style bidirectional broadcasting.Public Functions
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
Output bytes depend on both inputs, so the output buffer cannot safely alias either input buffer.
-
inline explicit KernelBase(const KernelContext &ctx)#
-
class StringNormalizer : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_text_kernels.h>
Reference implementation of the
StringNormalizeroperator (ai.onnx, since opset 10). Removes elements found instopwordsfrom the input string tensor (case-sensitively or not) and applies the requestedcase_change_action("LOWER","UPPER"or"NONE") to the surviving elements.Accepts only
[C]-shaped or[1, C]-shapedtensor(string)inputs. When every element is dropped, the output is a single empty string with shape[1](for[C]input) or[1, 1](for[1, C]input).Case folding and comparison use the
"C"locale (ASCII): thelocaleattribute, when present, is ignored. This matches the behavior of the upstream onnx reference implementation, which only supports the"en_US"-equivalent ASCII semantics.Public Types
Public Functions
-
Tensor operator()(const Tensor &x, CaseChangeAction case_change_action = CaseChangeAction::kNone, bool is_case_sensitive = false, const std::vector<std::string> &stopwords = {}) const#
Allocating overload.
stopwordsmay be empty.
-
void operator()(const Tensor &x, CaseChangeAction case_change_action, bool is_case_sensitive, const std::vector<std::string> &stopwords, Tensor &output) const#
In-place overload.
outputmust be atensor(string)with the shape returned by :cpp:func:ComputeOutputShapeand with a matching number of pre-allocated entries instring_data.
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static CaseChangeAction ParseCaseChangeAction(const std::string &value)#
Converts the string form of the
case_change_actionattribute ("NONE","LOWER"or"UPPER") into the matching enumerator. Throwsstd::invalid_argumentfor any other value.
-
static std::vector<int64_t> ComputeOutputShape(const std::vector<int64_t> &input_shape, int64_t kept)#
Computes the output shape given the input shape and the number of surviving (non-stopword) elements. Encapsulates the
[C] → [max(1, kept)]/[1, C] → [1, max(1, kept)]rule.
-
static inline constexpr bool CanRunInPlace() noexcept#
Output bytes depend on the input contents and on the
stopwordsset; the output buffer cannot safely alias the input buffer.
-
Tensor operator()(const Tensor &x, CaseChangeAction case_change_action = CaseChangeAction::kNone, bool is_case_sensitive = false, const std::vector<std::string> &stopwords = {}) const#
-
class StringSplit : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_text_kernels.h>
Reference implementation of the
StringSplitoperator (ai.onnx, since opset 20).Splits each element of the input
tensor(string)according to thedelimiterattribute and returns:Y— a padded string tensor whose shape isinput.shape + [M], whereMis the maximum number of substrings produced by any input element;Z— anINT64tensor of shapeinput.shapestoring the number of substrings produced for each input element.
When
delimiteris empty, the operator follows the ONNX reference semantics and splits on consecutive whitespace.Public Functions
-
std::pair<Tensor, Tensor> operator()(const Tensor &x, const std::string &delimiter = "", int64_t maxsplit = -1) const#
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static inline constexpr bool CanRunInPlace() noexcept#
-
class TfIdfVectorizer : public onnx_light::onnx_kernels::kernel::KernelBase#
- #include <include_text_kernels.h>
Reference implementation of the
TfIdfVectorizeroperator (ai.onnx, since opset 9).Extracts n-grams from a
[C]- or[N, C]-shaped integer (tensor(int32)ortensor(int64)) or string (tensor(string)) input and produces atensor(float)count ("TF") / weight ("IDF"/"TFIDF") vector with last dimensionmax(ngram_indexes) + 1.The kernel parameters mirror the operator attributes:
mode— one of"TF","IDF"or"TFIDF".min_gram_length/max_gram_length— inclusive range of n-gram sizes to extract.max_skip_count— maximum number of tokens to skip between consecutive elements of an n-gram (skip_distanceranges from 1 tomax_skip_count + 1).ngram_counts— starting offsets of 1-grams, 2-grams, … in the pool (CSR-style).ngram_indexes— output coordinate of each pool entry (parallel topool_*).pool_int64sorpool_strings— exactly one must be set; the type of the active pool must match the input dtype.weights— optional per-output weight; defaults to all ones whenIDF/TFIDFis selected andweightsis empty.
Public Types
-
enum class Mode#
Weighting criteria. Matches the
modeattribute of theTfIdfVectorizeroperator.Values:
-
enumerator kTF#
-
enumerator kIDF#
-
enumerator kTFIDF#
-
enumerator kTF#
Public Functions
-
Tensor operator()(const Tensor &x, Mode mode, int64_t min_gram_length, int64_t max_gram_length, int64_t max_skip_count, const std::vector<int64_t> &ngram_counts, const std::vector<int64_t> &ngram_indexes, const std::vector<int64_t> &pool_int64s, const std::vector<std::string> &pool_strings, const std::vector<float> &weights) const#
Allocating overload.
pool_int64smust be non-empty whenxis an integer tensor;pool_stringsmust be non-empty whenxis a string tensor.weightsmay be empty (treated as all-ones forIDF/TFIDF).
-
void operator()(const Tensor &x, Mode mode, int64_t min_gram_length, int64_t max_gram_length, int64_t max_skip_count, const std::vector<int64_t> &ngram_counts, const std::vector<int64_t> &ngram_indexes, const std::vector<int64_t> &pool_int64s, const std::vector<std::string> &pool_strings, const std::vector<float> &weights, Tensor &output) const#
In-place overload.
outputmust already be atensor(float)with the shape returned by :cpp:func:ComputeOutputShapeand a pre-sizeddatabuffer.
-
inline explicit KernelBase(const KernelContext &ctx)#
Public Static Functions
-
static Mode ParseMode(const std::string &value)#
Parses the string form of the
modeattribute ("TF","IDF"or"TFIDF"). Throwsstd::invalid_argumentfor any other value.
-
static std::vector<int64_t> ComputeOutputShape(const std::vector<int64_t> &input_shape, int64_t output_size)#
Computes the output shape of a TfIdfVectorizer node given the input shape and the size of the
ngram_indexesattribute. Input rank must be 1 or 2.
-
static inline constexpr bool CanRunInPlace() noexcept#
Output values depend on every input element and on the entire pool; the output buffer cannot safely alias the input buffer (different dtype / shape).
-
class RegexFullMatch : public onnx_light::onnx_kernels::kernel::KernelBase#
-
namespace kernel
-
namespace onnx_kernels