Hub documentation

Usando Transformers.js no Hugging Face

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Usando Transformers.js no Hugging Face

Transformers.js é uma biblioteca JavaScript para executar o 🤗 Transformers diretamente no seu navegador, sem a necessidade de um servidor! Ela foi projetada para ser funcionalmente equivalente à biblioteca original em Python, o que significa que você pode executar os mesmos modelos pré-treinados usando uma API muito semelhante.

Explorando o transformers.js no Hub

Você pode encontrar modelos de transformers.js filtrando por biblioteca na página de modelos.

Tour rápido

It’s super simple to translate from existing code! Just like the Python library, we support the pipeline API. Pipelines group together a pretrained model with preprocessing of inputs and postprocessing of outputs, making it the easiest way to run models with the library.

Python (original)JavaScript (nosso)
from transformers import pipeline

# Allocate a pipeline for sentiment-analysis
pipe = pipeline('sentiment-analysis')

out = pipe('I love transformers!')
# [{'label': 'POSITIVE', 'score': 0.999806941}]
import { pipeline } from '@huggingface/transformers';

// Allocate a pipeline for sentiment-analysis
let pipe = await pipeline('sentiment-analysis');

let out = await pipe('I love transformers!');
// [{'label': 'POSITIVE', 'score': 0.999817686}]

Você também pode usar um modelo diferente especificando o id ou o caminho do modelo como segundo argumento da função pipeline. Por exemplo:

// Use a different model for sentiment-analysis
let pipe = await pipeline('sentiment-analysis', 'nlptown/bert-base-multilingual-uncased-sentiment');

Consulte a documentação para a lista completa de tarefas e modelos suportados.

Instalação

Para instalar via NPM, execute:

npm i @huggingface/transformers

Para mais informações, incluindo como usá-lo em JS puro (sem nenhum bundler) via CDN ou hospedagem estática, consulte o README.

Recursos adicionais

Update on GitHub