简体   繁体   English

Keras中的双向LSTM句子填空

[英]Fill in the blank in sentences with bidirectional LSTM in Keras

I'm currently studying RNN, in particular LSTM and I was trying to figure out how to implement a bidirectional LSTM to fill in the missing word in a sentence.我目前正在研究 RNN,特别是 LSTM,我试图弄清楚如何实现双向 LSTM 来填补句子中缺失的单词。 I have a doubt about the strucuture of the train set to be passed to the fit method of the model.我对要传递给 model 的拟合方法的火车组的结构有疑问。 If my list of sentences is composed by elements like this: "HI GUYS, <MISSING> ARE YOU?"如果我的句子列表是由这样的元素组成的:“HI GUYS,<MISSING> ARE YOU?” and my target label is "HOW", how could the BI-LSTM understand that it has to predict the missing value and not the next element of the sentence?而我的目标 label 是“HOW”,BI-LSTM 怎么能理解它必须预测缺失值而不是句子的下一个元素? I saw here that the advantage of a bidirectional LSTM is the ability to look in both past and future tokens to get information about the context and better predict the target, but I still don't get how to implement this in practice.我在这里看到双向 LSTM 的优点是能够查看过去和未来的标记以获取有关上下文的信息并更好地预测目标,但我仍然不知道如何在实践中实现这一点。 So my questions are:所以我的问题是:

  1. what is the structure of my train set?我的火车组的结构是什么?
  2. Does the BI-LSTM know what token to predict or do I have to specify it? BI-LSTM 是否知道要预测什么标记,还是我必须指定它? And how?如何?

how could the BI-LSTM understand that it has to predict the missing value and not the next element of the sentence? BI-LSTM 如何理解它必须预测缺失值而不是句子的下一个元素?

If you train it to, then it should "understand" what you want it to do.如果你训练它,那么它应该“理解”你想要它做什么。

  1. Your train set would be the list of words in the sentence (in the correct order) without the missing word.您的训练集将是句子中的单词列表(以正确的顺序),没有丢失的单词。 You can also choose to replace the missing word with a missing-word token , that way the model as one less task to do.您还可以选择用缺失词标记替换缺失的单词,这样 model 就少了一项任务。 Honestly, there are a lot of ways to do this.老实说,有很多方法可以做到这一点。 The y will be the missing word. y将是缺失的单词。

  2. I don't really understand what you mean here but I believe I have already answered it in the first answer.我不太明白你在这里的意思,但我相信我已经在第一个答案中回答了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM