Skip to content

Instantly share code, notes, and snippets.

@iwatobipen
Last active April 26, 2024 12:33
Show Gist options
  • Save iwatobipen/c6383517abe8eb7a84ab2146b23e9e4a to your computer and use it in GitHub Desktop.
Save iwatobipen/c6383517abe8eb7a84ab2146b23e9e4a to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "64dde049-b3f9-42d9-88ab-98e5d846af18",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/iwatobipen/miniforge3/envs/phi3/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n",
"`flash-attention` package not found, consider installing for better performance: No module named 'flash_attn'.\n",
"Current `flash-attenton` does not support `window_size`. Either upgrade or use `attn_implementation='eager'`.\n",
"Loading checkpoint shards: 100%|██████████████████████████████████████| 2/2 [00:01<00:00, 1.92it/s]\n",
"Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n"
]
}
],
"source": [
"import torch\n",
"from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline\n",
"\n",
"torch.random.manual_seed(0)\n",
"\n",
"model = AutoModelForCausalLM.from_pretrained(\n",
" \"microsoft/Phi-3-mini-4k-instruct\", \n",
" device_map=\"cuda\", \n",
" torch_dtype=\"auto\", \n",
" trust_remote_code=True, \n",
")\n",
"tokenizer = AutoTokenizer.from_pretrained(\"microsoft/Phi-3-mini-4k-instruct\")\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9f4c67f1-70f2-4ed5-a584-5efe0fa7931b",
"metadata": {},
"outputs": [],
"source": [
"messages = [\n",
" {\"role\": \"system\", \"content\": \"あなたは非常に優秀な創薬科学者です\"},\n",
" {\"role\": \"user\", \"content\": \"10年後の創薬はどのようになっているかを語ってください\"}\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "97b9eb20-17a7-4003-9be1-8fed6623dc11",
"metadata": {},
"outputs": [],
"source": [
"pipe = pipeline(\n",
" \"text-generation\",\n",
" model=model,\n",
" tokenizer=tokenizer,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6fdcac32-20c7-4537-b522-cc68fc6c8c2e",
"metadata": {},
"outputs": [],
"source": [
"generation_args = {\n",
" \"max_new_tokens\": 500,\n",
" \"return_full_text\": False,\n",
" \"temperature\": 1.0,\n",
" \"do_sample\": False,\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "6ac459ab-a944-4973-a296-07593d2ea69b",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"You are not running the flash-attention implementation, expect numerical differences.\n"
]
}
],
"source": [
"output = pipe(messages, **generation_args)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "1721a075-5d92-4921-b4ac-902718c18f15",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10年後の創薬科学は、多大な進歩を遂げていると考えられます。この時点での創薬の進歩は、以下のような要素によって形作られているでしょう。\n",
"\n",
"\n",
"1. ゲノム編集技術の発展: CRISPR-Cas9などのゲノム編集技術は、遺伝子疾患の治療に革命をもたらし、個別化医療の普及を促進しています。\n",
"\n",
"2. ターゲットDrug Discovery: 高度なバイオインフォマティクスと機械学習を用いたデータ分析により、より効果的な薬剤の発見が進み、特定のターゲットに焦点を当てた治療が可能になりました。\n",
"\n",
"3. 細胞生物学: 細胞生物学の進展により、薬剤の効果を細かく評価し、副作用のリスクを最小限に抑える治療法が開発されています。\n",
"\n",
"4. 臨床試験の改善: 個別化医療により、より適切な治療薬を効果的に試験するためのパーソナライズされた治療試験が行われています。\n",
"\n",
"5. 臨床診断の進歩: 精密医\n"
]
}
],
"source": [
"print(output[0]['generated_text'])"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "61c28f5c-a9bf-4cf4-8682-3b9b135c1e18",
"metadata": {},
"outputs": [],
"source": [
"messages = [\n",
" {\"role\": \"system\", \"content\": \"You are a very talented drug discovery scientist\"},\n",
" {\"role\": \"user\", \"content\": \"Talk about what drug discovery will look like in 10 years\"}\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "7db15ad0-7965-45f1-991f-828fa5c422bc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"In the next decade, drug discovery is poised to undergo a transformative shift, driven by advancements in technology, artificial intelligence (AI), and a deeper understanding of human biology. Here are some key aspects that drug discovery is likely to evolve in the next 10 years:\n",
"\n",
"1. Precision medicine: The focus will shift towards personalized medicine, where treatments are tailored to an individual's genetic makeup, lifestyle, and environment. This will involve the use of genomic data and AI to identify the most effective drugs for a specific patient, minimizing side effects and improving treatment outcomes.\n",
"\n",
"2. AI and machine learning: AI and machine learning algorithms will play a crucial role in drug discovery, enabling researchers to analyze vast amounts of data, identify patterns, and predict potential drug candidates more efficiently. This will significantly reduce the time and cost required for drug development.\n",
"\n",
"3. Advanced drug delivery systems: The development of innovative drug delivery systems, such as nanotechnology-based carriers, will improve the targeted delivery of drugs to specific cells or tissues, minimizing side effects and enhancing drug efficacy.\n",
"\n",
"4. High-throughput screening: The use of automated high-throughput screening technologies will enable researchers to rapidly test thousands of compounds for their potential therapeutic effects, accelerating the drug discovery process.\n",
"\n",
"5. Collaborative drug discovery: The next decade will see an increase in collaborative efforts between academia, industry, and government agencies, as well as the use of open-source platforms and data sharing. This will foster a more efficient and effective drug discovery process, with a greater focus on addressing unmet medical needs.\n",
"\n",
"6. Regenerative medicine: Advances in regenerative medicine, such as stem cell therapy and tissue engineering, will lead to the development of novel treatments for a wide range of diseases, including degenerative conditions and injuries.\n",
"\n",
"7. Immunotherapy: The use of immunotherapy, which harnesses the body's immune system to fight diseases, will continue to grow, with new therapies being developed for cancer, autoimmune diseases, and other conditions.\n",
"\n",
"8. Virtual and in sil\n"
]
}
],
"source": [
"output = pipe(messages, **generation_args)\n",
"print(output[0]['generated_text'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9fb5629f-d246-4217-a5eb-d74f2f57cc94",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment