forked from huggingface/hub-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Transformers.js as a supported library (huggingface#854)
* Add Transformers.js as a supported library * Fix typo in docs/hub/transformers-js.md Co-authored-by: Omar Sanseviero <osanseviero@gmail.com> * Update docs/hub/transformers-js.md Co-authored-by: Pedro Cuenca <pedro@huggingface.co> * Use `const` instead of `let` in example code See js/src/lib/interfaces/Libraries.ts Co-authored-by: Julien Chaumond <julien@huggingface.co> * Update docs/hub/transformers-js.md Co-authored-by: Pedro Cuenca <pedro@huggingface.co> * Remove transformers.js from list of inference widgets * Update docs/hub/transformers-js.md Co-authored-by: Pedro Cuenca <pedro@huggingface.co> --------- Co-authored-by: Omar Sanseviero <osanseviero@gmail.com> Co-authored-by: Pedro Cuenca <pedro@huggingface.co> Co-authored-by: Julien Chaumond <julien@huggingface.co>
- Loading branch information
1 parent
fe2df05
commit 59f6adb
Showing
5 changed files
with
115 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Using `Transformers.js` at Hugging Face | ||
|
||
Transformers.js is a JavaScript library for running 🤗 Transformers directly in your browser, with no need for a server! It is designed to be functionally equivalent to the original [Python library](https://github.com/huggingface/transformers), meaning you can run the same pretrained models using a very similar API. | ||
|
||
## Exploring `transformers.js` in the Hub | ||
|
||
You can find `transformers.js` models by filtering by library in the [models page](https://huggingface.co/models?library=transformers.js). | ||
|
||
|
||
|
||
## Quick tour | ||
|
||
|
||
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. | ||
|
||
<table> | ||
<tr> | ||
<th width="440px" align="center"><b>Python (original)</b></th> | ||
<th width="440px" align="center"><b>Javascript (ours)</b></th> | ||
</tr> | ||
<tr> | ||
<td> | ||
|
||
```python | ||
from transformers import pipeline | ||
|
||
# Allocate a pipeline for sentiment-analysis | ||
pipe = pipeline('sentiment-analysis') | ||
|
||
out = pipe('I love transformers!') | ||
# [{'label': 'POSITIVE', 'score': 0.999806941}] | ||
``` | ||
|
||
</td> | ||
<td> | ||
|
||
```javascript | ||
import { pipeline } from '@xenova/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}] | ||
``` | ||
|
||
</td> | ||
</tr> | ||
</table> | ||
|
||
|
||
You can also use a different model by specifying the model id or path as the second argument to the `pipeline` function. For example: | ||
```javascript | ||
// Use a different model for sentiment-analysis | ||
let pipe = await pipeline('sentiment-analysis', 'nlptown/bert-base-multilingual-uncased-sentiment'); | ||
``` | ||
|
||
Refer to the [documentation](https://huggingface.co/docs/transformers.js) for the full list of supported tasks and models. | ||
|
||
## Installation | ||
|
||
To install via [NPM](https://www.npmjs.com/package/@xenova/transformers), run: | ||
```bash | ||
npm i @xenova/transformers | ||
``` | ||
|
||
For more information, including how to use it in vanilla JS (without any bundler) via a CDN or static hosting, refer to the [README](https://github.com/xenova/transformers.js/blob/main/README.md#installation). | ||
|
||
|
||
## Additional resources | ||
|
||
* Transformers.js [repository](https://github.com/xenova/transformers.js) | ||
* Transformers.js [docs](https://huggingface.co/docs/transformers.js) | ||
* Transformers.js [demo](https://xenova.github.io/transformers.js/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters