Beginner assistance - input tensors

how do I create tensors for the following input in an ONNX file:
image

I want to rephrase,
I tried this:

 private void OnEnable()
    {
        runtimeModel = ModelLoader.Load(modelAsset);
        engine = WorkerFactory.CreateWorker(BackendType.CPU, runtimeModel);
        inputs = new Dictionary<string, Tensor>
        {
            {"unique_ids_raw_output___9", TensorInt.Zeros(new TensorShape(60))},
            {"segment_ids",  new TensorInt(new TensorShape(20, 256),new int[20 * 256], 0)},
            {"input_mask",  new TensorInt(new TensorShape(20, 256),new int[20 * 256], 0)},
            {"input_ids",  new TensorInt(new TensorShape(20, 256),new int[20 * 256], 0)}
        };
        Debug.Log(runtimeModel.inputs[1].shape);
    }

    private void Update()
    {
        if (!started)
        {
            modelEnumerator = engine.StartManualSchedule(inputs);
            started = true;
        }
        if (hasMoreModelToRun)
        {
            
            hasMoreModelToRun = modelEnumerator.MoveNext();
        }
        else
        {
            foreach (var outputName in runtimeModel.outputs)
            {
                TensorFloat outputTensor = engine.PeekOutput(outputName) as TensorFloat;
                outputTensor.MakeReadable();
                outputTensor.PrintDataPart(10);
            }
        }
    }

    private void OnDisable()
    {
        engine.Dispose();
        foreach (var tensor in inputs.Values)
        {
            tensor.Dispose();
        }
    }

and I get this error on the MoveNext() Line (it also happens when I try a simple execute() method)
NullReferenceException: Object reference not set to an instance of an object
Unity.Sentis.CPUBackend.MatMul (Unity.Sentis.TensorFloat X, Unity.Sentis.TensorFloat Y) (at ./Library/PackageCache/com.unity.sentis@1.1.1-exp.2/Runtime/Core/Backends/CPU/BurstCPU.Backend.cs:87)
Unity.Sentis.Layers.MatMul.Execute (Unity.Sentis.Tensor inputTensors, Unity.Sentis.ExecutionContext ctx) (at ./Library/PackageCache/com.unity.sentis@1.1.1-exp.2/Runtime/Core/Layers/Layer.Math.cs:435)
Unity.Sentis.GenericWorker+d__33.MoveNext () (at ./Library/PackageCache/com.unity.sentis@1.1.1-exp.2/Runtime/Core/Backends/GenericWorker.cs:234)
model.Update () (at Assets/model.cs:43)

You are doing it right, I think the problem might be nastier and related to int matmuls.
Could you share your model?

I think it might be tokenizing?
the model is BERT-Squad

humm that’s curious. We have Bert-Squad in our test set.
Let me see if I can reproduce with your input code

I took a look at the model, you are doing everything correct.

The problem is a bug in our OneHot implementation. We will get a fix in the next version of Sentis. It is internally known as issue 142.

2 Likes

thanks for the reassurance,

is there a similar model that should work? I need a simple contextual model

This should be working in 1.2.0 which is now available, please let us know if that helps.