Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Onnxruntime SequenceInfo

From Leeroopedia


Knowledge Sources Description
Source File java/src/main/java/ai/onnxruntime/SequenceInfo.java
Repository Microsoft/onnxruntime

Domains

  • Machine Learning Runtime
  • Type Metadata

Overview

SequenceInfo describes an OnnxSequence, including its element type and length. It implements the ValueInfo interface and differentiates between sequences of tensors and sequences of maps. The class is constructed internally from JNI and by OrtSession when inspecting model outputs.

Description

The class has four public fields:

  • sequenceOfMaps: Boolean indicating whether the sequence contains maps.
  • sequenceType: The OnnxJavaType of elements (STRING, INT64, FLOAT, DOUBLE); UNKNOWN if it contains maps.
  • mapInfo: A MapInfo describing the map type if sequenceOfMaps is true; null otherwise.
  • length: The number of elements (-1 if unknown).

Four constructors exist: 1. Tensor sequence with known type: (int length, OnnxJavaType sequenceType) 2. Tensor sequence from JNI: (int length, int sequenceTypeInt) 3. Map sequence with MapInfo: (int length, MapInfo mapInfo) 4. Map sequence with key/value types: (int length, OnnxJavaType keyType, OnnxJavaType valueType)

The isSequenceOfMaps() method provides a convenience check.

Code Reference

Source Location

// File: java/src/main/java/ai/onnxruntime/SequenceInfo.java
// Package: ai.onnxruntime

Signature

public class SequenceInfo implements ValueInfo {
    public final boolean sequenceOfMaps;
    public final OnnxJavaType sequenceType;
    public final MapInfo mapInfo;
    public final int length;

    public boolean isSequenceOfMaps();
}

Import

import ai.onnxruntime.SequenceInfo;

I/O Contract

Inputs

Name Type Description
length int Number of elements (-1 if unknown)
sequenceType OnnxJavaType Element type for tensor sequences
mapInfo MapInfo Map type info for map sequences

Outputs

Name Type Description
sequenceOfMaps boolean Whether the sequence contains maps
sequenceType OnnxJavaType Element type (UNKNOWN for map sequences)
mapInfo MapInfo Map type info (null for tensor sequences)
length int Element count (-1 if unknown)

Usage Examples

import ai.onnxruntime.*;
import java.util.*;

OrtEnvironment env = OrtEnvironment.getEnvironment();
try (OrtSession session = env.createSession("/path/to/model.onnx")) {
    Map<String, NodeInfo> outputInfo = session.getOutputInfo();
    for (Map.Entry<String, NodeInfo> entry : outputInfo.entrySet()) {
        ValueInfo info = entry.getValue().getInfo();
        if (info instanceof SequenceInfo) {
            SequenceInfo seqInfo = (SequenceInfo) info;
            System.out.println("Output '" + entry.getKey() + "' is a sequence:");
            System.out.println("  Length: " + seqInfo.length);
            if (seqInfo.isSequenceOfMaps()) {
                System.out.println("  Contains maps: " + seqInfo.mapInfo);
            } else {
                System.out.println("  Element type: " + seqInfo.sequenceType);
            }
        }
    }
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment