Llama3-Med42-70B
2.1K
65
1 language
llama
by
m42-health
Language Model
OTHER
70B params
New
2K downloads
Early-stage
Edge AI:
Mobile
Laptop
Server
157GB+ RAM
Mobile
Laptop
Server
Quick Summary
AI model with specialized capabilities.
Device Compatibility
Mobile
4-6GB RAM
Laptop
16GB RAM
Server
GPU
Minimum Recommended
66GB+ RAM
Training Data Analysis
🟡 Average (4.8/10)
Researched training datasets used by Llama3-Med42-70B with quality assessment
Specialized For
general
science
multilingual
reasoning
Training Datasets (4)
common crawl
🔴 2.5/10
general
science
Key Strengths
- •Scale and Accessibility: At 9.5+ petabytes, Common Crawl provides unprecedented scale for training d...
- •Diversity: The dataset captures billions of web pages across multiple domains and content types, ena...
- •Comprehensive Coverage: Despite limitations, Common Crawl attempts to represent the broader web acro...
Considerations
- •Biased Coverage: The crawling process prioritizes frequently linked domains, making content from dig...
- •Large-Scale Problematic Content: Contains significant amounts of hate speech, pornography, violent c...
c4
🔵 6/10
general
multilingual
Key Strengths
- •Scale and Accessibility: 750GB of publicly available, filtered text
- •Systematic Filtering: Documented heuristics enable reproducibility
- •Language Diversity: Despite English-only, captures diverse writing styles
Considerations
- •English-Only: Limits multilingual applications
- •Filtering Limitations: Offensive content and low-quality text remain despite filtering
wikipedia
🟡 5/10
science
multilingual
Key Strengths
- •High-Quality Content: Wikipedia articles are subject to community review, fact-checking, and citatio...
- •Multilingual Coverage: Available in 300+ languages, enabling training of models that understand and ...
- •Structured Knowledge: Articles follow consistent formatting with clear sections, allowing models to ...
Considerations
- •Language Inequality: Low-resource language editions have significantly lower quality, fewer articles...
- •Biased Coverage: Reflects biases in contributor demographics; topics related to Western culture and ...
arxiv
🟡 5.5/10
science
reasoning
Key Strengths
- •Scientific Authority: Peer-reviewed content from established repository
- •Domain-Specific: Specialized vocabulary and concepts
- •Mathematical Content: Includes complex equations and notation
Considerations
- •Specialized: Primarily technical and mathematical content
- •English-Heavy: Predominantly English-language papers
Explore our comprehensive training dataset analysis
View All DatasetsCode Examples
pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])pythontransformers
import transformers
import torch
model_name_or_path = "m42-health/Llama3-Med42-70B"
pipeline = transformers.pipeline(
"text-generation",
model=model_name_or_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
messages = [
{
"role": "system",
"content": (
"You are a helpful, respectful and honest medical assistant. You are a second version of Med42 developed by the AI team at M42, UAE. "
"Always answer as helpfully as possible, while being safe. "
"Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. "
"Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. "
"If you don’t know the answer to a question, please don’t share false information."
),
},
{"role": "user", "content": "What are the symptoms of diabetes?"},
]
prompt = pipeline.tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=False
)
stop_tokens = [
pipeline.tokenizer.eos_token_id,
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"),
]
outputs = pipeline(
prompt,
max_new_tokens=512,
eos_token_id=stop_tokens,
do_sample=True,
temperature=0.4,
top_k=150,
top_p=0.75,
)
print(outputs[0]["generated_text"][len(prompt) :])Deploy This Model
Production-ready deployment in minutes
Together.ai
Instant API access to this model
Production-ready inference API. Start free, scale to millions.
Try Free APIReplicate
One-click model deployment
Run models in the cloud with simple API. No DevOps required.
Deploy NowDisclosure: We may earn a commission from these partners. This helps keep LLMYourWay free.