Transformers-js-py

Latest version: v0.19.4

Safety actively analyzes 688087 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 14 of 14

0.00005029444946558215

// { label: 'no', score: 4.877569494965428e-7 },
// { label: 'stop', score: 5.504634081887616e-9 }
// ]


**Example:** Perform automatic speech recognition w/ `Xenova/hubert-large-ls960-ft`.
javascript
import { pipeline } from 'xenova/transformers';

// Create automatic speech recognition pipeline
const transcriber = await pipeline('automatic-speech-recognition', 'Xenova/hubert-large-ls960-ft');

// Transcribe audio
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav';
const output = await transcriber(url);
// { text: 'AND SO MY FELLOW AMERICA ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR COUNTRY' }


4. [Chinese-CLIP](https://huggingface.co/docs/transformers/main/en/model_doc/chinese_clip) for zero-shot image classification (https://github.com/xenova/transformers.js/pull/455). See [here](https://huggingface.co/models?library=transformers.js&other=chinese_clip&sort=trending) for the list of available models.

**Example:** Zero-shot image classification w/ `Xenova/hubert-large-ls960-ft`.

js
import { pipeline } from 'xenova/transformers';

// Create zero-shot image classification pipeline
const classifier = await pipeline('zero-shot-image-classification', 'Xenova/chinese-clip-vit-base-patch16');

// Set image url and candidate labels
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/pikachu.png';
const candidate_labels = ['杰尼龟', '妙蛙种子', '小火龙', '皮卡丘'] // Squirtle, Bulbasaur, Charmander, Pikachu in Chinese

// Classify image
const output = await classifier(url, candidate_labels);
console.log(output);
// [
// { score: 0.9926728010177612, label: '皮卡丘' }, // Pikachu
// { score: 0.003480620216578245, label: '妙蛙种子' }, // Bulbasaur
// { score: 0.001942147733643651, label: '杰尼龟' }, // Squirtle
// { score: 0.0019044597866013646, label: '小火龙' } // Charmander
// ]


5. [DINOv2](https://huggingface.co/docs/transformers/main/en/model_doc/dinov2) for image classification (https://github.com/xenova/transformers.js/pull/444). See [here](https://huggingface.co/models?library=transformers.js&other=dinov2&sort=trending) for the list of available models.

**Example:** Image classification w/ `Xenova/dinov2-small-imagenet1k-1-layer`.
js
import { pipeline} from 'xenova/transformers';

// Create image classification pipeline
const classifier = await pipeline('image-classification', 'Xenova/dinov2-small-imagenet1k-1-layer');

// Classify an image
const url = 'http://images.cocodataset.org/val2017/000000039769.jpg';
const output = await classifier(url);
console.log(output)

0.004518700763583183

0.3183615803718567

// Compute image-image similarity scores
const image_to_image_score = await matmul(l2norm_image_embeddings[0], l2norm_image_embeddings[1]);

0.016986183822155

0.78

Page 14 of 14

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.