Xenova HF staff commited on
Commit
076accc
1 Parent(s): 2816ff5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -0
README.md CHANGED
@@ -5,4 +5,49 @@ base_model: facebook/MobileLLM-125M
5
 
6
  https://huggingface.co/facebook/MobileLLM-125M 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/facebook/MobileLLM-125M with ONNX weights to be compatible with Transformers.js.
7
 
8
+
9
+ ## Usage (Transformers.js)
10
+
11
+ 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:
12
+ ```bash
13
+ npm i @huggingface/transformers
14
+ ```
15
+
16
+ **Example:** Text generation with `onnx-community/MobileLLM-125M`.
17
+
18
+ ```js
19
+ import { pipeline } from "@huggingface/transformers";
20
+
21
+ // Create a text generation pipeline
22
+ const generator = await pipeline(
23
+ "text-generation",
24
+ "onnx-community/MobileLLM-125M",
25
+ { dtype: "fp32" },
26
+ );
27
+
28
+ // Define the list of messages
29
+ const text = "Q: What is the capital of France?\nA: Paris\nQ: What is the capital of England?\nA:";
30
+
31
+ // Generate a response
32
+ const output = await generator(text, { max_new_tokens: 30 });
33
+ console.log(JSON.stringify(output[0].generated_text));
34
+ ```
35
+
36
+ <details>
37
+
38
+ <summary>Example output</summary>
39
+
40
+ ```
41
+ Q: What is the capital of France?
42
+ A: Paris
43
+ Q: What is the capital of England?
44
+ A: London
45
+ Q: What is the capital of Scotland?
46
+ A: Edinburgh
47
+ Q: What is the capital of Wales?
48
+ A: Cardiff
49
+ ```
50
+ </details>
51
+
52
+
53
  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`).