macadeliccc
commited on
Commit
•
479296a
1
Parent(s):
53aa454
Update README.md
Browse files
README.md
CHANGED
@@ -5,7 +5,9 @@ license: apache-2.0
|
|
5 |
|
6 |
![polyglot](polyglot.png)
|
7 |
|
8 |
-
|
|
|
|
|
9 |
|
10 |
The model is a merge of models that are capable of Chinese and Japanese output.
|
11 |
|
@@ -20,49 +22,34 @@ The model is a merge of models that are capable of Chinese and Japanese output.
|
|
20 |
Inference [Colab](https://colab.research.google.com/drive/1tYSb63IKZDsiQ5BIJU8Oc92phxugAmB3?usp=sharing)
|
21 |
|
22 |
```python
|
23 |
-
|
24 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
25 |
-
|
26 |
-
# Load tokenizer and model
|
27 |
-
tokenizer = AutoTokenizer.from_pretrained("macadeliccc/laser-polyglot-4x7b")
|
28 |
-
model = AutoModelForCausalLM.from_pretrained("macadeliccc/laser-polyglot-4x7b",load_in_4bit=True)
|
29 |
|
30 |
-
def generate_response(prompt
|
31 |
"""
|
32 |
-
Generate a response from the model based on the input prompt
|
33 |
|
34 |
Args:
|
35 |
prompt (str): Prompt for the model.
|
36 |
-
max_length (int): Maximum length of the model's response.
|
37 |
-
num_return_sequences (int): Number of response sequences to generate.
|
38 |
-
temperature (float): Sampling temperature for model generation.
|
39 |
-
top_k (int): The number of highest probability vocabulary tokens to keep for top-k filtering.
|
40 |
-
top_p (float): If set to float < 1, only the most probable tokens with probabilities that add up to top_p or higher are kept for generation.
|
41 |
|
42 |
Returns:
|
43 |
str: The generated response from the model.
|
44 |
"""
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
# Apply chat template to input messages
|
51 |
-
gen_input = tokenizer.apply_chat_template(messages, return_tensors="pt")
|
52 |
-
|
53 |
-
# Generate a response
|
54 |
-
output = model.generate(**gen_input,
|
55 |
-
max_length=max_length,
|
56 |
-
num_return_sequences=num_return_sequences,
|
57 |
-
temperature=temperature,
|
58 |
-
top_k=top_k,
|
59 |
-
top_p=top_p)
|
60 |
|
61 |
# Decode the generated tokens to a string
|
62 |
-
response = tokenizer.decode(
|
63 |
|
64 |
return response
|
65 |
|
|
|
|
|
|
|
|
|
|
|
66 |
# Example prompts in different languages
|
67 |
english_prompt = "Write a quicksort algorithm in python"
|
68 |
chinese_prompt = "用Python写一个快速排序算法"
|
@@ -70,15 +57,78 @@ japanese_prompt = "Pythonでクイックソートアルゴリズムを書いて
|
|
70 |
|
71 |
# Generate and print responses for each language
|
72 |
print("English Response:")
|
73 |
-
print(generate_response(english_prompt
|
74 |
|
75 |
print("Chinese Response:")
|
76 |
-
print(generate_response(chinese_prompt
|
77 |
|
78 |
print("Japanese Response:")
|
79 |
-
print(generate_response(japanese_prompt
|
|
|
80 |
```
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
# Evaluations
|
83 |
|
84 |
| Tasks |Version|Filter|n-shot| Metric |Value | |Stderr|
|
|
|
5 |
|
6 |
![polyglot](polyglot.png)
|
7 |
|
8 |
+
Polyglot-4x7b is a Mixture of Experts approach to a multilingual model.
|
9 |
+
|
10 |
+
This project is an experiment to see if each expert can be of a different language. The answer is yes.
|
11 |
|
12 |
The model is a merge of models that are capable of Chinese and Japanese output.
|
13 |
|
|
|
22 |
Inference [Colab](https://colab.research.google.com/drive/1tYSb63IKZDsiQ5BIJU8Oc92phxugAmB3?usp=sharing)
|
23 |
|
24 |
```python
|
25 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
+
def generate_response(prompt):
|
28 |
"""
|
29 |
+
Generate a response from the model based on the input prompt.
|
30 |
|
31 |
Args:
|
32 |
prompt (str): Prompt for the model.
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
Returns:
|
35 |
str: The generated response from the model.
|
36 |
"""
|
37 |
+
# Tokenize the input prompt
|
38 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
39 |
+
|
40 |
+
# Generate output tokens
|
41 |
+
outputs = model.generate(**inputs, max_new_tokens=256, eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.pad_token_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
# Decode the generated tokens to a string
|
44 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
45 |
|
46 |
return response
|
47 |
|
48 |
+
# Load the model and tokenizer
|
49 |
+
model_id = "macadeliccc/laser-polyglot-4x7b"
|
50 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
51 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, load_in_4bit=True)
|
52 |
+
|
53 |
# Example prompts in different languages
|
54 |
english_prompt = "Write a quicksort algorithm in python"
|
55 |
chinese_prompt = "用Python写一个快速排序算法"
|
|
|
57 |
|
58 |
# Generate and print responses for each language
|
59 |
print("English Response:")
|
60 |
+
print(generate_response(english_prompt), "\n")
|
61 |
|
62 |
print("Chinese Response:")
|
63 |
+
print(generate_response(chinese_prompt), "\n")
|
64 |
|
65 |
print("Japanese Response:")
|
66 |
+
print(generate_response(japanese_prompt), "\n")
|
67 |
+
|
68 |
```
|
69 |
|
70 |
+
## Example Output
|
71 |
+
English:
|
72 |
+
|
73 |
+
Write a quicksort algorithm in python.
|
74 |
+
|
75 |
+
```python
|
76 |
+
def quicksort(arr):
|
77 |
+
if len(arr) <= 1:
|
78 |
+
return arr
|
79 |
+
else:
|
80 |
+
pivot = arr[0]
|
81 |
+
less = [i for i in arr[1:] if i <= pivot]
|
82 |
+
greater = [i for i in arr[1:] if i > pivot]
|
83 |
+
return quicksort(less) + [pivot] + quicksort(greater)
|
84 |
+
|
85 |
+
arr = [5, 2, 9, 1, 5, 7, 4, 8, 6, 3]
|
86 |
+
print(quicksort(arr))
|
87 |
+
```
|
88 |
+
|
89 |
+
This is a simple implementation of the quicksort algorithm in python. The function `quicksort` takes an array as input and returns a sorted array. The algorithm works by selecting a pivot element from the array and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot. The process is then repeated recursively on the sub-arrays until the entire array is sorted.
|
90 |
+
|
91 |
+
Chinese Response:
|
92 |
+
|
93 |
+
用Python写一个快速排序算法
|
94 |
+
|
95 |
+
```python
|
96 |
+
def quick_sort(arr):
|
97 |
+
if len(arr) <= 1:
|
98 |
+
return arr
|
99 |
+
else:
|
100 |
+
pivot = arr[0]
|
101 |
+
less = [i for i in arr[1:] if i <= pivot]
|
102 |
+
greater = [i for i in arr[1:] if i > pivot]
|
103 |
+
return quick_sort(less) + [pivot] + quick_sort(greater)
|
104 |
+
|
105 |
+
arr = [3, 5, 2, 1, 4, 6, 8, 7]
|
106 |
+
print(quick_sort(arr))
|
107 |
+
```
|
108 |
+
这个程序的时间复杂度为O(nlogn),空间复杂度为O(n)。
|
109 |
+
|
110 |
+
Japanese Response:
|
111 |
+
|
112 |
+
Pythonでクイックソートアルゴリズムを書いてください。
|
113 |
+
|
114 |
+
```python
|
115 |
+
def quicksort(arr):
|
116 |
+
if len(arr) <= 1:
|
117 |
+
return arr
|
118 |
+
pivot = arr[0]
|
119 |
+
left = [x for x in arr[1:] if x < pivot]
|
120 |
+
right = [x for x in arr[1:] if x >= pivot]
|
121 |
+
return quicksort(left) + [pivot] + quicksort(right)
|
122 |
+
|
123 |
+
print(quicksort([3,6,8,10,1,5,9,2,4,7]))
|
124 |
+
```
|
125 |
+
|
126 |
+
このコードはクイックソートアルゴリズムを実装しています。クイックソートは一種の分割と conquers アルゴリズムで、配列を分割し、それぞれの部分配列を再帰的にソートします。
|
127 |
+
|
128 |
+
この実装では、配列の最初の要素をピボットとして使用します。そして、配列を2つの
|
129 |
+
|
130 |
+
|
131 |
+
|
132 |
# Evaluations
|
133 |
|
134 |
| Tasks |Version|Filter|n-shot| Metric |Value | |Stderr|
|