java icon indicating copy to clipboard operation
java copied to clipboard

we need Embeddings Lookup this method

Open mullerhai opened this issue 3 years ago • 11 comments
trafficstars

Hi : I wanna to invoke tf.nn.embedding_lookup to make embedding layer ,but the java version has not these part code.please make it real work in java ? thank you ,

mullerhai avatar Feb 12 '22 10:02 mullerhai

FYI, it looks like the C++ API of PyTorch implements this functionality, which we can easily use from Java: https://github.com/bytedeco/javacpp-presets/blob/master/pytorch/src/gen/java/org/bytedeco/pytorch/EmbeddingImpl.java

saudet avatar Feb 12 '22 10:02 saudet

Hi @mullerhai , did you tried to use tf.gather instead? According to TF documentation, embedding_lookup is just a generalization of gather.

karllessard avatar Feb 12 '22 14:02 karllessard

FYI, it looks like the C++ API of PyTorch implements this functionality, which we can easily use from Java: https://github.com/bytedeco/javacpp-presets/blob/master/pytorch/src/gen/java/org/bytedeco/pytorch/EmbeddingImpl.java @karllessard @saudet Hi ,I think we can read this and implement it in our code https://github.com/eaplatanios/tensorflow_scala/blob/master/modules/api/src/main/scala/org/platanios/tensorflow/api/learn/layers/Embedding.scala

mullerhai avatar Feb 12 '22 16:02 mullerhai

If you could port that to Java, I'm sure we will want to merge this, yes.

saudet avatar Feb 13 '22 05:02 saudet

ohh , maybe let me try to do this

mullerhai avatar Feb 13 '22 15:02 mullerhai

Thanks @mullerhai ,

Again, the "happy path" of embedding_lookup (getting raw embeddings from a single tensor) can be replaced by a single call to tf.gather. But if you could write/port a wrapper that does also the fancy stuff (partitioning, norm, transform, ...), that would be certainly a great addition to our Java framework.

karllessard avatar Feb 13 '22 15:02 karllessard

Thanks @mullerhai ,

Again, the "happy path" of embedding_lookup (getting raw embeddings from a single tensor) can be replaced by a single call to tf.gather. But if you could write/port a wrapper that does also the fancy stuff (partitioning, norm, transform, ...), that would be certainly a great addition to our Java framework.

yeah, if the tf java framework has embedding look up method then we will have embedding layer, it will benefit for all users

mullerhai avatar Feb 14 '22 01:02 mullerhai

Talking of embedding layers… @JimClarke5 , is this something you have worked on as part of the first phase for layers?

karllessard avatar Feb 14 '22 23:02 karllessard

Exactly what do you mean by embedding layers? The Sequential model can contain a network of layers if that is what you mean.

I have not worked on layers for the simpler models, the plan is to get the basic model plumbing accepted, then add more layers.

Also, I have not tackled saving the model in a SavedModelBundle yet.

There is a lot of work yet for models and layers.

Jim

On Feb 14, 2022, at 6:07 PM, Karl Lessard @.***> wrote:

 Talking of embedding layers… @JimClarke5 , is this something you have worked on as part of the first phase for layers?

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.

JimClarke5 avatar Feb 15 '22 00:02 JimClarke5

Yes I was asking if you’ve already started to port the Keras embedding layer, to make sure we are not duplicating the efforts here.

karllessard avatar Feb 15 '22 18:02 karllessard

I haven’t started it. There is some plumbing for Layers you will need, like the Layer Interface and BaseLayer abstract class.

Jim

On Feb 15, 2022, at 2:00 PM, Karl Lessard @.***> wrote:

 Yes I was asking if you’ve already started to port the Keras embedding layer, to make sure we are not duplicating the efforts here.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.

JimClarke5 avatar Feb 15 '22 20:02 JimClarke5