Can not load the safetensors huggingface model in DJL in Java - Stack Overflow

I tried a lot, but I want to read embeddings from the jina embeddingsthis is my java code:public stat

I tried a lot, but I want to read embeddings from the jina embeddings

this is my java code:

public static float[] getTextEmbedding(String text) throws ModelNotFoundException, MalformedModelException, IOException, TranslateException {
        Criteria<String, float[]> criteria = Criteria.builder()
                .setTypes(String.class, float[].class)
                .optEngine("PyTorch")
                .optModelPath(Paths.get("/jina-embeddings-v2-base-de"))
                .optTranslator(
                    TextEmbeddingTranslator
                        .builder(HuggingFaceTokenizer.newInstance(Paths.get("/jina-embeddings-v2-base-de")))
                        .build()
                )
                .optProgress(new ProgressBar())
                .optOption("trust_remote_code", "true")
                .build();

        try (Predictor<String, float[]> predictor = ModelZoo.loadModel(criteria).newPredictor()) {
            return predictor.predict(text);
        }
    }

but I keept getting this error:

java.io.FileNotFoundException: jina-embeddings-v2-base-de.pt file not found in: /jina-embeddings-v2-base-de

I tried a lot, but I want to read embeddings from the jina embeddings

this is my java code:

public static float[] getTextEmbedding(String text) throws ModelNotFoundException, MalformedModelException, IOException, TranslateException {
        Criteria<String, float[]> criteria = Criteria.builder()
                .setTypes(String.class, float[].class)
                .optEngine("PyTorch")
                .optModelPath(Paths.get("/jina-embeddings-v2-base-de"))
                .optTranslator(
                    TextEmbeddingTranslator
                        .builder(HuggingFaceTokenizer.newInstance(Paths.get("/jina-embeddings-v2-base-de")))
                        .build()
                )
                .optProgress(new ProgressBar())
                .optOption("trust_remote_code", "true")
                .build();

        try (Predictor<String, float[]> predictor = ModelZoo.loadModel(criteria).newPredictor()) {
            return predictor.predict(text);
        }
    }

but I keept getting this error:

java.io.FileNotFoundException: jina-embeddings-v2-base-de.pt file not found in: /jina-embeddings-v2-base-de
Share Improve this question asked Nov 16, 2024 at 0:04 Richard BurkhardtRichard Burkhardt 8839 silver badges25 bronze badges 2
  • What files are there in your /jina-embeddings-v2-base-de folder? Can you try to convert the model using djl-convert – Frank Liu Commented Dec 3, 2024 at 6:52
  • Converting would work, but since I want to experiment with different models, I hoped I could somehow get it to work like this. The base folder is basically the repo, which is linked in my post. – Richard Burkhardt Commented Dec 4, 2024 at 11:28
Add a comment  | 

1 Answer 1

Reset to default 0

djl-convert can convert local model into DJL format as well:

djl-convert -m /jina-embeddings-v2-base-de

Then you can point to model/jina-embeddings-v2-base-de folder in Java code. You will find the following files in the folder:

  • jina-embeddings-v2-base-de.pt
  • config.json
  • serving.properties
  • tokenizer_config.json
  • tokenizer.json

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745670392a4639368.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信