def multi_perspective_expand_for_1D(in_tensor, weights):
"""
Given a 1D input tensor and weights of the appropriate shape,
weight the input tensor by the weights by multiplying them
together.
Parameters
----------
in_tensor:
Tensor of shape (x,) to be weighted.
weights:
Tensor of shape (y, x) to multiply the input tensor by. In this
case, y is the number of perspectives.
Returns
-------
weighted_input:
Tensor of shape (y, x), representing the weighted input
across multiple perspectives.
"""
# Shape: (1, rnn_hidden_dim)
in_tensor_expanded = tf.expand_dims(in_tensor, axis=0)
# Shape: (multiperspective_dims, rnn_hidden_dim)
return tf.multiply(in_tensor_expanded, weights)
评论列表
文章目录