Xenova HF Staff commited on
Commit
9de474d
·
verified ·
1 Parent(s): d0043a7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +36 -0
README.md CHANGED
@@ -5,4 +5,40 @@ base_model: baidu/ERNIE-4.5-0.3B-PT
5
 
6
  https://huggingface.co/baidu/ERNIE-4.5-0.3B-PT with ONNX weights to be compatible with Transformers.js.
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  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`).
 
5
 
6
  https://huggingface.co/baidu/ERNIE-4.5-0.3B-PT with ONNX weights to be compatible with Transformers.js.
7
 
8
+ ## Usage (Transformers.js)
9
+
10
+ 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/@huggingface/transformers) using:
11
+ ```bash
12
+ npm i @huggingface/transformers
13
+ ```
14
+
15
+ You can then generate text as follows:
16
+ ```js
17
+ import { pipeline, TextStreamer } from "@huggingface/transformers";
18
+
19
+ // Create a text generation pipeline
20
+ const generator = await pipeline(
21
+ "text-generation",
22
+ "onnx-community/ERNIE-4.5-0.3B-ONNX",
23
+ { dtype: "fp32" }, // Options: "fp32", "fp16", "q8", "q4", "q4f16"
24
+ );
25
+
26
+ // Define the list of messages
27
+ const messages = [
28
+ { role: "system", content: "You are a helpful assistant." },
29
+ { role: "user", content: "What is the capital of France?" },
30
+ ];
31
+
32
+ // Generate a response
33
+ const output = await generator(messages, {
34
+ max_new_tokens: 512,
35
+ do_sample: false,
36
+ streamer: new TextStreamer(generator.tokenizer, { skip_prompt: true, skip_special_tokens: true}),
37
+ });
38
+ console.log(output[0].generated_text.at(-1).content);
39
+ // The capital of France is Paris.
40
+ ```
41
+
42
+ ---
43
+
44
  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`).