Xenova HF staff commited on
Commit
5140127
1 Parent(s): 0eb78bf

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +31 -0
README.md CHANGED
@@ -4,4 +4,35 @@ library_name: "transformers.js"
4
 
5
  https://huggingface.co/gpt2 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/gpt2 with ONNX weights to be compatible with Transformers.js.
6
 
7
+ ## Usage (Transformers.js)
8
+
9
+ 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:
10
+ ```bash
11
+ npm i @xenova/transformers
12
+ ```
13
+
14
+ You can then use the model to generate text as follows:
15
+
16
+ ```js
17
+ import { pipeline } from '@xenova/transformers';
18
+
19
+ // Create a text-generation pipeline
20
+ const generator = await pipeline('text-generation', 'Xenova/gpt2');
21
+
22
+ // Generate text (default parameters)
23
+ const text = 'Once upon a time,';
24
+ const output = await generator(text);
25
+ console.log(output);
26
+ // [{ generated_text: 'Once upon a time, I was in a room with a woman who was very attractive. She was' }]
27
+
28
+ // Generate text (custom parameters)
29
+ const output2 = await generator(text, {
30
+ max_new_tokens: 20,
31
+ do_sample: true,
32
+ top_k: 5,
33
+ });
34
+ console.log(output2);
35
+ // [{ generated_text: 'generated_text: 'Once upon a time, the first thing I did was put a small piece of paper on a table. I put the paper' }]
36
+ ```
37
+
38
  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`).