(inputs, padding_token=0)
return sen_lens
Count how many words in a sentence.
  inputs: [..., time_steps]
  sen_lens: [...]
Count how many words in a sentence.
  inputs: [..., time_steps]
  sen_lens: [...]
Count how many words in a sentence . inputs : [ ... time_steps ] sen_lens : [ ... ]
def compute_sen_lens(inputs, padding_token=0):
  """
  Count how many words in a sentence.
  inputs: [..., time_steps]
  sen_lens: [...]
  """
  x_binary = tf.cast(tf.not_equal(inputs, padding_token), tf.int32)
  sen_lens = tf.reduce_sum(x_binary, axis=-1)
  ones = tf.ones_like(sen_lens)
  sen_lens = tf.where(tf.equal(sen_lens, utils.PAD_IDX), x=ones, y=sen_lens)
  return sen_lens
def compute_sen_lens ( inputs , padding_token = 0 ) : x_binary = tf . cast ( tf . not_equal ( inputs , padding_token ) , tf . int32 ) sen_lens = tf . reduce_sum ( x_binary , axis = - 1 ) ones = tf . ones_like ( sen_lens ) sen_lens = tf . where ( tf . equal ( sen_lens , utils . PAD_IDX ) , x = ones , y = sen_lens ) return sen_lens