-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathTokenizerModule.ts
More file actions
34 lines (27 loc) · 1 KB
/
TokenizerModule.ts
File metadata and controls
34 lines (27 loc) · 1 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
import { TokenizerNativeModule } from '../../native/RnExecutorchModules';
import { ResourceSource } from '../../types/common';
import { BaseModule } from '../BaseModule';
export class TokenizerModule extends BaseModule {
protected static override nativeModule = TokenizerNativeModule;
static override async load(tokenizerSource: ResourceSource) {
await super.load([tokenizerSource]);
}
static async decode(
input: number[],
skipSpecialTokens = false
): Promise<string> {
return await this.nativeModule.decode(input, skipSpecialTokens);
}
static async encode(input: string): Promise<number[]> {
return await this.nativeModule.encode(input);
}
static async getVocabSize(): Promise<number> {
return await this.nativeModule.getVocabSize();
}
static async idToToken(tokenId: number): Promise<string> {
return await this.nativeModule.idToToken(tokenId);
}
static async tokenToId(token: string): Promise<number> {
return await this.nativeModule.tokenToId(token);
}
}