|
1 |
| -# This file was authored by GitHub user @couillonnade (PR #2) |
| 1 | +# This file was originally authored by GitHub user @couillonnade (PR #2) |
2 | 2 |
|
3 |
| -import sys |
4 |
| -from pathlib import Path |
5 |
| -sys.path.append(str(Path(__file__).parent)) |
| 3 | +import phi_3_vision_mlx as pv |
6 | 4 |
|
7 |
| -from phi_3_vision_mlx import Agent |
| 5 | +# Decoding Strategies |
| 6 | + |
| 7 | +## Multiple Choice Question Answering 1 |
| 8 | +prompts = [ |
| 9 | + "A 20-year-old woman presents with menorrhagia for the past several years. She says that her menses “have always been heavy”, and she has experienced easy bruising for as long as she can remember. Family history is significant for her mother, who had similar problems with bruising easily. The patient's vital signs include: heart rate 98/min, respiratory rate 14/min, temperature 36.1°C (96.9°F), and blood pressure 110/87 mm Hg. Physical examination is unremarkable. Laboratory tests show the following: platelet count 200,000/mm3, PT 12 seconds, and PTT 43 seconds. Which of the following is the most likely cause of this patient’s symptoms? A: Factor V Leiden B: Hemophilia A C: Lupus anticoagulant D: Protein C deficiency E: Von Willebrand disease", |
| 10 | + "A 25-year-old primigravida presents to her physician for a routine prenatal visit. She is at 34 weeks gestation, as confirmed by an ultrasound examination. She has no complaints, but notes that the new shoes she bought 2 weeks ago do not fit anymore. The course of her pregnancy has been uneventful and she has been compliant with the recommended prenatal care. Her medical history is unremarkable. She has a 15-pound weight gain since the last visit 3 weeks ago. Her vital signs are as follows: blood pressure, 148/90 mm Hg; heart rate, 88/min; respiratory rate, 16/min; and temperature, 36.6℃ (97.9℉). The blood pressure on repeat assessment 4 hours later is 151/90 mm Hg. The fetal heart rate is 151/min. The physical examination is significant for 2+ pitting edema of the lower extremity. Which of the following tests o should confirm the probable condition of this patient? A: Bilirubin assessment B: Coagulation studies C: Hematocrit assessment D: Leukocyte count with differential E: 24-hour urine protein"] |
| 11 | +pv.choose("What is the capital of France? A: London B: Berlin C: Paris D: Madrid E: Rome") |
| 12 | + |
| 13 | +## Multiple Choice Question Answering 2 |
| 14 | +pv.constrain(prompts, constraints=[(30, ' The correct answer is'), (10, 'X.')], blind_model=True, quantize_model=True) |
| 15 | + |
| 16 | +## Code Generation |
| 17 | +pv.constrain("Write a Python function to calculate the Fibonacci sequence up to a given number n.", [(100, "\n```python\n"), (100, " return "), (200, "\n```")]) |
| 18 | + |
| 19 | +# Train |
| 20 | +pv.train_lora( |
| 21 | + lora_layers=5, # Number of layers to apply LoRA |
| 22 | + lora_rank=16, # Rank of the LoRA adaptation |
| 23 | + epochs=10, # Number of training epochs |
| 24 | + lr=1e-4, # Learning rate |
| 25 | + warmup=0.5, # Fraction of steps for learning rate warmup |
| 26 | + dataset_path="JosefAlbers/akemiH_MedQA_Reason" |
| 27 | +) |
| 28 | + |
| 29 | +# Test |
| 30 | +pv.test_lora() |
8 | 31 |
|
9 | 32 | # Multi-turn VQA
|
10 |
| -agent = Agent() |
| 33 | +agent = pv.Agent() |
11 | 34 | agent('What is shown in this image?', 'https://collectionapi.metmuseum.org/api/collection/v1/iiif/344291/725918/main-image')
|
12 | 35 | agent('What is the location?')
|
13 | 36 | agent.end()
|
|
23 | 46 | agent('Speak "People say nothing is impossible, but I do nothing every day."')
|
24 | 47 | agent.end()
|
25 | 48 |
|
26 |
| -from phi_3_vision_mlx import constrain |
27 |
| - |
28 |
| -# Code Generation |
29 |
| -constrain ("Write a Python function to calculate the Fibonacci sequence up to a given number n.", [(100, "\n```python\n"), (100, " return "), (200, "\n```")]) |
30 |
| - |
31 |
| -# Multiple Choice Question Answering |
32 |
| -prompts = [ |
33 |
| - "A 20-year-old woman presents with menorrhagia for the past several years. She says that her menses “have always been heavy”, and she has experienced easy bruising for as long as she can remember. Family history is significant for her mother, who had similar problems with bruising easily. The patient's vital signs include: heart rate 98/min, respiratory rate 14/min, temperature 36.1°C (96.9°F), and blood pressure 110/87 mm Hg. Physical examination is unremarkable. Laboratory tests show the following: platelet count 200,000/mm3, PT 12 seconds, and PTT 43 seconds. Which of the following is the most likely cause of this patient’s symptoms? A: Factor V Leiden B: Hemophilia A C: Lupus anticoagulant D: Protein C deficiency E: Von Willebrand disease", |
34 |
| - "A 25-year-old primigravida presents to her physician for a routine prenatal visit. She is at 34 weeks gestation, as confirmed by an ultrasound examination. She has no complaints, but notes that the new shoes she bought 2 weeks ago do not fit anymore. The course of her pregnancy has been uneventful and she has been compliant with the recommended prenatal care. Her medical history is unremarkable. She has a 15-pound weight gain since the last visit 3 weeks ago. Her vital signs are as follows: blood pressure, 148/90 mm Hg; heart rate, 88/min; respiratory rate, 16/min; and temperature, 36.6℃ (97.9℉). The blood pressure on repeat assessment 4 hours later is 151/90 mm Hg. The fetal heart rate is 151/min. The physical examination is significant for 2+ pitting edema of the lower extremity. Which of the following tests o should confirm the probable condition of this patient? A: Bilirubin assessment B: Coagulation studies C: Hematocrit assessment D: Leukocyte count with differential E: 24-hour urine protein"] |
35 |
| -constrain(prompts, constraints=[(30, ' The correct answer is'), (10, 'X.')], blind_model=True, quantize_model=True) |
36 |
| - |
37 |
| -from phi_3_vision_mlx import train_lora, test_lora |
38 |
| - |
39 |
| -# Train |
40 |
| -train_lora(lora_layers=5, lora_rank=16, epochs=10, take=10, batch_size=2, lr=1e-4, warmup=.5, dataset_path="JosefAlbers/akemiH_MedQA_Reason") |
41 |
| - |
42 |
| -# Test |
43 |
| -test_lora() |
44 |
| - |
45 |
| -from phi_3_vision_mlx import benchmark |
| 49 | +# Misc |
| 50 | +pv.add_text('How to inspect API endpoints? @https://raw.githubusercontent.com/gradio-app/gradio/main/guides/08_gradio-clients-and-lite/01_getting-started-with-the-python-client.md') |
| 51 | +pv.rag('Comparison of Sortino Ratio for Bitcoin and Ethereum.') |
46 | 52 |
|
47 | 53 | # Benchmark
|
48 |
| -benchmark() |
| 54 | +pv.benchmark() |
0 commit comments