Xenova HF staff commited on
Commit
bd96243
·
verified ·
1 Parent(s): 09095b1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +73 -0
README.md CHANGED
@@ -5,4 +5,77 @@ base_model: Qwen/Qwen2.5-Coder-1.5B-Instruct
5
 
6
  https://huggingface.co/Qwen/Qwen2.5-Coder-1.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-1.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-1.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-1.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
+ Sure! Below is the implementation of the QuickSort algorithm in Python:
44
+
45
+ ```python
46
+ def quicksort(arr):
47
+ if len(arr) <= 1:
48
+ return arr
49
+
50
+ pivot = arr[len(arr) // 2]
51
+
52
+ left = [x for x in arr if x < pivot]
53
+ middle = [x for x in arr if x == pivot]
54
+ right = [x for x in arr if x > pivot]
55
+
56
+ return quicksort(left) + middle + quicksort(right)
57
+
58
+ # Example usage:
59
+ arr = [3, 6, 8, 10, 1, 2, 1]
60
+ print("Original array:", arr)
61
+ sorted_arr = quicksort(arr)
62
+ print("Sorted array:", sorted_arr)
63
+ ```
64
+
65
+ ### Explanation:
66
+ - **Base Case**: If the length of the list `arr` is less than or equal to one (`len(arr) <= 1`), it means the list is already sorted and can be returned as it is.
67
+ - **Pivot Selection**: The chosen `pivot` element can be any element from the list (e.g., `len(arr)//2`). For simplicity here we choose this way.
68
+ - **Partitioning**:
69
+ - Elements less than or equal to `pivot` are placed into a new list called `left`.
70
+ - Elements equal to `pivot` are placed into another new list called `middle`.
71
+ - Elements greater than or equal to `pivot` are placed into yet another new list called `right`.
72
+ - **Recursive Sorting**: The function recursively applies itself on these three lists (`left`, middle`, and right`) and concatenates them back together.
73
+
74
+ This implementation ensures that all elements less than or equal to any given element will appear before that element in their respective partitions.
75
+ ````
76
+ </details>
77
+
78
+
79
+ ---
80
+
81
  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`).