clab / clab/dynet

inputTensor() Problem

Open
#1,306 0 comments 0 reactions 0 assignees View on GitHub
moderate bug
Dominant language
C++
Stars
3.4k
Forks
701
PR merge metrics
No merged PRs in 30d

Description

Since `dynet.matInput` and `dynet.inputMatrix` are marked as DEPRECATED, `dynet.inputTensor` seems to function as the only operation for higher-order (excluding scalar and vector) tensor input.

### IN SHORT:
now it works well for dynamic computational graph, if we only call it for initial assignment; but for static computational graph or for reset tensor expression value, it still has some problem.

## About current `reusable_expr` (#1194)

`reusable_expr` is designed to enable the returned `Expression` of `inputTensor` to call `set()`, so that the returned `Expression` can play a placeholder role in a static graph.

Here `set()` is a wonderful idea (though it currently has a bug -- discussed below). However, `inputTensor` use `reusable_expr` to control; while for vector input, we have:
* `inputVector(np.ndarray arr)` for dynamic input, plus
* `vecInput(int dim)` as a placeholder which has `set()` to call;

and this seems a more natural way.

Even though people may still prefer `reusable_expr` to two separate functions, it'd be better to make identical designs for both the placeholders of `Tensor` and `Vector`.

## `.set()` bug
```
import numpy as np
import dynet as dy

W = np.random.randn(2,3)
# [[ 0.53032127 -0.24661635 0.02916484]
# [ 1.14034417 -0.85794905 0.29356377]]
dyW = dy.inputTensor(W, reusable_expr=True)
# [[ 0.5303213 -0.24661635 0.02916484]
# [ 1.14034414 -0.85794908 0.29356375]]

V = np.random.randn(2,3)
# [[-0.48587236 -1.30600176 0.46575287]
# [-0.34119798 -1.28642354 -0.86978386]]
dyW.set(V.flatten())
# [[-0.48587236 0.46575287 -1.28642356] # !!! Wrong order
# [-1.30600178 -0.341198 -0.86978388]] # !!! Wrong order
dyW.set(V.T.flatten())
# [[-0.48587236 -1.30600176 0.46575287]
# [-0.34119798 -1.28642354 -0.86978386]]
```
`dyW` is a returned `Expression` of `inputTensor`. Its `set()` can only accept "flattened" tensor (which is bad for now), and even for temporary usage it can NOT naturally set the array from numpy (as shown above).

![screen shot 2018-03-14 at 12 19 02 pm](https://user-images.githubusercontent.com/21228317/37428594-2204aa3e-27a3-11e8-8ded-cee1864d50ce.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.