Flair Elmo嵌入在Pytorch模型中的应用
我尝试在PyTorch模型上生成elmo嵌入,在每次批处理迭代中,如:Flair Elmo嵌入在Pytorch模型中的应用,pytorch,elmo,flair,Pytorch,Elmo,Flair,我尝试在PyTorch模型上生成elmo嵌入,在每次批处理迭代中,如: for batch in iterator: optimizer.zero_grad() embeddings = get_elmo_embeddings(batch.dataset.examples) predictions = model(embeddings).squeeze(1) target = batch.target where the get
for batch in iterator:
optimizer.zero_grad()
embeddings = get_elmo_embeddings(batch.dataset.examples)
predictions = model(embeddings).squeeze(1)
target = batch.target
where the get elmo embeddings is something like:
from flair.embeddings import StackedEmbeddings
from flair.embeddings import ELMoEmbeddings
from flair.data import Sentence
elmo_embedding = ELMoEmbeddings('original')
stacked_embeddings = StackedEmbeddings(embeddings = [elmo_embedding])
def get_elmo_embeddings(text):
flat_list = list()
for x in text:
sentence = Sentence(x.text)
stacked_embeddings.embed(sentence)
return elmo(stacked_embeddings)
为了将这些嵌入提供给模型,但问题是,对于单个批处理,创建它们需要几个小时。。我做错什么了吗?有没有关于如何改进的建议
另外,当我将它输入到模型时,它可以直接进入GRU还是需要更多的处理
谢谢大家抽出时间:)