Add Transformers.js library tag and sample code (#6)
Browse files- Add Transformers.js library tag and sample code (3d0766beb5f2b3d75633f547dbdbbcb260bd9327)
- Update README.md (b910065e67bb86f73e8a2f6a64d4703d6666a419)
Co-authored-by: Joshua <[email protected]>
README.md
CHANGED
@@ -11,6 +11,7 @@ language:
|
|
11 |
library_name: transformers
|
12 |
tags:
|
13 |
- text2text-generation
|
|
|
14 |
widget:
|
15 |
- text: >-
|
16 |
Teapot is an open-source small language model (~800 million parameters) fine-tuned on synthetic data and optimized to run locally on resource-constrained devices such as smartphones and CPUs.
|
@@ -264,6 +265,25 @@ answer = teapot_ai(context+"\n"+question)
|
|
264 |
print(answer[0].get('generated_text')) # => The Eiffel Tower stands at a height of 330 meters.
|
265 |
```
|
266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
---
|
268 |
|
269 |
|
|
|
11 |
library_name: transformers
|
12 |
tags:
|
13 |
- text2text-generation
|
14 |
+
- transformers.js
|
15 |
widget:
|
16 |
- text: >-
|
17 |
Teapot is an open-source small language model (~800 million parameters) fine-tuned on synthetic data and optimized to run locally on resource-constrained devices such as smartphones and CPUs.
|
|
|
265 |
print(answer[0].get('generated_text')) # => The Eiffel Tower stands at a height of 330 meters.
|
266 |
```
|
267 |
|
268 |
+
### Transformers.js Support
|
269 |
+
|
270 |
+
You can even run the model in-browser (or any other JavaScript environment) with [Transformers.js](https://huggingface.co/docs/transformers.js) as follows:
|
271 |
+
|
272 |
+
```js
|
273 |
+
// npm i @huggingface/transformers
|
274 |
+
import { pipeline } from "@huggingface/transformers";
|
275 |
+
|
276 |
+
const teapot_ai = await pipeline("text2text-generation", "teapotai/teapotllm");
|
277 |
+
|
278 |
+
const context = `
|
279 |
+
The Eiffel Tower is a wrought iron lattice tower in Paris, France. It was designed by Gustave Eiffel and completed in 1889.
|
280 |
+
It stands at a height of 330 meters and is one of the most recognizable structures in the world.
|
281 |
+
`;
|
282 |
+
const question = "What is the height of the Eiffel Tower?";
|
283 |
+
const answer = await teapot_ai(context + "\n" + question);
|
284 |
+
console.log(answer[0].generated_text); // => " The Eiffel Tower stands at a height of 330 meters."
|
285 |
+
```
|
286 |
+
|
287 |
---
|
288 |
|
289 |
|