Update README.md
Browse files
README.md
CHANGED
@@ -4,4 +4,63 @@ library_name: transformers.js
|
|
4 |
|
5 |
https://huggingface.co/susnato/phi-1_5_dev 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/susnato/phi-1_5_dev with ONNX weights to be compatible with Transformers.js.
|
6 |
|
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/@xenova/transformers) using:
|
11 |
+
```bash
|
12 |
+
npm i @xenova/transformers
|
13 |
+
```
|
14 |
+
|
15 |
+
**Example:** Text generation (code completion) with `Xenova/phi-1_5_dev`.
|
16 |
+
|
17 |
+
```js
|
18 |
+
import { pipeline } from '@xenova/transformers';
|
19 |
+
|
20 |
+
// Create a text-generation pipeline
|
21 |
+
const generator = await pipeline('text-generation', 'Xenova/phi-1_5_dev');
|
22 |
+
|
23 |
+
// Construct prompt
|
24 |
+
const prompt = `\`\`\`py
|
25 |
+
import math
|
26 |
+
def print_prime(n):
|
27 |
+
"""
|
28 |
+
Print all primes between 1 and n
|
29 |
+
"""`;
|
30 |
+
|
31 |
+
// Generate text
|
32 |
+
const result = await generator(prompt, {
|
33 |
+
max_new_tokens: 100,
|
34 |
+
});
|
35 |
+
console.log(result[0].generated_text);
|
36 |
+
```
|
37 |
+
|
38 |
+
Results in:
|
39 |
+
```py
|
40 |
+
import math
|
41 |
+
def print_prime(n):
|
42 |
+
"""
|
43 |
+
Print all primes between 1 and n
|
44 |
+
"""
|
45 |
+
primes = []
|
46 |
+
for num in range(2, n+1):
|
47 |
+
is_prime = True
|
48 |
+
for i in range(2, int(math.sqrt(num))+1):
|
49 |
+
if num % i == 0:
|
50 |
+
is_prime = False
|
51 |
+
break
|
52 |
+
if is_prime:
|
53 |
+
primes.append(num)
|
54 |
+
print(primes)
|
55 |
+
|
56 |
+
print_prime(20)
|
57 |
+
```
|
58 |
+
|
59 |
+
Running the code produces the correct result:
|
60 |
+
```
|
61 |
+
[2, 3, 5, 7, 11, 13, 17, 19]
|
62 |
+
```
|
63 |
+
---
|
64 |
+
|
65 |
+
|
66 |
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`).
|