Transformer.js
HuggingFace Transformers.js is a JavaScript library that lets you run pretrained models locally on your machine. The library uses onnxruntime to leverage the CPU/GPU capabilities of your hardware.
In this guide, we will show how to create summaries using the Transformers.js library.
Installation
Following the installation instructions, we add the @xenova/transformers to the current project.
You can also install this library globally to be able to use on any project
Import the pipeline
The snippet below imports the Transformers.js library and loads the summarizer pipeline and model. You can specify a model name or let the library pick the latest and greatest.
Allocating and loading the model can take some time, so itβs best to do this at the beginning of your script and only once.
Invoke the pipeline
The summarizer pipeline has a single argument, the content to summarize. It returns an array of summaries
which we need to unpack to access the final summary text. This is what we do below and summary_index
contains the summary text.
Final code
The example below generates a summary of each input file before letting the model generate a full summary.