djl icon indicating copy to clipboard operation
djl copied to clipboard

use the gte model generate embedding

Open g5zhu5896 opened this issue 6 months ago • 2 comments

Issue Description: i use the gte model generate embedding ,but get a error like the following

Image

the gte model download from https://www.modelscope.cn/iic/nlp_gte_sentence-embedding_chinese-large.git

my code:

` {

   public static void main(String[] args) {
    String text = "This is an example sentence";

    Criteria<String, float[]> criteria =
            Criteria.builder()
                    .setTypes(String.class, float[].class)
                    .optModelPath(Paths.get("nlp_gte_sentence-embedding_chinese-large"))
                    .optEngine("PyTorch")
                    .optOption("mapLocation", "true")
                    .optTranslatorFactory(new TextEmbeddingTranslatorFactory())
                    .optProgress(new ProgressBar())
                    .optModelName("pytorch_model.bin")
                    .build();

    try (ZooModel<String, float[]> model = criteria.loadModel();
         Predictor<String, float[]> predictor = model.newPredictor()) {
        float[] res = predictor.predict(text);
        System.out.println("Embedding: " + Arrays.toString(res));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

`

my pom.xml:

Image

the djl pytorch env config: Image

and i use the python run the gte model,run successs,the following is the python code

Image

g5zhu5896 avatar May 23 '25 08:05 g5zhu5896