Skip to content

Latest commit

 

History

History
106 lines (91 loc) · 2.91 KB

File metadata and controls

106 lines (91 loc) · 2.91 KB

description: Add padding to the beginning and end of data in a specific dimension.

text.pad_along_dimension

View source

Add padding to the beginning and end of data in a specific dimension.

text.pad_along_dimension(
    data, axis=-1, left_pad=None, right_pad=None, name=None
)

Returns a tensor constructed from data, where each row in dimension axis is replaced by the concatenation of the left padding followed by the row followed by the right padding. I.e., if L=left_pad.shape[0] and R=right_pad.shape[0], then:

result[i1...iaxis, 0:L] = left_pad
result[i1...iaxis, L:-R] = data[i0...iaxis]
result[i1...iaxis, -R:] = right_pad

Args

`data` `[O1...ON, A, I1...IM]` A potentially ragged `K` dimensional tensor with outer dimensions of size `O1...ON`; axis dimension of size `A`; and inner dimensions of size `I1...IM`. I.e. `K = N + 1 + M`, where `N>=0` and `M>=0`.
`axis` An integer constant specifying the axis along which padding is added. Negative axis values from `-K` to `-1` are supported.
`left_pad` `[L, I1...IM]` An `M+1` dimensional tensor that should be prepended to each row along dimension `axis`; or `None` if no padding should be added to the left side.
`right_pad` `[R, I1...IM]` An `M+1` dimensional tensor that should be appended to each row along dimension `axis`; or `None` if no padding should be added to the right side.
`name` The name of this op (optional).

Returns

`[O1...ON, L + A + R, I1...IM]` A potentially ragged `K` dimensional tensor with outer dimensions of size `O1...ON`; padded axis dimension size `L+A+R`; and inner dimensions of size `I1...IM`. If `data` is a `RaggedTensor`, then the returned tensor is a `RaggedTensor` with the same `ragged_rank`.