Skip to content

Commit 21f9178

Browse files
author
jakmro
committed
refactor: update module instantiation
1 parent 596c08e commit 21f9178

12 files changed

Lines changed: 75 additions & 51 deletions

File tree

docs/docs/02-hooks/01-natural-language-processing/useSpeechToText.md

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

docs/docs/03-typescript-api/01-natural-language-processing/SpeechToTextModule.md

Lines changed: 10 additions & 10 deletions
Large diffs are not rendered by default.

docs/docs/03-typescript-api/01-natural-language-processing/TextEmbeddingsModule.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ TypeScript API implementation of the [useTextEmbeddings](../../02-hooks/01-natur
1010
import {
1111
TextEmbeddingsModule,
1212
ALL_MINILM_L6_V2,
13-
All_MINILM_L6_V2_TOKENIZER,
1413
} from 'react-native-executorch';
1514

15+
// Creating an instance
16+
const textEmbeddingsModule = new TextEmbeddingsModule();
17+
1618
// Loading the model
17-
await TextEmbeddingsModule.load(ALL_MINILM_L6_V2);
19+
await textEmbeddingsModule.load(ALL_MINILM_L6_V2);
1820

1921
// Running the model
20-
const embedding = await TextEmbeddingsModule.forward('Hello World!');
22+
const embedding = await textEmbeddingsModule.forward('Hello World!');
2123
```
2224

2325
### Methods

docs/docs/03-typescript-api/01-natural-language-processing/TokenizerModule.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,33 @@ TypeScript API implementation of the [useTokenizer](../../02-hooks/01-natural-la
99
```typescript
1010
import { TokenizerModule, ALL_MINILM_L6_V2 } from 'react-native-executorch';
1111

12+
// Creating an instance
13+
const tokenizerModule = new TokenizerModule();
14+
1215
// Load the tokenizer
13-
await TokenizerModule.load(ALL_MINILM_L6_V2);
16+
await tokenizerModule.load(ALL_MINILM_L6_V2);
1417
console.log('Tokenizer loaded');
1518

1619
// Get tokenizers vocabulary size
17-
const vocabSize = await TokenizerModule.getVocabSize();
20+
const vocabSize = await tokenizerModule.getVocabSize();
1821
console.log('Vocabulary size:', vocabSize);
1922

2023
const text = 'Hello, world!';
2124

2225
// Tokenize the text
23-
const tokens = await TokenizerModule.encode(text);
26+
const tokens = await tokenizerModule.encode(text);
2427
console.log('Token IDs:', tokens);
2528

2629
// Decode the tokens back to text
27-
const decoded = await TokenizerModule.decode(tokens);
30+
const decoded = await tokenizerModule.decode(tokens);
2831
console.log('Decoded text:', decoded);
2932

3033
// Get the token ID for a specific token
31-
const tokenId = await TokenizerModule.tokenToId('hello');
34+
const tokenId = await tokenizerModule.tokenToId('hello');
3235
console.log('Token ID for "Hello":', tokenId);
3336

3437
// Get the token for a specific ID
35-
const token = await TokenizerModule.idToToken(tokenId);
38+
const token = await tokenizerModule.idToToken(tokenId);
3639
console.log('Token for ID:', token);
3740
```
3841

docs/docs/03-typescript-api/02-computer-vision/ClassificationModule.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import {
1414

1515
const imageUri = 'path/to/image.png';
1616

17-
const module = new ClassificationModule();
17+
// Creating an instance
18+
const classificationModule = new ClassificationModule();
1819

1920
// Loading the model
20-
await module.load(EFFICIENTNET_V2_S);
21+
await classificationModule.load(EFFICIENTNET_V2_S);
2122

2223
// Running the model
23-
const classesWithProbabilities = await module.forward(imageUri);
24+
const classesWithProbabilities = await classificationModule.forward(imageUri);
2425
```
2526

2627
### Methods

docs/docs/03-typescript-api/02-computer-vision/ImageEmbeddingsModule.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ TypeScript API implementation of the [useImageEmbeddings](../../02-hooks/02-comp
99
```typescript
1010
import {
1111
ImageEmbeddingsModule,
12-
CLIP_VIT_BASE_PATCH_32_IMAGE_ENCODER,
12+
CLIP_VIT_BASE_PATCH32_IMAGE,
1313
} from 'react-native-executorch';
1414

15+
// Creating an instance
16+
const imageEmbeddingsModule = new ImageEmbeddingsModule();
17+
1518
// Loading the model
16-
await ImageEmbeddingsModule.load(CLIP_VIT_BASE_PATCH_32_IMAGE_ENCODER);
19+
await imageEmbeddingsModule.load(CLIP_VIT_BASE_PATCH32_IMAGE);
1720

1821
// Running the model
19-
const embedding = await ImageEmbeddingsModule.forward(
22+
const embedding = await imageEmbeddingsModule.forward(
2023
'https://url-to-image.jpg'
2124
);
2225
```

docs/docs/03-typescript-api/02-computer-vision/ImageSegmentationModule.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import {
1414

1515
const imageUri = 'path/to/image.png';
1616

17-
const module = new ImageSegmentationModule();
17+
// Creating an instance
18+
const imageSegmentationModule = new ImageSegmentationModule();
1819

1920
// Loading the model
20-
await module.load(DEEPLAB_V3_RESNET50);
21+
await imageSegmentationModule.load(DEEPLAB_V3_RESNET50);
2122

2223
// Running the model
23-
const outputDict = await module.forward(imageUri);
24+
const outputDict = await imageSegmentationModule.forward(imageUri);
2425
```
2526

2627
### Methods

docs/docs/03-typescript-api/02-computer-vision/OCRModule.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ TypeScript API implementation of the [useOCR](../../02-hooks/02-computer-vision/
1010
import { OCRModule, OCR_ENGLISH } from 'react-native-executorch';
1111
const imageUri = 'path/to/image.png';
1212

13+
// Creating an instance
14+
const ocrModule = new OCRModule();
15+
1316
// Loading the model
14-
await OCRModule.load(OCR_ENGLISH);
17+
await ocrModule.load(OCR_ENGLISH);
1518

1619
// Running the model
17-
const ocrDetections = await OCRModule.forward(imageUri);
20+
const detections = await ocrModule.forward(imageUri);
1821
```
1922

2023
### Methods

docs/docs/03-typescript-api/02-computer-vision/ObjectDetectionModule.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import {
1414

1515
const imageUri = 'path/to/image.png';
1616

17-
const module = new ObjectDetectionModule();
17+
// Creating an instance
18+
const objectDetectionModule = new ObjectDetectionModule();
1819

1920
// Loading the model
20-
await module.load(SSDLITE_320_MOBILENET_V3_LARGE);
21+
await objectDetectionModule.load(SSDLITE_320_MOBILENET_V3_LARGE);
2122

2223
// Running the model
23-
const detections = await module.forward(imageUri);
24+
const detections = await objectDetectionModule.forward(imageUri);
2425
```
2526

2627
### Methods

docs/docs/03-typescript-api/02-computer-vision/StyleTransferModule.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import {
1414

1515
const imageUri = 'path/to/image.png';
1616

17-
const module = new StyleTransferModule();
17+
// Creating an instance
18+
const styleTransferModule = new StyleTransferModule();
1819

1920
// Loading the model
20-
await module.load(STYLE_TRANSFER_CANDY);
21+
await styleTransferModule.load(STYLE_TRANSFER_CANDY);
2122

2223
// Running the model
23-
const generatedImageUrl = await module.forward(imageUri);
24+
const generatedImageUrl = await styleTransferModule.forward(imageUri);
2425
```
2526

2627
### Methods

0 commit comments

Comments
 (0)