Skip to content

Commit e4cb674

Browse files
committed
Add JSDoc for tokenizers.js
1 parent 2576c32 commit e4cb674

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/tokenizers.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,12 @@ class PostProcessor extends Callable {
926926
throw Error("post_process should be implemented in subclass.")
927927
}
928928

929+
/**
930+
* Alias for {@link PostProcessor#post_process}.
931+
* @param {Array} tokens - The text or array of texts to post-process.
932+
* @param {...*} args - Additional arguments required by the post-processing logic.
933+
* @returns {Array} An array of post-processed tokens.
934+
*/
929935
_call(tokens, ...args) {
930936
return this.post_process(tokens, ...args);
931937
}
@@ -1498,6 +1504,17 @@ class PreTrainedTokenizer extends Callable {
14981504
return inputs;
14991505
}
15001506

1507+
/**
1508+
* Encode/tokenize the given text(s).
1509+
* @param {string|string[]} text - The text to tokenize.
1510+
* @param {object} options - An optional object containing the following properties:
1511+
* @param {string|string[]} [options.text_pair=null] - Optional second sequence to be encoded. If set, must be the same type as text.
1512+
* @param {boolean} [options.padding=false] - Whether to pad the input sequences.
1513+
* @param {boolean} [options.truncation=null] - Whether to truncate the input sequences.
1514+
* @param {number} [options.max_length=null] - Maximum length of the returned list and optionally padding length.
1515+
* @param {boolean} [options.return_tensor=true] - Whether to return the results as Tensors or arrays.
1516+
* @returns {{ input_ids: number[]|number[][]|Tensor; attention_mask: any[]|Tensor; }} Object to be passed to the model.
1517+
*/
15011518
_call(
15021519
// Required positional arguments
15031520
text,
@@ -1512,6 +1529,7 @@ class PreTrainedTokenizer extends Callable {
15121529
return_tensor = true, // Different to HF
15131530
} = {},
15141531
) {
1532+
/** @type {number[]|number[][]|Tensor} */
15151533
let tokens;
15161534

15171535
if (Array.isArray(text)) {

0 commit comments

Comments
 (0)