-
Notifications
You must be signed in to change notification settings - Fork 390
Add Transformers.js as a supported library #854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ae9275e
86bbbcf
b07acec
96608f8
33e9bca
c736384
1a82458
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. off topic from this PR, but maybe at some point we should ship it under
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be HUGE! 🚀 We can maybe align the move with a major version release too 👍 (e.g., when WebGPU is supported?). On that note, however, the npm docs say that it isn't possible to transfer a scoped package to another organization. So, we'll either need to create a new package in the new scope, or get custom support for this.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. creating a new package is probably fine. Pinging @coyotte508 to add you to our npm org for when we want to make the switch
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @julien-c I think you will have to do it, I don't see the option Alternatively we can add the secret to the repo (like when publishing hf.js), to be able to publish through github actions |
||
| ``` | ||
|
|
||
| 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/) | ||

Uh oh!
There was an error while loading. Please reload this page.