MCPcopy Create free account
hub / github.com/tensorflow/tfjs / stringNGrams_

Function stringNGrams_

tfjs-core/src/ops/string/string_n_grams.ts:67–97  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

65 * @doc {heading: 'Operations', subheading: 'String'}
66 */
67function 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
99export const stringNGrams = /* @__PURE__ */ op({stringNGrams_});

Callers

nothing calls this directly

Calls 2

convertToTensorFunction · 0.90
runKernelMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…