Views
No views yet

1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3def generate_response(prompt):
4 """
5 Generate a response from the model based on the input prompt.
6
7 Args:
8 prompt (str): Prompt for the model.
9
10 Returns:
11 str: The generated response from the model.
12 """
13 # Tokenize the input prompt
14 inputs = tokenizer(prompt, return_tensors="pt")
15
16 # Generate output tokens
17 outputs = model.generate(**inputs, max_new_tokens=256, eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.pad_token_id)
18
19 # Decode the generated tokens to a string
20 response = tokenizer.decode(outputs[0], skip_special_tokens=True)
21
22 return response
23
24# Load the model and tokenizer
25model_id = "macadeliccc/laser-polyglot-4x7b"
26tokenizer = AutoTokenizer.from_pretrained(model_id)
27model = AutoModelForCausalLM.from_pretrained(model_id, load_in_4bit=True)
28
29# Example prompts in different languages
30english_prompt = "Write a quicksort algorithm in python"
31chinese_prompt = "用Python写一个快速排序算法"
32japanese_prompt = "Pythonでクイックソートアルゴリズムを書いてください"
33
34# Generate and print responses for each language
35print("English Response:")
36print(generate_response(english_prompt), "\n")
37
38print("Chinese Response:")
39print(generate_response(chinese_prompt), "\n")
40
41print("Japanese Response:")
42print(generate_response(japanese_prompt), "\n")
431def quicksort(arr):
2 if len(arr) <= 1:
3 return arr
4 else:
5 pivot = arr[0]
6 less = [i for i in arr[1:] if i <= pivot]
7 greater = [i for i in arr[1:] if i > pivot]
8 return quicksort(less) + [pivot] + quicksort(greater)
9
10arr = [5, 2, 9, 1, 5, 7, 4, 8, 6, 3]
11print(quicksort(arr))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.1def quick_sort(arr):
2 if len(arr) <= 1:
3 return arr
4 else:
5 pivot = arr[0]
6 less = [i for i in arr[1:] if i <= pivot]
7 greater = [i for i in arr[1:] if i > pivot]
8 return quick_sort(less) + [pivot] + quick_sort(greater)
9
10arr = [3, 5, 2, 1, 4, 6, 8, 7]
11print(quick_sort(arr))1def quicksort(arr):
2 if len(arr) <= 1:
3 return arr
4 pivot = arr[0]
5 left = [x for x in arr[1:] if x < pivot]
6 right = [x for x in arr[1:] if x >= pivot]
7 return quicksort(left) + [pivot] + quicksort(right)
8
9print(quicksort([3,6,8,10,1,5,9,2,4,7]))| Tasks | Version | Filter | n-shot | Metric | Value | Stderr | |
|---|---|---|---|---|---|---|---|
| arc_challenge | Yaml | none | 0 | acc | 0.5495 | ± | 0.0145 |
| none | 0 | acc_norm | 0.5794 | ± | 0.0144 | ||
| arc_easy | Yaml | none | 0 | acc | 0.8304 | ± | 0.0077 |
| none | 0 | acc_norm | 0.8068 | ± | 0.0081 | ||
| boolq | Yaml | none | 0 | acc | 0.8749 | ± | 0.0058 |
| hellaswag | Yaml | none | 0 | acc | 0.6276 | ± | 0.0048 |
| none | 0 | acc_norm | 0.8157 | ± | 0.0039 | ||
| openbookqa | Yaml | none | 0 | acc | 0.3180 | ± | 0.0208 |
| none | 0 | acc_norm | 0.4460 | ± | 0.0223 | ||
| piqa | Yaml | none | 0 | acc | 0.8139 | ± | 0.0091 |
| none | 0 | acc_norm | 0.8237 | ± | 0.0089 | ||
| winogrande | Yaml | none | 0 | acc | 0.7419 | ± | 0.0123 |
| Metric | Value |
|---|---|
| Avg. | 65.79 |
| AI2 Reasoning Challenge (25-Shot) | 64.16 |
| HellaSwag (10-Shot) | 84.98 |
| MMLU (5-Shot) | 63.88 |
| TruthfulQA (0-shot) | 55.47 |
| Winogrande (5-shot) | 77.82 |
| GSM8k (5-shot) | 48.45 |