Xenova HF staff commited on
Commit
a7f074e
1 Parent(s): d6da6d4

Add example code to README

Browse files
Files changed (1) hide show
  1. README.md +26 -0
README.md CHANGED
@@ -4,3 +4,29 @@ library_name: "transformers.js"
4
  ---
5
 
6
  INT8 ONNX version of [Locutusque/TinyMistral-248M](https://huggingface.co/Locutusque/TinyMistral-248M) to use with [Transformers.js](https://huggingface.co/docs/transformers.js).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
  INT8 ONNX version of [Locutusque/TinyMistral-248M](https://huggingface.co/Locutusque/TinyMistral-248M) to use with [Transformers.js](https://huggingface.co/docs/transformers.js).
7
+
8
+ ### Example usage
9
+ #### Pipeline API
10
+ ```js
11
+ import { pipeline } from '@xenova/transformers';
12
+
13
+ const generator = await pipeline('text-generation', 'Felladrin/onnx-int8-TinyMistral-248M');
14
+ const output = await generator('Once upon a time,', { add_special_tokens: true, max_new_tokens: 60, repetition_penalty: 1.2});
15
+ console.log(output);
16
+ // 'Once upon a time, the world was in turmoil. The United States had been on an unprecedented hiatus since 1970 and it seemed that America’s role as a global powerhouse would be at risk if we were to continue with our current political system.\n\nThe US has become'
17
+ ```
18
+
19
+ #### Auto Classes
20
+ ```js
21
+ import { AutoModelForCausalLM, AutoTokenizer } from '@xenova/transformers'
22
+
23
+ const model_path = 'Felladrin/onnx-int8-TinyMistral-248M';
24
+ const model = await AutoModelForCausalLM.from_pretrained(model_path);
25
+ const tokenizer = await AutoTokenizer.from_pretrained(model_path);
26
+
27
+ const prompt = 'Once upon a time,';
28
+ const { input_ids } = tokenizer(prompt);
29
+ const tokens = await model.generate(input_ids, { max_new_tokens: 60, repetition_penalty: 1.2});
30
+ console.log(tokenizer.decode(tokens[0], { skip_special_tokens: true }));
31
+ // 'Once upon a time, the world was in turmoil. The United States had been on an unprecedented hiatus since 1970 and it seemed that America’s role as a global powerhouse would be at risk if we were to continue with our current political system.\n\nThe US has become'
32
+ ```