Repository navigation
Expand file tree
/
Copy pathindex.d.ts
More file actions
135 lines (131 loc) · 5.09 KB
/
Copy pathindex.d.ts
File metadata and controls
135 lines (131 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* auto-generated by NAPI-RS */
/* eslint-disable */
/**
* Text encoded to token ids by a tokenizer.
*
* Each getter returns a `Uint32Array`, not a JS `Array`: an `Array` costs one napi value per
* token, which on token-dense input is 13x the encode itself (gpt2 chinese 31 vs 616 MB/s).
*/
export declare class Encoding {
/** The id of each token. */
get ids(): Uint32Array
/** The type id of each token: 0 for the first sequence of a pair, 1 for the second. */
get typeIds(): Uint32Array
/** 1 for each token, 0 for each padding token. */
get attentionMask(): Uint32Array
/** The number of tokens. */
get length(): number
}
/** A tokenizer. Encodes text into token ids, and decodes token ids back into text. */
export declare class Tokenizer {
/**
* Read a `tokenizer.json`. The file is put through the legacy "1.0" -> canonical "2.0"
* upgrade first, so the tokenizers already on disk keep loading; `tk_serialize` itself only
* reads the canonical form.
*/
static fromFile(path: string): Tokenizer
/**
* Encodes the given text, or pair of texts, to token ids. The post-processor joins a pair,
* for example as `[CLS] A [SEP] B [SEP]`.
*/
encode(input: string | [string, string], options?: EncodeOptions | undefined | null): Encoding
/**
* Encodes the given text, or pair of texts, and returns the token of each id.
*
* Shorthand for `decodeTokens(encode(input, options).ids)`.
*/
tokenize(input: string | [string, string], options?: EncodeOptions | undefined | null): Array<string>
/**
* Encodes a batch of texts, or pairs of texts. A batch can mix both. The encodings come back
* in input order.
*/
encodeBatch(inputs: Array<string | [string, string]>, options?: EncodeOptions | undefined | null): Array<Encoding>
/**
* Drops the two remaining per-call costs of [`Self::encode`]: the JS string -> UTF-8 copy
* (as fast as the tokenizer itself, so it halves throughput) and the fresh `ArrayBuffer`
* (388 ns of a 789 ns call). Returns how many ids were written.
*/
encodeBytesInto(text: Uint8Array, out: Uint32Array, options?: EncodeOptions | undefined | null): number
/**
* Decodes token ids back into text.
*
* `skipSpecialTokens` drops special tokens from the text. `true` when left out.
*/
decode(ids: Uint32Array, skipSpecialTokens?: boolean | undefined | null): string
/**
* Converts token ids to their tokens. This does not run the decoder, so each token keeps its
* spelling in the vocabulary: a byte-level BPE token reads `Ġworld`, not ` world`.
*
* `skipSpecialTokens` drops special tokens. `false` when left out. Ids not in the vocabulary
* are dropped.
*/
decodeTokens(ids: Uint32Array, skipSpecialTokens?: boolean | undefined | null): Array<string>
}
/** Per-call settings. A field left out keeps the tokenizer's own behaviour. */
export interface EncodeOptions {
/**
* Whether the post-processor adds its special tokens, such as `[CLS]` and `[SEP]`. `true`
* when left out.
*/
addSpecialTokens?: boolean
/**
* Whether a special token written in the text goes through the model (`true`) or becomes its
* added-vocabulary id. `false` when left out.
*/
encodeSpecialTokens?: boolean
/**
* Padding for this call, replacing the tokenizer's configured padding. `false` disables
* padding. Left out, the configured padding applies.
*/
padding?: false | Padding
/**
* Truncation for this call, replacing the tokenizer's configured truncation. `false` disables
* truncation. Left out, the configured truncation applies.
*/
truncation?: false | Truncation
}
/**
* Padding for one call. It replaces the tokenizer's configured padding as a whole, so a field
* left out takes the value noted on the field, not the configured one.
*/
export interface Padding {
/**
* `right` when left out, or `left`: whether padding tokens are appended to the right or
* prepended to the left of encoded tokens.
*/
direction?: 'left' | 'right'
/** The id of the padding token. `0` when left out. */
padId?: number
/** The type id of the padding token. `0` when left out. */
padTypeId?: number
/** The text of the padding token. `[PAD]` when left out. */
padToken?: string
/**
* Pads every encoding to exactly this many tokens. Left out, pads each batch to its longest
* item.
*/
length?: number
/** Rounds the padded length up to a multiple of this. */
padToMultipleOf?: number
}
/**
* Truncation for one call. It replaces the tokenizer's configured truncation as a whole, so a
* field left out takes the value noted on the field, not the configured one.
*/
export interface Truncation {
/**
* The maximum number of tokens, including special tokens, to keep. Encodings with more tokens
* get truncated.
*/
maxLength: number
/**
* `longest_first` when left out, `only_first` or `only_second`: which sequence of a pair is
* truncated.
*/
strategy?: 'longest_first' | 'only_first' | 'only_second'
/**
* `right` when left out, or `left`: whether to truncate tokens at the end of the sequence or
* at its beginning.
*/
direction?: 'left' | 'right'
}