Equivalent of allennlp.commands.elmo in Allennlp v0.8.4 for version 2.10.0

116 views Asked by At

I'm using a Python library as a dependency of my app, which imports Allennlp v0.8.4. The library uses ElmoEmbedder class for getting tokenised word embeddings with its batch_to_embeddings() function as follows:

 elmo = ElmoEmbedder(options, weight, cuda_device)
 embedding, mask = elmo.batch_to_embeddings(tokened_sentences)

Since using an old version of Allennlp would affect my entire application, I want to modify the imported library so as to keep it working. So, how can I keep the same functionality for Allennlp v2.10.0?

1

There are 1 answers

0
Dirk Groeneveld On

I'm afraid there isn't a 1:1 equivalent to that function. The best you can do is figure out how https://demo.allennlp.org/reading-comprehension/bidaf-elmo does it, and do the same thing in your code.

The config for that model will specify a few token indexers and embedders. You can specify the same thing directly in code if you want to emulate how batch_to_embeddings() worked. You don't have to use a config file.