robrua / easy-bert

A Dead Simple BERT API for Python and Java (https://github.com/google-research/bert)
MIT License
170 stars 44 forks source link

Java API model.json not found #10

Closed hrzafer closed 4 years ago

hrzafer commented 4 years ago

I downloaded and extracted a model but there is no model.json inside the folder.

Exception in thread "main" java.lang.RuntimeException: java.io.FileNotFoundException: F:\Desktop\aa\bert\bert-multi-cased\assets\model.json (The system cannot find the file specified)
    at com.robrua.nlp.bert.Bert.load(Bert.java:149)
    at com.robrua.nlp.bert.Bert.load(Bert.java:132)
    at BertTest.main(BertTest.java:8)
Caused by: java.io.FileNotFoundException: F:\Desktop\aa\bert\bert-multi-cased\assets\model.json (The system cannot find the file specified)
    at java.base/java.io.FileInputStream.open0(Native Method)
    at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
    at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
    at com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:766)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2902)
    at com.robrua.nlp.bert.Bert.load(Bert.java:147)
    ... 2 more
robrua commented 4 years ago

Did you download the model from tfhub or the jar on maven central? The tfhub models need to be converted before they can be used by the Java bindings. You can do this using the bert download command after installing the python tools, or you can use the pre-converted models on maven central. It's easiest to pull those in through maven as described here.

roncking commented 4 years ago

I'm having the same issue. I used the jar from maven central, and there is no model.json file. What's the solution?

robrua commented 4 years ago

So the model itself is inside an an uncompressed ZIP inside the JAR. To get at the model resources directly you can unzip the model (named bert-uncased-L-12-H-768-A-12 or similar) inside the com/robrua/nlp/easy-bert/ directory once you've unpacked the JAR.

roncking commented 4 years ago

I don't see a model.json file here? image

robrua commented 4 years ago

It's in the bert-multi-cased-L-12-H-768-A-12 archive you're highlighting in that image. Unzip that.

roncking commented 4 years ago

Thank you.

roncking commented 4 years ago

Oh, now I can load a model! What's a good tutorial on using Bert? I don't have a clue for what to do next!

Thanks

On Wed, Apr 29, 2020 at 1:12 PM Torres0521 notifications@github.com wrote:

It's in the bert-multi-cased-L-12-H-768-A-12 archive you're highlighting in that image. Unzip that.

how to unzip that?it's not a zip file?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/robrua/easy-bert/issues/10#issuecomment-621376234, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASYN45OVP3ELRRF6KSULILRPBUX5ANCNFSM4J77DJ6Q .

-- Fear is a reaction, courage a decision - Winston Churchill

diptenduLF commented 2 years ago

Did you download the model from tfhub or the jar on maven central? The tfhub models need to be converted before they can be used by the Java bindings. You can do this using the bert download command after installing the python tools, or you can use the pre-converted models on maven central. It's easiest to pull those in through maven as described here.

Hello,

"You can do this using the bert download command after installing the python tools".

Can you please provide a little more details about how to convert the tfhub models.

Thank you.