File tree Expand file tree Collapse file tree
packages/react-native-executorch
src/modules/natural_language_processing Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #pragma once
2+
3+ #include < ReactCommon/CallInvoker.h>
4+ #include < string>
5+ #include < tokenizers-cpp/tokenizers_cpp.h>
6+
7+ namespace rnexecutorch {
8+ using namespace facebook ;
9+
10+ class TokenizerModule {
11+ public:
12+ std::unique_ptr<tokenizers::Tokenizer> tokenizer;
13+ TokenizerModule (std::string source,
14+ std::shared_ptr<react::CallInvoker> callInvoker);
15+ std::vector<int32_t > encode (std::string s);
16+ std::string decode (std::vector<int32_t > vec);
17+ int getMemoryLowerBound ();
18+ };
19+ } // namespace rnexecutorch
Original file line number Diff line number Diff line change 1+ import { ResourceSource } from '../../types/common' ;
2+ import { ResourceFetcher } from '../../utils/ResourceFetcher' ;
3+
4+ export class NewTokenizerModule {
5+ nativeModule : any ;
6+
7+ async load (
8+ modelSource : ResourceSource ,
9+ onDownloadProgressCallback : ( _ : number ) => void = ( ) => { }
10+ ) : Promise < void > {
11+ const paths = await ResourceFetcher . fetchMultipleResources (
12+ onDownloadProgressCallback ,
13+ modelSource
14+ ) ;
15+ console . log ( paths ) ;
16+ this . nativeModule = global . loadTokenizerModule ( paths [ 0 ] || '' ) ;
17+ }
18+
19+ async encode ( s : string ) {
20+ return await this . nativeModule . encode ( s ) ;
21+ }
22+
23+ async decode ( tokens : number [ ] ) {
24+ return await this . nativeModule . decode ( tokens ) ;
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments