prince-canuma
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -35,6 +35,7 @@ import torch
|
|
35 |
from pathlib import Path
|
36 |
from transformers import AutoModelForCausalLM
|
37 |
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
|
|
38 |
from mistral_common.protocol.instruct.messages import UserMessage
|
39 |
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
40 |
from huggingface_hub import snapshot_download
|
@@ -68,7 +69,10 @@ def load_chat_request(message: str) -> ChatCompletionRequest:
|
|
68 |
model_name = "prince-canuma/Ministral-8B-Instruct-2410-HF"
|
69 |
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
|
70 |
model_path = get_model_path(model_name)
|
|
|
71 |
tokenizer = MistralTokenizer.from_file(f"{model_path}/tokenizer.json")
|
|
|
|
|
72 |
|
73 |
# Chat interaction
|
74 |
user_message = "Tell me a short story about a robot learning to paint."
|
@@ -78,10 +82,11 @@ input_ids = torch.tensor(tokens).unsqueeze(0)
|
|
78 |
|
79 |
# Generate response
|
80 |
output = model.generate(input_ids, max_new_tokens=500, temperature=0.7, do_sample=True)
|
81 |
-
response = tokenizer.decode(output[0][input_ids.shape[1]:])
|
82 |
|
83 |
print("User:", user_message)
|
84 |
print("Model:", response)
|
|
|
85 |
```
|
86 |
|
87 |
## Model Details
|
|
|
35 |
from pathlib import Path
|
36 |
from transformers import AutoModelForCausalLM
|
37 |
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
|
38 |
+
from mistral_common.tokens.tokenizers.tekken import SpecialTokenPolicy
|
39 |
from mistral_common.protocol.instruct.messages import UserMessage
|
40 |
from mistral_common.protocol.instruct.request import ChatCompletionRequest
|
41 |
from huggingface_hub import snapshot_download
|
|
|
69 |
model_name = "prince-canuma/Ministral-8B-Instruct-2410-HF"
|
70 |
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
|
71 |
model_path = get_model_path(model_name)
|
72 |
+
|
73 |
tokenizer = MistralTokenizer.from_file(f"{model_path}/tokenizer.json")
|
74 |
+
tekken = tokenizer.instruct_tokenizer.tokenizer
|
75 |
+
tekken.special_token_policy = SpecialTokenPolicy.IGNORE
|
76 |
|
77 |
# Chat interaction
|
78 |
user_message = "Tell me a short story about a robot learning to paint."
|
|
|
82 |
|
83 |
# Generate response
|
84 |
output = model.generate(input_ids, max_new_tokens=500, temperature=0.7, do_sample=True)
|
85 |
+
response = tokenizer.decode(output[0][input_ids.shape[1]:].tolist())
|
86 |
|
87 |
print("User:", user_message)
|
88 |
print("Model:", response)
|
89 |
+
|
90 |
```
|
91 |
|
92 |
## Model Details
|