clab / dynet

DyNet: The Dynamic Neural Network Toolkit
Apache License 2.0
3.42k stars 707 forks source link

Support for manual vector dimension value assignment of expression #1346

Open AmitMY opened 6 years ago

AmitMY commented 6 years ago

I'm trying to write a seq2seq with out-of-vocab copy, for which I create a zeros input vector in the size of the out-of-vocab tokens:

copy_vec = dy.inputVector(np.zeros(len(copy_vocab)))

But after I value each token seperately (conditional copy mechanism) and have a score for the token, I want to add to that word's scrore so I do:

copy_vec[copy_vocab.w2i[token]] += token_score

Which is deriveable as it's a sum, and should just change the expression in that dimension to be a sum of expressions, as far as I understand.

Error:

TypeError: '_dynet._vecInputExpression' object does not support item assignment

pmichel31415 commented 6 years ago

Yes this is something that isn't super easy to do right now. One solution is to compute all your token scores separately and concatenate them in copy_vec later. Not sure if that's applicable in your case.

neubig commented 6 years ago

This is something that we should add though.

AmitMY commented 6 years ago

@pmichel31415 that is my current fix, but adding that made my model train 10 times slower on cpu, 60 times slower on gpu.. not 100% sure if it’s this thing or the way I’m calculating the scores, but yeah that sucks