OpenNMT-py icon indicating copy to clipboard operation
OpenNMT-py copied to clipboard

Retrieve NMT Encoder's output

Open brash6 opened this issue 4 years ago • 11 comments

Hi,

Assuming that I've trained a NMT with OpenNMT, how coud I retrieve the representation vector of new sequences ?

More precisely, If I trained a NMT to translate from French to English, if I want to predict the output sequence for a new French sentence, how could I also retrieve the output vector of the encoder ?

Thank you !

brash6 avatar Jun 09 '20 08:06 brash6

Hi there, This is quite similar to this post. It is not handled "as is" but it should not be too difficult to add it if you're willing to dive a bit in the code.

francoishernandez avatar Jun 09 '20 14:06 francoishernandez

Thank you for your answer, I'll post here If I manage to do it !

brash6 avatar Jun 10 '20 07:06 brash6

hi, do you manage to do it? @brash6

Marvinmw avatar Jul 03 '20 18:07 Marvinmw

Hello, not really, If you have any idea how to do it, I am interested !

brash6 avatar Jul 04 '20 09:07 brash6

Hi,

Did anybody had any success in getting the encoder representation from the trained model?

shashankg7 avatar Oct 08 '20 05:10 shashankg7

This should not be very difficult guys, if you're willing to dive a bit in the code. You can start by printing / torch.save what's happening here, after the encoder forward: https://github.com/OpenNMT/OpenNMT-py/blob/8b073fb2a047509ff590839b1194a155ec1a50bf/onmt/models/model.py#L45

Then, it's just plumbing to retrieve this at the translator level.

francoishernandez avatar Oct 08 '20 08:10 francoishernandez

Thanks for your reply.

I have mainly used it's command line tool only. Have not used the torch api. Any reference to building a transformer translation model with its pytorch api?

Pardon if I am missing anything obvious here.

On Thu, Oct 8, 2020, 1:59 PM François Hernandez [email protected] wrote:

This should not be very difficult guys, if you're willing to dive a bit in the code. You can start by printing / torch.save what's happening here, after the encoder forward:

https://github.com/OpenNMT/OpenNMT-py/blob/8b073fb2a047509ff590839b1194a155ec1a50bf/onmt/models/model.py#L45

Then, it's just plumbing to retrieve this at the translator level.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/OpenNMT/OpenNMT-py/issues/1811#issuecomment-705416630, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5VTOB6KRTPNAMYAH5MCNLSJVZ7TANCNFSM4NZGBKTQ .

shashankg7 avatar Oct 08 '20 09:10 shashankg7

You don't need to rebuild everything just to retrieve some representations. You can just edit the code and run the scripts.

francoishernandez avatar Oct 08 '20 09:10 francoishernandez

Thank you for your prompt response.

I have one more doubt. Please pardon me if my doubts appear naive.

The installed scripts will invoke the code from the installed location, right?

How do I ensure that the scripts call the changes I make in the onmt codebases' model?

shashankg7 avatar Oct 08 '20 17:10 shashankg7

Easiest is probably to git clonethe repo in the location you'd like and work from there.

francoishernandez avatar Oct 08 '20 19:10 francoishernandez

Hi @francoishernandez! Is anyone working on this issue? I want to contribute.

Shikhar-S avatar Mar 06 '21 07:03 Shikhar-S