Update README.md
Browse files
README.md
CHANGED
@@ -4,6 +4,27 @@ tags:
|
|
4 |
- transformers
|
5 |
---
|
6 |
|
7 |
-
|
8 |
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
- transformers
|
5 |
---
|
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 generate text like this:
|
15 |
+
|
16 |
+
```js
|
17 |
+
import { pipeline } from "@xenova/transformers";
|
18 |
+
|
19 |
+
// Create a text-generation pipeline
|
20 |
+
const generator = await pipeline('text-generation', 'Xenova/llama2.c-stories110M');
|
21 |
+
|
22 |
+
const text = 'Once upon a time,';
|
23 |
+
const output = await generator(text);
|
24 |
+
console.log(output);
|
25 |
+
// [{ generated_text: "Once upon a time, there was a little girl named Lily. She loved to play outside in" }]
|
26 |
+
|
27 |
+
const output2 = await generator(text, { max_new_tokens: 50 });
|
28 |
+
console.log(output2);
|
29 |
+
// [{ generated_text: "Once upon a time, there was a little girl named Lily. She loved to play outside in the sunshine. One day, she saw a big, scary dog. She was scared and didn't know what to do. \nSudden" }]
|
30 |
+
```
|