Will this model be updated for Sentis 2.0.0?

#1
by IainTotem - opened

Hi, I rather like how this model works but I don't understand AI models well enough to know how to adapt it for Sentis 2.0.0 myself. Will there be an official update soon?

If not, would anyone be able to help me rewrite the sample code to work with Sentis 2.0.0? I've managed to follow the upgrade guide for almost the entire script, but I'm stuck on the Functional.Compile() bits as I don't understand how to rewrite the inputs for the new FunctionalGraph() approach. The bits I'm stuck on are:

    Model modelWithMeanPooling = Functional.Compile(
      (input_ids, attention_mask, token_type_ids) =>
      {
          var tokenEmbeddings = model.Forward(input_ids, attention_mask, token_type_ids)[0];
          return MeanPooling(tokenEmbeddings, attention_mask);
      },
      (model.inputs[0], model.inputs[1], model.inputs[2])
    );

and

    Model dotScoreModel = Functional.Compile(
        (input1, input2) => Functional.ReduceSum(input1 * input2, 1),
        (InputDef.Float(new TensorShape(1, FEATURES)),
        InputDef.Float(new TensorShape(1, FEATURES)))
    );

Any help/guidance would be sincerely appreciated!

This seems to be the way now.

Worker CreateDotScoreModel()
        {
            FunctionalGraph functionalGraph = new FunctionalGraph();
            FunctionalTensor input1 = functionalGraph.AddInput<float>(new TensorShape(1, FEATURES));
            FunctionalTensor input2 = functionalGraph.AddInput<float>(new TensorShape(1, FEATURES));

            FunctionalTensor reduce = Functional.ReduceSum(input1 * input2, 1);

            Model dotScoreModel = functionalGraph.Compile(reduce);

            return new Worker(dotScoreModel, backend);
        }
        Worker CreateMLModel()
        {
            Model model = ModelLoader.Load(Application.streamingAssetsPath + "/MiniLMv6.sentis");

            FunctionalGraph graph = new FunctionalGraph();
            FunctionalTensor[] inputs = graph.AddInputs(model);
            FunctionalTensor[] outputs = Functional.Forward(model, inputs);

            FunctionalTensor meanPooled = MeanPooling(outputs[0], inputs[1]);

            var modelWithMeanPooling = graph.Compile(meanPooled);
            return new Worker(modelWithMeanPooling, backend);
        }

This seems to be the way now.

Worker CreateDotScoreModel()
        {
            FunctionalGraph functionalGraph = new FunctionalGraph();
            FunctionalTensor input1 = functionalGraph.AddInput<float>(new TensorShape(1, FEATURES));
            FunctionalTensor input2 = functionalGraph.AddInput<float>(new TensorShape(1, FEATURES));

            FunctionalTensor reduce = Functional.ReduceSum(input1 * input2, 1);

            Model dotScoreModel = functionalGraph.Compile(reduce);

            return new Worker(dotScoreModel, backend);
        }
        Worker CreateMLModel()
        {
            Model model = ModelLoader.Load(Application.streamingAssetsPath + "/MiniLMv6.sentis");

            FunctionalGraph graph = new FunctionalGraph();
            FunctionalTensor[] inputs = graph.AddInputs(model);
            FunctionalTensor[] outputs = Functional.Forward(model, inputs);

            FunctionalTensor meanPooled = MeanPooling(outputs[0], inputs[1]);

            var modelWithMeanPooling = graph.Compile(meanPooled);
            return new Worker(modelWithMeanPooling, backend);
        }

Similar to what I have, however my output is always 0 even given the default inputs. Can you share your thought on what my current issues may be? I tried your code and it still returned 0.

Sign up or log in to comment