Xenova HF staff commited on
Commit
ccf7568
1 Parent(s): 6ce67c1

Update Transformers.js example code

Browse files
Files changed (1) hide show
  1. README.md +10 -4
README.md CHANGED
@@ -2733,14 +2733,20 @@ The model natively supports scaling of the sequence length past 2048 tokens. To
2733
  import { pipeline } from '@xenova/transformers';
2734
 
2735
  // Create a feature extraction pipeline
2736
- const extractor = await pipeline('feature-extraction', 'nomic-ai/nomic-embed-text-v1', {
2737
  quantized: false, // Comment out this line to use the quantized version
2738
  });
2739
 
 
 
 
2740
  // Compute sentence embeddings
2741
- const texts = ['What is TSNE?', 'Who is Laurens van der Maaten?'];
2742
- const embeddings = await extractor(texts, { pooling: 'mean', normalize: true });
2743
- console.log(embeddings);
 
 
 
2744
  ```
2745
 
2746
  # Join the Nomic Community
 
2733
  import { pipeline } from '@xenova/transformers';
2734
 
2735
  // Create a feature extraction pipeline
2736
+ const extractor = await pipeline('feature-extraction', 'nomic-ai/nomic-embed-text-v1.5', {
2737
  quantized: false, // Comment out this line to use the quantized version
2738
  });
2739
 
2740
+ // Define sentences
2741
+ const texts = ['search_query: What is TSNE?', 'search_query: Who is Laurens van der Maaten?'];
2742
+
2743
  // Compute sentence embeddings
2744
+ let embeddings = await extractor(texts, { pooling: 'mean' });
2745
+ console.log(embeddings); // Tensor of shape [2, 768]
2746
+
2747
+ const matryoshka_dim = 512;
2748
+ embeddings = embeddings.slice(null, [0, matryoshka_dim]).normalize(2, -1);
2749
+ console.log(embeddings); // Tensor of shape [2, 512]
2750
  ```
2751
 
2752
  # Join the Nomic Community