Update README.md
Browse files
README.md
CHANGED
|
@@ -69,30 +69,29 @@ device = 'cuda'
|
|
| 69 |
set_seed(42)
|
| 70 |
|
| 71 |
# Loading the model tokenizer.
|
| 72 |
-
|
| 73 |
|
| 74 |
# Causal Language Models predict tokens from left to right and use EOS token for padding.
|
| 75 |
tokenizer.pad_token = tokenizer.eos_token
|
| 76 |
tokenizer.padding_side = 'right'
|
| 77 |
|
| 78 |
-
|
| 79 |
# Load the model from the path to the device and set it in evaluation mode.
|
| 80 |
-
|
| 81 |
-
|
| 82 |
|
| 83 |
# Set the system, instruction and user prompts.
|
| 84 |
system_prompt = 'Είσαι ο Μαΐστρος, ένα εξαιρετικά ανεπτυγμένο μοντέλο Τεχνητής Νοημοσύνης για την Ελληνική γλώσσα.\nΈχεις δημιουργηθεί απο το IMIS Lab του Πανεπιστημιού Πατρών.'
|
| 85 |
instruction_prompt = 'Παρακαλώ απάντησε στην παρακάτω απάντηση.'
|
| 86 |
-
user_prompt = ''
|
| 87 |
|
| 88 |
# Defining the message template.
|
| 89 |
messages = [
|
| 90 |
-
{'role': 'system', 'content': [{'type': 'text', 'text': system_prompt}]}
|
| 91 |
{'role': 'user', 'content': [{'type': 'text', 'text': '\n\n'.join((instruction_prompt, user_prompt))}]}
|
| 92 |
]
|
| 93 |
|
| 94 |
# Applying the tokenizer chat template.
|
| 95 |
-
tokenized =
|
| 96 |
messages,
|
| 97 |
add_generation_prompt = True,
|
| 98 |
return_tensors = 'pt',
|
|
@@ -100,13 +99,13 @@ tokenized = self.tokenizer.apply_chat_template(
|
|
| 100 |
)
|
| 101 |
|
| 102 |
# Sending the tokenized instances to the device.
|
| 103 |
-
tokenized = {k: v.to(
|
| 104 |
input_len = len(tokenized['input_ids'][0])
|
| 105 |
|
| 106 |
# Generating the model output.
|
| 107 |
-
output =
|
| 108 |
**tokenized,
|
| 109 |
-
max_new_tokens =
|
| 110 |
do_sample = False, # Equivalent to temperature = 0.0
|
| 111 |
temperature = None,
|
| 112 |
top_p = None,
|
|
@@ -114,7 +113,7 @@ output = self.model.generate(
|
|
| 114 |
)
|
| 115 |
|
| 116 |
# Decoding the assistant part of the output and printing it.
|
| 117 |
-
decoded_output =
|
| 118 |
print(decoded_output)
|
| 119 |
```
|
| 120 |
|
|
|
|
| 69 |
set_seed(42)
|
| 70 |
|
| 71 |
# Loading the model tokenizer.
|
| 72 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code = True)
|
| 73 |
|
| 74 |
# Causal Language Models predict tokens from left to right and use EOS token for padding.
|
| 75 |
tokenizer.pad_token = tokenizer.eos_token
|
| 76 |
tokenizer.padding_side = 'right'
|
| 77 |
|
|
|
|
| 78 |
# Load the model from the path to the device and set it in evaluation mode.
|
| 79 |
+
model = Mistral3ForConditionalGeneration.from_pretrained(model_path, device_map = device, trust_remote_code = True)
|
| 80 |
+
model.eval()
|
| 81 |
|
| 82 |
# Set the system, instruction and user prompts.
|
| 83 |
system_prompt = 'Είσαι ο Μαΐστρος, ένα εξαιρετικά ανεπτυγμένο μοντέλο Τεχνητής Νοημοσύνης για την Ελληνική γλώσσα.\nΈχεις δημιουργηθεί απο το IMIS Lab του Πανεπιστημιού Πατρών.'
|
| 84 |
instruction_prompt = 'Παρακαλώ απάντησε στην παρακάτω απάντηση.'
|
| 85 |
+
user_prompt = 'Τι είναι η Ακρόπολη των Αθηνών;'
|
| 86 |
|
| 87 |
# Defining the message template.
|
| 88 |
messages = [
|
| 89 |
+
{'role': 'system', 'content': [{'type': 'text', 'text': system_prompt}]},
|
| 90 |
{'role': 'user', 'content': [{'type': 'text', 'text': '\n\n'.join((instruction_prompt, user_prompt))}]}
|
| 91 |
]
|
| 92 |
|
| 93 |
# Applying the tokenizer chat template.
|
| 94 |
+
tokenized = tokenizer.apply_chat_template(
|
| 95 |
messages,
|
| 96 |
add_generation_prompt = True,
|
| 97 |
return_tensors = 'pt',
|
|
|
|
| 99 |
)
|
| 100 |
|
| 101 |
# Sending the tokenized instances to the device.
|
| 102 |
+
tokenized = {k: v.to(device) for k, v in tokenized.items()}
|
| 103 |
input_len = len(tokenized['input_ids'][0])
|
| 104 |
|
| 105 |
# Generating the model output.
|
| 106 |
+
output = model.generate(
|
| 107 |
**tokenized,
|
| 108 |
+
max_new_tokens = 1024,
|
| 109 |
do_sample = False, # Equivalent to temperature = 0.0
|
| 110 |
temperature = None,
|
| 111 |
top_p = None,
|
|
|
|
| 113 |
)
|
| 114 |
|
| 115 |
# Decoding the assistant part of the output and printing it.
|
| 116 |
+
decoded_output = tokenizer.decode(output[0][input_len:], skip_special_tokens = True)
|
| 117 |
print(decoded_output)
|
| 118 |
```
|
| 119 |
|