Xenova HF staff commited on
Commit
7cb8f6b
1 Parent(s): cdfe1d2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +72 -0
README.md CHANGED
@@ -5,4 +5,76 @@ base_model: Qwen/Qwen2.5-Coder-0.5B-Instruct
5
 
6
  https://huggingface.co/Qwen/Qwen2.5-Coder-0.5B-Instruct with ONNX weights to be compatible with Transformers.js.
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
 
5
 
6
  https://huggingface.co/Qwen/Qwen2.5-Coder-0.5B-Instruct with ONNX weights to be compatible with Transformers.js.
7
 
8
+ ## Usage (Transformers.js)
9
+
10
+ If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@huggingface/transformers) using:
11
+ ```bash
12
+ npm i @huggingface/transformers
13
+ ```
14
+
15
+ **Example:** Text generation with `onnx-community/Qwen2.5-Coder-0.5B-Instruct`.
16
+
17
+ ```js
18
+ import { pipeline } from "@huggingface/transformers";
19
+
20
+ // Create a text generation pipeline
21
+ const generator = await pipeline(
22
+ "text-generation",
23
+ "onnx-community/Qwen2.5-Coder-0.5B-Instruct",
24
+ { dtype: "q4" },
25
+ );
26
+
27
+ // Define the list of messages
28
+ const messages = [
29
+ { role: "system", content: "You are a helpful assistant." },
30
+ { role: "user", content: "Write a quick sort algorithm." },
31
+ ];
32
+
33
+ // Generate a response
34
+ const output = await generator(messages, { max_new_tokens: 512, do_sample: false });
35
+ console.log(output[0].generated_text.at(-1).content);
36
+ ```
37
+
38
+ <details>
39
+
40
+ <summary>Example output</summary>
41
+
42
+ ````
43
+ Here's a simple implementation of the quick sort algorithm in Python:
44
+
45
+ ```python
46
+ def quick_sort(arr):
47
+ if len(arr) <= 1:
48
+ return arr
49
+
50
+ pivot = arr[len(arr) // 2]
51
+ left = [x for x in arr if x < pivot]
52
+ middle = [x for x in arr if x == pivot]
53
+ right = [x for x in arr if x > pivot]
54
+
55
+ return quick_sort(left) + middle + quick_sort(right)
56
+
57
+ # Example usage:
58
+ arr = [3, 6, 8, 10, 1, 2]
59
+ sorted_arr = quick_sort(arr)
60
+ print(sorted_arr)
61
+ ```
62
+
63
+ ### Explanation:
64
+
65
+ - **Base Case**: If the array has less than or equal to one element (i.e., `len(arr)` is less than or equal to `1`), it is already sorted and can be returned as is.
66
+
67
+ - **Pivot Selection**: The pivot is chosen as the middle element of the array.
68
+
69
+ - **Partitioning**: The array is partitioned into three parts: elements less than the pivot (`left`), elements equal to the pivot (`middle`), and elements greater than the pivot (`right`). These partitions are then recursively sorted.
70
+
71
+ - **Recursive Sorting**: The subarrays are sorted recursively using `quick_sort`.
72
+
73
+ This approach ensures that each recursive call reduces the problem size by half until it reaches a base case.
74
+ ````
75
+ </details>
76
+
77
+
78
+ ---
79
+
80
  Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).