* Creates ngrams from ragged string data. * * This op accepts a ragged tensor with 1 ragged dimension containing only * strings and outputs a ragged tensor with 1 ragged dimension containing ngrams * of that string, joined along the innermost axis. * * ```js * const result = tf.string.stringN
(
data: Tensor1D|TensorLike, dataSplits: Tensor|TensorLike, separator: string,
nGramWidths: number[], leftPad: string, rightPad: string, padWidth: number,
preserveShortSequences: boolean)
| 65 | * @doc {heading: 'Operations', subheading: 'String'} |
| 66 | */ |
| 67 | function stringNGrams_( |
| 68 | data: Tensor1D|TensorLike, dataSplits: Tensor|TensorLike, separator: string, |
| 69 | nGramWidths: number[], leftPad: string, rightPad: string, padWidth: number, |
| 70 | preserveShortSequences: boolean): NamedTensorMap { |
| 71 | const $data = convertToTensor(data, 'data', 'stringNGrams', 'string'); |
| 72 | if ($data.dtype !== 'string') { |
| 73 | throw new Error('Data must be of datatype string'); |
| 74 | } |
| 75 | if ($data.shape.length !== 1) { |
| 76 | throw new Error(`Data must be a vector, saw: ${$data.shape}`); |
| 77 | } |
| 78 | |
| 79 | const $dataSplits = convertToTensor(dataSplits, 'dataSplits', 'stringNGrams'); |
| 80 | if ($dataSplits.dtype !== 'int32') { |
| 81 | throw new Error('Data splits must be of datatype int32'); |
| 82 | } |
| 83 | |
| 84 | const attrs: StringNGramsAttrs = { |
| 85 | separator, |
| 86 | nGramWidths, |
| 87 | leftPad, |
| 88 | rightPad, |
| 89 | padWidth, |
| 90 | preserveShortSequences |
| 91 | }; |
| 92 | |
| 93 | const inputs: StringNGramsInputs = {data: $data, dataSplits: $dataSplits}; |
| 94 | const result: Tensor[] = |
| 95 | ENGINE.runKernel(StringNGrams, inputs as {}, attrs as {}); |
| 96 | return {nGrams: result[0], nGramsSplits: result[1]}; |
| 97 | } |
| 98 | |
| 99 | export const stringNGrams = /* @__PURE__ */ op({stringNGrams_}); |
nothing calls this directly
no test coverage detected
searching dependent graphs…