transformers safetensors llama text-generation instruct finetune DPO distillation heathcare medical clinical med lifescience Pharmaceutical Pharma Enterprise LLM Enterprise Enterprise ready conversational en arxiv:2305.18290 license:other autotrain_compatible text-generation-inference endpoints_compatible region:us
---
base_model: Writer/Palmyra-x-003
language:
- en
license: other
license_name: writer-open-model-license
license_link: https://writer.com/legal/open-model-license/
tags:
- instruct
- finetune
- DPO
- distillation
- heathcare
- medical
- clinical
- med
- lifescience
- Pharmaceutical
- Pharma
- Enterprise LLM
- Enterprise
- Enterprise ready
model_type: palmyra
extra_gated_prompt: By clicking "Agree", you agree to the [License Agreement](https://writer.com/legal/open-model-license/)
  and acknowledge Writer's [Privacy Policy](https://writer.com/legal/acceptable-use/).
extra_gated_fields:
  Name: text
  Email: text
  Organization or Affiliation: text
  Receive email updates and promotions on Writer products, services, and research?:
    type: select
    options:
    - 'Yes'
    - 'No'
  I acknowledge that this model is for non-commercial use only unless I acquire a separate license from Writer: checkbox
widget:
- example_title: Palmyra-Med-70B
  messages:
  - role: system
    content: You are a highly knowledgeable and experienced expert in the healthcare
      and biomedical field, possessing extensive medical knowledge and practical expertise.
  - role: user
    content: Does danzhi Xiaoyao San ameliorate depressive-like behavior by shifting
      toward serotonin via the downregulation of hippocampal indoleamine 2,3-dioxygenase?
  output:
    text: Danzhi Xiaoyao San (DXS) exhibited significant antidepressant-like effects
      in rats subjected to chronic unpredictable mild stress (CUMS), a commonly used
      model for inducing depressive-like behavior. The administration of DXS led to
      a notable reduction in the activity of indoleamine 2,3-dioxygenase (IDO) in
      the hippocampus. This reduction in IDO activity is crucial because IDO is an
      enzyme that catalyzes the degradation of tryptophan into kynurenine (Kyn), thereby
      diverting tryptophan away from the serotonin (5-HT) synthesis pathway. By downregulating
      IDO, DXS effectively shifts the balance of tryptophan metabolism towards increased
      serotonin production, thereby enhancing the availability of serotonin. This
      shift in the Kyn/5-HT pathway favoring serotonin is likely a key mechanism underlying
      the antidepressant effects observed with DXS treatment. Enhanced serotonin levels
      in the hippocampus are associated with improved mood and reduction of depressive
      symptoms, suggesting that DXS could be a promising therapeutic agent for managing
      depression.
model-index:
- name: Palmyra-Med-70B
  results: []
---



<div align="center">
  <h1>Palmyra-Med, a powerful LLM designed for healthcare</h1>

<img src="img/Palmyra Medical wordmark.svg" width=420px  />
</div>


### Model Description

- **Developed by:** Writer
- **Language(s) (NLP):** English
- **License:** [Writer open model license](https://writer.com/legal/acceptable-use/)
- **Finetuned from model:** Palmyra-X-003
- **Context window:** 8192

## Model Details

Palmyra-Med is a model built by Writer specifically to meet the needs of the healthcare industry. The leading LLM on biomedical benchmarks, with an average score of 85.87%, outperforming GPT-4, claude Opus, Gemini and Med-PaLM-2 base model and a medically trained human test-taker.

### Resources and Technical Documentation:

+ [Writer Blog](https://writer.com/blog/palmyra-med-fin-models/)
+ [Writer Developer Website](https://dev.writer.com/home/models)
+ [Writer AI Studio](https://writer.com/product/ai-studio/)
+ [Palmyra Model API](https://dev.writer.com/api-guides/chat-completion)



#### Specialized for Biomedical Applications
Palmyra-Med-70B is meticulously designed to meet the unique linguistic and knowledge demands of the medical and life sciences sectors. It has been fine-tuned on an extensive collection of high-quality biomedical data, ensuring it can comprehend and generate text with precise domain-specific accuracy and fluency.

Our system integrates the DPO dataset and a well-crafted fine-tuning recipe along with a custom diverse medical instruction dataset, making it highly adept at handling the specific needs of this field. Key components of our training pipeline include:

- **Policy Optimization**: Utilizing Direct Preference Optimization to enhance the model's performance. [DPO](https://arxiv.org/abs/2305.18290).
- **Fine-tuning dataset**: Custom Medical Instruct dataset (Writer in-house build)




## Intended Use

**Intended Use Cases:**  Palmyra-Med-70b is intended for **non**-commercial and research use in English. Instruction tuned models are intended for assistant-like chat, whereas pretrained models can be adapted for a variety of natural language generation tasks.

**Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in any other way that is prohibited by [Writer's Acceptable Use Policy](https://writer.com/legal/acceptable-use/) and [the Writer open model license](https://writer.com/legal/acceptable-use/). Use in languages other than English.

**Note:** Developers may fine-tune Palmyra-Med-70b models for languages beyond English provided they comply with the [Writer open model license](https://writer.com/legal/acceptable-use/) and the Acceptable Use Policy.

**Watermarks**: All models built by Writer.com contain watermarks to detect and prevent misuse and illegal use.


### Use with transformers

You can run conversational inference using the Transformers Auto classes with the `generate()` function. Let's see an example.


```py
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_id = "Writer/Palmyra-Med-70B"

tokenizer = AutoTokenizer.from_pretrained(model_id)

model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.float16,
    device_map="auto",
    attn_implementation="flash_attention_2",
)

messages = [
    {
        "role": "system",
        "content": "You are a highly knowledgeable and experienced expert in the healthcare and biomedical field, possessing extensive medical knowledge and practical expertise.",
    },
    {
        "role": "user",
        "content": "Does danzhi Xiaoyao San ameliorate depressive-like behavior by shifting toward serotonin via the downregulation of hippocampal indoleamine 2,3-dioxygenase?",
    },
]

input_ids = tokenizer.apply_chat_template(
    messages, tokenize=True, add_generation_prompt=True, return_tensors="pt"
)

gen_conf = {
    "max_new_tokens": 256,
    "eos_token_id": [tokenizer.eos_token_id, tokenizer.convert_tokens_to_ids("<|eot_id|>")],
    "temperature": 0.0,
    "top_p": 0.9,
}

with torch.inference_mode():
    output_id = model.generate(input_ids, **gen_conf)

output_text = tokenizer.decode(output_id[0][input_ids.shape[1] :])

print(output_text)
```


## Evaluation Results

Palmyra-Med-70b outperforms larger models like GPT-4, Gemini and Med-PaLM-2 across 9 diverse biomedical datasets, achieving state-of-the-art results with an average score of 85.9% despite having fewer parameters. Its strong performance in tasks like Clinical KG, Medical Genetics, and PubMedQA underscores its effective grasp of biomedical knowledge.


### Performance on Biomedical Benchmarks


![Palmyra-Med-70b Performance](img/med_model_chart.png)

![Palmyra-Med-70b Performance Heat Map](img/med_model_heatmap.png)

### Medical Use Cases

Palmyra-Med-70b excels in analyzing and summarizing complex clinical notes, EHR data, and discharge summaries, extracting key information to generate concise, structured summaries. It help enhance clinical decision-making by performing advanced clinical entity recognition, identifying key medical concepts such as diseases, symptoms, medications, procedures, and anatomical structures from unstructured text. 

By leveraging its deep understanding of medical terminology, the model enhances information retrieval, data analysis, and knowledge discovery from EHRs, research articles, and other biomedical sources. These capabilities support applications like clinical decision support, pharmacovigilance, and medical research.


### Bias, Risks, and Limitations

Palmyra-Med-70b, despite leveraging high-quality data, may contain inaccuracies, biases, or misalignments and has not been rigorously evaluated in clinical trials or real-world healthcare settings. 


It is advised not to use the model for direct patient care, clinical decision support, or professional medical purposes. Instead, its use should be confined to research by qualified individuals who understand its limitations. Palmyra-Med-70b should not replace professional medical judgment, and adapting it for medical use would require extensive additional work, including thorough testing, guideline alignment, bias mitigation, human oversight, and regulatory compliance. Always consult a qualified healthcare provider for personal medical needs.


### Citation and Related Information

To cite this model:

```
@misc{Palmyra-Med-70B,
  author = {Writer Engineering team},
  title = {{Palmyra-Med-70b: A powerful LLM designed for healthcare}},
  howpublished = {\url{https://dev.writer.com}},
  year = 2024,
  month = June 
}
```

Contact
Hello@writer.com


