Views
No views yet
npm i @huggingface/transformers1import { pipeline } from '@huggingface/transformers';
2
3// Create a text-generation pipeline
4const generator = await pipeline('text-generation', 'Xenova/gpt2');
5
6// Generate text (default parameters)
7const text = 'Once upon a time,';
8const output = await generator(text);
9console.log(output);
10// [{ generated_text: 'Once upon a time, I was in a room with a woman who was very attractive. She was' }]
11
12// Generate text (custom parameters)
13const output2 = await generator(text, {
14 max_new_tokens: 20,
15 do_sample: true,
16 top_k: 5,
17});
18console.log(output2);
19// [{ 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' }]onnx).