Views
No views yet
npm i @huggingface/transformers1import { pipeline } from '@huggingface/transformers';
2
3// Create a feature-extraction pipeline
4const extractor = await pipeline('feature-extraction', 'huggingworld/all-MiniLM-L6-v2-ONNX');
5
6// Compute sentence embeddings
7const sentences = ['This is an example sentence', 'Each sentence is converted'];
8const output = await extractor(sentences, { pooling: 'mean', normalize: true });
9console.log(output);
10// Tensor {
11// dims: [ 2, 384 ],
12// type: 'float32',
13// data: Float32Array(768) [ 0.04592696577310562, 0.07328180968761444, ... ],
14// size: 768
15// }.tolist():1console.log(output.tolist());
2// [
3// [ 0.04592696577310562, 0.07328180968761444, 0.05400655046105385, ... ],
4// [ 0.08188057690858841, 0.10760223120450974, -0.013241755776107311, ... ]
5// ]