Xenova HF Staff commited on
Commit
d47ca0e
·
verified ·
1 Parent(s): 2ebc4f8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +59 -0
README.md CHANGED
@@ -5,4 +5,63 @@ base_model: SakanaAI/TinySwallow-1.5B-Instruct
5
 
6
  https://huggingface.co/SakanaAI/TinySwallow-1.5B-Instruct 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/SakanaAI/TinySwallow-1.5B-Instruct 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 use the model to generate text like this:
16
+
17
+ ```js
18
+ import { pipeline } from "@huggingface/transformers";
19
+
20
+ // Create a text generation pipeline
21
+ const generator = await pipeline(
22
+ "text-generation",
23
+ "onnx-community/TinySwallow-1.5B-Instruct-ONNX",
24
+ { dtype: "q4" },
25
+ );
26
+
27
+ // Define the list of messages
28
+ const messages = [
29
+ { role: "system", content: "You are a helpful assistant." },
30
+ { role: "user", content: "Solve the equation: x^2 + 2x - 3 = 0" },
31
+ ];
32
+
33
+ // Generate a response
34
+ const output = await generator(messages, { max_new_tokens: 256, do_sample: false });
35
+ console.log(output[0].generated_text.at(-1).content);
36
+ ```
37
+
38
+ <details>
39
+
40
+ <summary>See example output</summary>
41
+
42
+ ```
43
+ Here's how to solve the quadratic equation \(x^2 + 2x - 3 = 0\):
44
+
45
+ **Step 1:** Recognize that this is a quadratic equation in standard form, \(ax^2 + bx + c = 0\), where \(a=1\), \(b=2\), and \(c=-3\).
46
+
47
+ **Step 2:** We can factor the left side of the equation:
48
+
49
+ \[x^2 + 2x - 3 = (x + 3)(x - 1) = 0.\]
50
+
51
+ **Step 3:** Now we have two possible solutions from factoring:
52
+
53
+ - \(x + 3 = 0\) or \(x - 1 = 0\)
54
+
55
+ **Step 4:** Solve each equation for \(x\):
56
+
57
+ - \(x + 3 = 0 \Rightarrow x = -3\)
58
+ - \(x - 1 = 0 \Rightarrow x = 1\)
59
+
60
+ Therefore, the solutions to the equation \(x^2 + 2x - 3 = 0\) are \(x = -3\) and \(x = 1\).
61
+ ```
62
+
63
+ </details>
64
+
65
+ ---
66
+
67
  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`).