Xenova HF staff commited on
Commit
adcb50f
1 Parent(s): bba8c8c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +35 -0
README.md CHANGED
@@ -4,4 +4,39 @@ library_name: transformers.js
4
 
5
  https://huggingface.co/OFA-Sys/chinese-clip-vit-base-patch16 with ONNX weights to be compatible with Transformers.js.
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
 
4
 
5
  https://huggingface.co/OFA-Sys/chinese-clip-vit-base-patch16 with ONNX weights to be compatible with Transformers.js.
6
 
7
+ ## Usage (Transformers.js)
8
+
9
+ If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@xenova/transformers) using:
10
+ ```bash
11
+ npm i @xenova/transformers
12
+ ```
13
+
14
+ **Example:** Zero-shot image classification w/ `Xenova/chinese-clip-vit-base-patch16`.
15
+
16
+ ```javascript
17
+ import { pipeline } from '@xenova/transformers';
18
+
19
+ // Create zero-shot image classification pipeline
20
+ const classifier = await pipeline('zero-shot-image-classification', 'Xenova/chinese-clip-vit-base-patch16');
21
+
22
+ // Set image url and candidate labels
23
+ const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/pikachu.png';
24
+ const candidate_labels = ['杰尼龟', '妙蛙种子', '小火龙', '皮卡丘'] // Squirtle, Bulbasaur, Charmander, Pikachu in Chinese
25
+
26
+ // Classify image
27
+ const output = await classifier(url, candidate_labels);
28
+ console.log(output);
29
+ // [
30
+ // { score: 0.9926728010177612, label: '皮卡丘' }, // Pikachu
31
+ // { score: 0.003480620216578245, label: '妙蛙种子' }, // Bulbasaur
32
+ // { score: 0.001942147733643651, label: '杰尼龟' }, // Squirtle
33
+ // { score: 0.0019044597866013646, label: '小火龙' } // Charmander
34
+ // ]
35
+ ```
36
+
37
+
38
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/bVOErVl5Zsz1dpstDfKpu.png)
39
+
40
+ ---
41
+
42
  Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).