TypeError:add():参数“ other”(位置1)必须为张量,而不是矩阵

时间:2019-12-19 00:20:31

标签: matrix pytorch google-colaboratory tensor fast-ai

我正在经历这个tutorial。这是GitHub link。我正在使用Google Colab。

我在“ model_forward_pass”中遇到问题。 具体在这里:

from functions import LSTM
lstm  = LSTM(embedding, lm_wgts_wiki, 1150)
st_lstm = LSTM.stacked(lstm)
print(st_lstm.hidden_state_l2)
st_lstm.hidden_state_l2.shape

这是我遇到的错误:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-d5e390384560> in <module>()
      1 from functions import LSTM
      2 lstm  = LSTM(embedding, lm_wgts_wiki, 1150)
----> 3 st_lstm = LSTM.stacked(lstm)
      4 print(st_lstm.hidden_state_l2)
      5 st_lstm.hidden_state_l2.shape

1 frames
/content/drive/My Drive/Colab Notebooks/SIS_ULMFiT-master/functions.ipynb in stacked(self)
     66     "        texts = f'\\n{BOS} ' + df[n_lbls].astype(str)\n",
     67     "        for i in range(n_lbls+1, len(df.columns)): \n",
---> 68     "            texts += df[i].astype(str)\n",
     69     "        texts = texts.apply(Prep.cleaning).values.astype(str)\n",
     70     "        tok = Tokenizer().proc_all_mp(partition_by_cores(texts))\n",

/content/drive/My Drive/Colab Notebooks/SIS_ULMFiT-master/functions.ipynb in single(input, wgts, nh, stage)
     48     "class Prep:\n",
     49     "    \n",
---> 50     "    def __init__(self, tweet, label, vocab):\n",
     51     "        self.tweet = tweet\n",
     52     "        self.label = label\n",

TypeError: add(): argument 'other' (position 1) must be Tensor, not matrix

我该如何解决?

0 个答案:

没有答案