If you haven't already, you can install the
Transformers.js
JavaScript library from
NPM
using:
npm i @xenova/transformers
You can then use the model to generate text as follows:
import { pipeline } from'@xenova/transformers';
// Create a text-generation pipelineconst generator = awaitpipeline('text-generation', 'Xenova/gpt2');
// Generate text (default parameters)const text = 'Once upon a time,';
const output = awaitgenerator(text);
console.log(output);
// [{ generated_text: 'Once upon a time, I was in a room with a woman who was very attractive. She was' }]// Generate text (custom parameters)const output2 = awaitgenerator(text, {
max_new_tokens: 20,
do_sample: true,
top_k: 5,
});
console.log(output2);
// [{ 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' }]
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
and structuring your repo like this one (with ONNX weights located in a subfolder named
onnx
).
Runs of Xenova gpt2 on huggingface.co
5.1K
Total runs
0
24-hour runs
109
3-day runs
1.2K
7-day runs
1.6K
30-day runs
More Information About gpt2 huggingface.co Model
gpt2 huggingface.co
gpt2 huggingface.co is an AI model on huggingface.co that provides gpt2's model effect (), which can be used instantly with this Xenova gpt2 model. huggingface.co supports a free trial of the gpt2 model, and also provides paid use of the gpt2. Support call gpt2 model through api, including Node.js, Python, http.
gpt2 huggingface.co is an online trial and call api platform, which integrates gpt2's modeling effects, including api services, and provides a free online trial of gpt2, you can try gpt2 online for free by clicking the link below.
gpt2 is an open source model from GitHub that offers a free installation service, and any user can find gpt2 on GitHub to install. At the same time, huggingface.co provides the effect of gpt2 install, users can directly use gpt2 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.