Update README.md
Browse files
README.md
CHANGED
@@ -5,4 +5,30 @@ library_name: transformers.js
|
|
5 |
|
6 |
https://huggingface.co/Salesforce/codegen-350M-mono 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/Salesforce/codegen-350M-mono 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:** Code completion w/ `Xenova/codegen-350M-mono`.
|
17 |
+
```js
|
18 |
+
import { pipeline } from "@huggingface/transformers";
|
19 |
+
|
20 |
+
// Create a text generation pipeline
|
21 |
+
const generator = await pipeline("text-generation", "Xenova/codegen-350M-mono");
|
22 |
+
|
23 |
+
// Define the prompt
|
24 |
+
const text = `def fib(n):
|
25 |
+
"""Calculates the nth Fibonacci number"""`;
|
26 |
+
|
27 |
+
// Generate a response
|
28 |
+
const output = await generator(text, { max_new_tokens: 45 });
|
29 |
+
console.log(output[0].generated_text);
|
30 |
+
```
|
31 |
+
|
32 |
+
---
|
33 |
+
|
34 |
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`).
|