Hub documentation

Hugging Face에서 Transformers.js 사용

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Hugging Face에서 Transformers.js 사용

Transformers.js는 서버 없이 브라우저에서 🤗 Transformers를 직접 실행할 수 있는 JavaScript 라이브러리입니다. 원래의 Python 라이브러리와 기능적으로 동등하도록 설계되어, 매우 유사한 API를 사용하여 동일한 사전 학습 모델을 실행할 수 있습니다.

Hub에서 transformers.js 탐색

모델 페이지에서 라이브러리로 필터링하여 transformers.js 모델을 찾을 수 있습니다.

빠른 둘러보기

기존 코드에서 변환하는 것은 매우 간단합니다! Python 라이브러리처럼 pipeline API를 지원합니다. 파이프라인은 사전 학습된 모델과 입력 전처리, 출력 후처리를 하나로 묶어 라이브러리로 모델을 실행하는 가장 쉬운 방법을 제공합니다.

Python (원본)JavaScript(자체 개발)
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}]

pipeline 함수의 두 번째 인수로 모델 ID 또는 경로를 지정하여 다른 모델을 사용할 수도 있습니다. 예를 들어:

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

지원되는 작업 및 모델의 전체 목록은 문서를 참조하세요.

설치

NPM을 통해 설치하려면 다음을 실행하세요:

npm i @huggingface/transformers

CDN 또는 정적 호스팅을 통해 번들러 없이 순수 JS에서 사용하는 방법 등 자세한 내용은 README를 참고하세요.

추가 리소스

Update on GitHub