initial commit

This commit is contained in:
ahmed-ai 2024-01-30 18:18:14 +03:00
commit 35f4fa39b2
3 changed files with 160 additions and 0 deletions

BIN
1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 KiB

126
Galen_AI_Demo.ipynb Normal file
View File

@ -0,0 +1,126 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"gpuType": "T4"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"source": [
"# **Galen AI Demo**"
],
"metadata": {
"id": "WX4uJNZWM9T9"
}
},
{
"cell_type": "code",
"source": [
"%%capture\n",
"# @title Install packages { display-mode: \"form\" }\n",
"# @markdown Please wait for the model to be loaded, it takes minutes to load, make sure you enabled GPU in your notebook\n",
"\n",
"!pip install -q -U bitsandbytes\n",
"!pip install -q -U git+https://github.com/huggingface/transformers.git\n",
"!pip install -q -U git+https://github.com/huggingface/accelerate.git\n",
"!pip install -q -U einops"
],
"metadata": {
"id": "o0zCCilRMuqc"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# @title Load the model {display-mode: \"form\"}\n",
"from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig,HfArgumentParser,TrainingArguments,pipeline, logging\n",
"import transformers\n",
"import torch\n",
"\n",
"model_name = 'ahmed-ai/galen'\n",
"\n",
"tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
"model_pipeline = pipeline(task=\"text-generation\", model=model_name, tokenizer=tokenizer)\n",
"\n",
"# bnb_config = BitsAndBytesConfig(\n",
"# load_in_4bit=True,\n",
"# bnb_4bit_quant_type=\"nf4\",\n",
"# bnb_4bit_use_double_quant=True,\n",
"# )\n",
"# model = AutoModelForCausalLM.from_pretrained(\n",
"# model_name,\n",
"# load_in_4bit=True,\n",
"# quantization_config=bnb_config,\n",
"# torch_dtype=torch.bfloat16,\n",
"# device_map=\"auto\",\n",
"# trust_remote_code=True,\n",
"# )"
],
"metadata": {
"id": "wfV5CarBc5h_"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# @title Hyperparameters {display-mode: \"form\"}\n",
"# @markdown The hypermeters of the input\n",
"\n",
"def user_prompt(prompt):\n",
" return f\"\"\"\n",
" Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n",
"\n",
" ### Instruction:\n",
" Generate an impressive qoute\n",
"\n",
"\n",
" ### Input:\n",
" {prompt}\n",
"\n",
" ### Response:\n",
" \"\"\"\n",
"\n",
"input = \"what is squamous cell carcinoma\" # @param {type: \"string\"}\n",
"max_length = 256 # @param {type:\"slider\", min:0, max:2048, step:2}\n",
"temperature = 0.5 # @param {type: \"slider\", min:0, max:1, step:0.1}\n",
"top_p = 0.5 # @param {type: \"slider\", min:0, max:1, step:0.1}"
],
"metadata": {
"id": "S0ugjLBZc-1J"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# @title Run the model {display-mode: \"form\"}\n",
"\n",
"prompt = user_prompt(input)\n",
"result = model_pipeline(prompt, max_length=max_lenght, temperature=temperature, top_p=top_p)\n",
"print(result[0]['generated_text'][len(prompt):])"
],
"metadata": {
"id": "Q9pNcQs6eyFQ"
},
"execution_count": null,
"outputs": []
}
]
}

34
README.md Normal file
View File

@ -0,0 +1,34 @@
---
inference: false
datasets:
- medalpaca/medical_meadow_medqa
language:
- en
library_name: transformers
tags:
- biology
- medical
- QA
- healthcare
---
# Galen
Galen is fine-tuned from [Mistral-7B-Instruct-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2), using [medical quesion answering dataset](https://huggingface.co/datasets/medalpaca/medical_meadow_medqa)
### Galen's view about future of medicine and AI:
![alt text](1.png "Galen's view about future of medicine and AI")
# Get Started
Install "accelerate" to use CUDA GPU
```bash
pip install accelerate
```
```py
from transformers import AutoTokenizer, pipeline
```
```py
tokenizer = AutoTokenizer.from_pretrained('ahmed/galen')
model_pipeline = pipeline(task="text-generation", model='ahmed/galen', tokenizer=tokenizer, max_length=256, temperature=0.5, top_p=0.6)
```
```py
result = model_pipeline('What is squamous carcinoma')
#print the generated text
print(result[0]['generated_text'][len(prompt):])
```