如何将数据提供给TensorFlow中的LSTM单元以进行多类分类?

时间:2017-09-18 08:27:27

标签: python tensorflow lstm rnn

我有一个单行句子的数据集,每个句子都属于一个基于上下文的类。我创建了一个重要单词的词典,并将我的输入数据转换为一个特征列表,其中每个特征都是词典长度的向量。 我想将这些数据输入到动态LSTM单元格中,但无法弄清楚如何重塑它。 考虑我的batch_size = 100,length_lexicon = 64,nRows_Input = 1000

1 个答案:

答案 0 :(得分:0)

为什么不使用numpy.reshape? 查看此文档:https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html

例如: >>> a = np.arange(6).reshape((3, 2)) >>> a array([[0, 1],        [2, 3],        [4, 5]])

  

numpy.reshape¶

     

numpy.reshape(a,newshape,order ='C')

Gives a new shape to an array without changing its data.
Parameters:   

a : array_like

    Array to be reshaped.

newshape : int or tuple of ints

    The new shape should be compatible with the original shape. If an integer, then the result will be a 1-D array of that length. One
     

形状尺寸可以是-1。在这种情况下,该值是从中推断出来的   数组的长度和剩余的尺寸。

order : {‘C’, ‘F’, ‘A’}, optional

    Read the elements of a using this index order, and place the elements into the reshaped array using this index order. ‘C’ means to
     

使用类似C的索引顺序读取/写入元素,使用最后一个轴   索引变化最快,回到第一轴索引变化最慢。   'F'表示使用类似Fortran的索引顺序读/写元素,   第一个索引变化最快,最后一个索引变化   最慢的。请注意,'C'和'F'选项不考虑   底层数组的内存布局,只参考顺序   索引。 'A'表示读取/写入类似Fortran的索引中的元素   如果a是Fortran在内存中是连续的,那么顺序就是C-like命令。

Returns:  

reshaped_array : ndarray

    This will be a new view object if possible; otherwise, it will be a copy. Note there is no guarantee of the memory layout (C- or
     

Fortran-contiguous)返回的数组。