deepjavalibrary / djl

An Engine-Agnostic Deep Learning Framework in Java
https://djl.ai
Apache License 2.0
4.09k stars 650 forks source link

ai.djl.repository.zoo.ModelNotFoundException: No model with the specified URI or the matching Input/Output type is found. #2783

Open josephykwang opened 1 year ago

josephykwang commented 1 year ago

Description

following https://github.com/deepjavalibrary/djl/blob/master/extensions/tokenizers/README.md

for Use DJL HuggingFace model converter (experimental)

public void setup() {
    Criteria<QAInput, String> criteria =
        Criteria.builder()
            .setTypes(QAInput.class, String.class)
            .optModelPath(
                Paths.get(
                    "myproject/src/test/resources/roberta-base-squad2.zip"))
            .optProgress(new ProgressBar())
            .build();
    try {
      model = criteria.loadModel();
    } catch (IOException ex) {
      System.out.println(ex.toString());
    } catch (ModelNotFoundException ex2) {
      System.out.println(ex2.toString());
    } catch (MalformedModelException ex3) {
      System.out.println(ex3.toString());
    }
  }

also tried https://huggingface.co/deepset/roberta-base-squad2. hit with the same issue

Expected Behavior

able to load the model and the following code should run.


  String question = "When did BBC Japan start broadcasting?";
  String paragraph =
      "BBC Japan was a general entertainment Channel. "
          + "Which operated between December 2004 and April 2006. "
          + "It ceased operations after its Japanese distributor folded.";
  QAInput input = new QAInput(question, paragraph);

public void checkInference() {
    assertNotNull(model);

    Predictor<QAInput, String> predictor = model.newPredictor();
    assertNotNull(predictor);

    try {
      String result = predictor.predict(input);
      assertEquals(result, "December 2004");
    } catch (TranslateException ex) {

    }
  }

Error Message

(Paste the complete error message, including stack trace.)

How to Reproduce?

(If you developed your own code, please provide a short script that reproduces the error. For existing examples, please provide link.)

Steps to reproduce

run the test

What have you tried to solve it?

tried different model. tried unzip and used bert-base-cased-squad2.pt for path

zachgk commented 1 year ago

You need to provide a translator in the criteria. This may depend on the specific model you are using. You can try using our MxBertQATranslator, PtBertQATranslator, or hf tokenizer QuestionAnswerTranslator as a reference