How to ask questions using all-MiniLM-L6-V2?

mc 7,361 Reputation points
2026-09-10T07:26:58.4466667+00:00

I am using .net android and how to ask questions using Microsoft.ML.Tokenizers?

I have get InferenceSession and I do not know how to do it?

the repo:https://github.com/ljzj2/XMedicalAndroid

there will be error when I run _session.Run(inputs);

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 85,281 Reputation points
    2026-09-10T14:59:52.95+00:00

    all-MiniLM-L6-V2 is not a text generator (chat). It’s a tokenizer of input for sentence transformer libraries. It’s takes a text sentence and produces a vector space. See:

    https://www.sbert.net

    The use case is typically comparing two sentences, for grouping or search algorithms.

    Note: the model supports up to 512 tokens input (most words are multiple tokens, so about 380 words)

    Was this answer helpful?

    0 comments No comments

  2. Nguyen Dam (WICLOUD CORPORATION) 160 Reputation points Microsoft External Staff Moderator
    2026-09-10T08:37:01.2633333+00:00

    Thank you for your question. 

    This appears to be the same topic as your previous thread. I have already provided guidance there on loading the model, generating embeddings, and integrating all-MiniLM-L6-v2 into a .NET MAUI Android application. With that in mind, I would like to add the following comments based on the code shared here. 

    Regarding the error at _session.Run(inputs), based on the code you shared, one possible cause is that the ONNX model expects additional input tensors that are not being provided. Many BERT-based models, including all-MiniLM-L6-v2 variants, commonly require inputs such as attention_mask and, in some cases, token_type_ids in addition to input_ids

    For example: 

    var inputs = new List 
    { 
        NamedOnnxValue.CreateFromTensor("input_ids", idTensor), 
        NamedOnnxValue.CreateFromTensor("attention_mask", attentionMaskTensor), 
        NamedOnnxValue.CreateFromTensor("token_type_ids", tokenTypeIdsTensor) 
    }; 
    using var results = _session.Run(inputs); 
    

    The exact input names and required tensors depend on the ONNX model you are using. You may want to inspect the model inputs (for example, through _session.InputMetadata) and compare them against the tensors being supplied before calling _session.Run()

    Please continue in the original thread and share the complete exception message together with the model input metadata if the issue persists. 

     

    If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation.  

    Thank you.  

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.