Python tensorflow.sparse_transpose() Examples

The following are 6 code examples of tensorflow.sparse_transpose(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tensorflow , or try the search function .
Example #1
Source File: sparse_ops_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def testTranspose(self):
    with self.test_session(use_gpu=False):
      np.random.seed(1618)
      shapes = [np.random.randint(1, 10, size=rank) for rank in range(1, 6)]
      for shape in shapes:
        for dtype in [np.int32, np.int64, np.float32, np.float64]:
          dn_input = np.random.randn(*shape).astype(dtype)
          rank = tf.rank(dn_input).eval()
          perm = np.random.choice(rank, rank, False)
          sp_input, unused_a_nnz = _sparsify(dn_input)
          sp_trans = tf.sparse_transpose(sp_input, perm=perm)
          dn_trans = tf.sparse_tensor_to_dense(sp_trans).eval()
          expected_trans = tf.transpose(dn_input, perm=perm).eval()
          self.assertAllEqual(dn_trans, expected_trans) 
Example #2
Source File: ctc_decoder.py    From neuralmonkey with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def decoded(self) -> tf.Tensor:
        if self.beam_width == 1:
            decoded, _ = tf.nn.ctc_greedy_decoder(
                inputs=self.logits, sequence_length=self.encoder.lengths,
                merge_repeated=self.merge_repeated_outputs)
        else:
            decoded, _ = tf.nn.ctc_beam_search_decoder(
                inputs=self.logits, sequence_length=self.encoder.lengths,
                beam_width=self.beam_width,
                merge_repeated=self.merge_repeated_outputs)

        return tf.sparse_tensor_to_dense(
            tf.sparse_transpose(decoded[0]),
            default_value=END_TOKEN_INDEX) 
Example #3
Source File: ctc_decoder.py    From neuralmonkey with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def decoded(self) -> tf.Tensor:
        if self.beam_width == 1:
            decoded, _ = tf.nn.ctc_greedy_decoder(
                inputs=self.logits, sequence_length=self.encoder.lengths,
                merge_repeated=self.merge_repeated_outputs)
        else:
            decoded, _ = tf.nn.ctc_beam_search_decoder(
                inputs=self.logits, sequence_length=self.encoder.lengths,
                beam_width=self.beam_width,
                merge_repeated=self.merge_repeated_outputs)

        return tf.sparse_tensor_to_dense(
            tf.sparse_transpose(decoded[0]),
            default_value=END_TOKEN_INDEX) 
Example #4
Source File: ctc_decoder.py    From neuralmonkey with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def decoded(self) -> tf.Tensor:
        if self.beam_width == 1:
            decoded, _ = tf.nn.ctc_greedy_decoder(
                inputs=self.logits, sequence_length=self.encoder.lengths,
                merge_repeated=self.merge_repeated_outputs)
        else:
            decoded, _ = tf.nn.ctc_beam_search_decoder(
                inputs=self.logits, sequence_length=self.encoder.lengths,
                beam_width=self.beam_width,
                merge_repeated=self.merge_repeated_outputs)

        return tf.sparse_tensor_to_dense(
            tf.sparse_transpose(decoded[0]),
            default_value=END_TOKEN_INDEX) 
Example #5
Source File: util.py    From pregel with MIT License 5 votes vote down vote up
def get_transpose_op(sparse_features=True):
    if (sparse_features):
        return tf.sparse_transpose
    else:
        return tf.transpose 
Example #6
Source File: relational_graph_attention.py    From rgat with Apache License 2.0 5 votes vote down vote up
def _attn_r_n_m_h(self):
        h, r, n = self.heads, self.relations, self._nodes

        attn_h_n_rm = self._attn_h_n_rm
        attn_h_n_r_m = tf.sparse_reshape(attn_h_n_rm, [h, n, r, n])
        attn_r_n_m_h = tf.sparse_transpose(attn_h_n_r_m, [2, 1, 3, 0])

        return attn_r_n_m_h