allenai / bilm-tf

Tensorflow implementation of contextualized word representations from bi-directional language models
Apache License 2.0
1.62k stars 452 forks source link

question: my trained model gives output dictionary with different fields from those from the tf.hub model #193

Closed amttar closed 5 years ago

amttar commented 5 years ago

When using pre-trained models, I get an output dictionary different from the output dictionary explained in the published tf.hub model My output dictionary's signature is

> model = BidirectionalLanguageModel(options_file, weight_file)
> ops = model(ids_placeholder)
> print (ops)
{'token_embeddings': <tf.Tensor 'bilm/Reshape_1:0' shape=(?, ?, 512) dtype=float32>, 
'lengths': <tf.Tensor 'sub:0' shape=(?,) dtype=int32>, 
'mask': <tf.Tensor 'Cast_1:0' shape=(?, ?) dtype=bool>, 
'lm_embeddings': <tf.Tensor 'concat_3:0' shape=(?, 3, ?, 1024) dtype=float32>}

while the output dictionary from tf hub contains:

how can I access the word_emb, lstm_outputs1, lstm_outputs2 .. fields in the output dictionary? I am following the usage example to cache a dataset from this link

matt-peters commented 5 years ago

lm_embeddings holds the embeddings for all layers, starting with word embeddings at the lowest layer.

word_emb = ops['lm_embeddings'][:, 0, :, :512]    # word embeddings are duplicated for forward/backward
lstm_outputs1 = ops['lm_embeddings'][:, 1, :, :]
lstm_outputs2 = ops['lm_embeddings'][:, 2, :, :]
amttar commented 5 years ago

Thanks @matt-peters for the clarification, where is this info listed?