我正在嘗試使用 ELMo,只需將其用作更大的 PyTorch 模型的一部分。此處給出了一個基本示例。這是一個 torch.nn.Module 子類,它計算任意數量的 ELMo 表示并為每個表示引入可訓練的標量權重。例如,此代碼片段計算兩層表示(如我們論文中的 SNLI 和 SQuAD 模型):from allennlp.modules.elmo import Elmo, batch_to_idsoptions_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/2x4096_512_2048cnn_2xhighway/elmo_2x4096_512_2048cnn_2xhighway_options.json"weight_file = "https://s3-us-west-2.amazonaws.com/allennlp/models/elmo/2x4096_512_2048cnn_2xhighway/elmo_2x4096_512_2048cnn_2xhighway_weights.hdf5"# Compute two different representation for each token.# Each representation is a linear weighted combination for the# 3 layers in ELMo (i.e., charcnn, the outputs of the two BiLSTM))elmo = Elmo(options_file, weight_file, 2, dropout=0)# use batch_to_ids to convert sentences to character idssentences = [['First', 'sentence', '.'], ['Another', '.']]character_ids = batch_to_ids(sentences)embeddings = elmo(character_ids)# embeddings['elmo_representations'] is length two list of tensors.# Each element contains one layer of ELMo representations with shape# (2, 3, 1024).# 2 - the batch size# 3 - the sequence length of the batch# 1024 - the length of each ELMo vector我的問題涉及“陳述”。你能將它們與普通的 word2vec 輸出層進行比較嗎?您可以選擇將返回多少ELMo(增加第 n 維),但是這些生成的表示之間有什么區別以及它們的典型用途是什么?給你一個想法,對于上面的代碼,embeddings['elmo_representations']返回兩個項目(兩個表示層)的列表,但它們是相同的。簡而言之,如何定義 ELMo 中的“表示”?
添加回答
舉報
0/150
提交
取消