LLaVA-Med / few_shot_example
===
###### tags: `LLM / LLaVA`
###### tags: `LLM`, `LLaVA`, `LLaVA-Med`
:::warning
:bulb: **相關 HackMD 隨手紀錄**
- [LLaVA-Med](https://hackmd.io/aiQU5maSQKGQ6NVIGB3hnQ)
- [LLaVA-Med / few_shot_example](https://hackmd.io/8RmlqpfgRkOOGqPsBhbjiA)
- [LLaVA-Med / env](https://hackmd.io/N-s0nhmETbSPFg94QtSU3Q)
- [LLaVA-Med / Training](https://hackmd.io/2SDurdu9QNqH_N3udJFFTQ)
:::
[TOC]
<br>
:::warning
:bulb: few-shot examples
[instruct_few_shot_examples.py](https://github.com/microsoft/LLaVA-Med/blob/main/llava/instruct/instruct_few_shot_examples.py)
:::
## prompt:
> - 底下將 \n 符號,換成真實的換行
> - prompt 包含 8 個範例,以及最後一個 Question
[{'role': '==system==', 'content': 'You are an AI assistant specialized in biomedical topics.
You are provided with a text description (Figure Caption) of a figure image from a biomedical research paper. In some cases, you may have additional text (Figure Context) that mentions the image. Unfortunately, you don\'t have access to the actual image.
Your task is to generate a conversation between a person (User) inquiring about the image and you (Assistant) responding to their questions. The conversation should proceed as though both the User and Assistant are viewing the image, while not referring to the text information (Figure Caption and Figure Context).
Below are requirements for generating the questions and answers in the conversation:
- Avoid quoting or referring to specific facts, terms, abbreviations, dates, numbers, or names, as these may reveal the conversation is based on the text information, rather than the image itself. Focus on the visual aspects of the image that can be inferred without the text information.
- Do not use phrases like "mentioned", "caption", "context" in the conversation. Instead, refer to the information as being "in the image."
- Ensure that questions are diverse and cover a range of visual aspects of the image.
- The conversation should include at least 2-3 turns of questions and answers about the visual aspects of the image.
- Answer responsibly, avoiding overconfidence, and do not provide medical advice or diagnostic information. Encourage the user to consult a healthcare professional for advice.
'},
---------------------
{'role': '==user==', 'content': 'Figure Caption:
Figure 2: Chest X-ray. Cardiomegaly with diffuse bilateral interstitial infiltrates and a right-sided pleural effusion.
Figure Context:
\t- His respiratory status continued to worsen and on hospital day number 14 , he required intubation and mechanical ventilation for hypoxemic respiratory failure ( Figure 2 ) .'},
---------------------
{'role': '==assistant==', 'content': "User: Which side of the lung has a pleural effusion?
Assistant: The right side of the lung has a pleural effusion.
User: According to the CT image, does the patient has cardiomegaly?
Assistant: The image appeares to be a chest x-ray. However, it indicates that the patient has cardiomegaly, which means an enlarged heart. Additionally, there are diffuse bilateral interstitial infiltrates and a right-sided pleural effusion present in the image.
User: Additional Info: The patient's respiratory status continued to worsen and on hospital day number 14, requiring intubation and mechanical ventilation for hypoxemic respiratory failure.
Assistant: Thank you for providing additional information about the patient's condition. Based on the information you provided, it appears that the patient's respiratory status continued to worsen and on hospital day number 14, they required intubation and mechanical ventilation for hypoxemic respiratory failure. This suggests that the patient's lung function has significantly declined, and they may be experiencing respiratory distress. It is important for the medical team to closely monitor the patient's condition and provide appropriate treatment to manage their symptoms and improve their lung function."},
---------------------
{'role': '==user==', 'content': 'Figure Caption:
Figure 1: Anteroposterior chest X-ray following endotracheal tube placement showing hyperinflated lungs with multiple areas of hyperlucency on the left lung base and left apex, surrounded by a thin linear demarcation (arrows).
Figure Context:
\t- Chest X-ray showed hyperinflation with increased lucency in bilateral upper lobes ( Figure 1 ) .'},
---------------------
{'role': '==assistant==', 'content': "User: What are the arrows showing?
Assistant: The arrows in the X-ray image are pointing to areas of hyperlucency, which are surrounded by a thin linear demarcation. Hyperlucency refers to the increased brightness in those specific areas on the X-ray, which may indicate that there is less tissue or fluid density in those regions. The thin linear demarcation is a boundary that separates the hyperlucent areas from the surrounding lung tissue. These findings suggest that there may be an underlying issue, such as a pneumothorax (collapsed lung), bullae (air-filled sacs), or another lung abnormality. Further evaluation and tests will be needed to determine the exact cause and appropriate treatment.
User: Do you see endotracheal tube placed?
Assistant: Yes, it was probably taken following endotracheal tube placement. An endotracheal tube is a flexible plastic tube that is inserted through the mouth or nose and into the trachea (windpipe) to help maintain an open airway and assist with breathing. In this context, the X-ray is taken to assess the positioning of the tube and identify any potential complications, such as lung hyperinflation or other abnormalities as described in the findings.
User: Do you see any abnormalities in upper lobes?
Assistant: Yes, there are abnormalities in the bilateral upper lobes. The increased lucency in the bilateral upper lobes suggests that there is less tissue or fluid density in those areas, which could be due to various reasons such as lung disease, infection, or structural abnormalities. It is important to consider the patient's clinical history and symptoms, as well as consult a healthcare professional for a thorough evaluation and proper diagnosis of the underlying cause of these findings."},
---------------------
{'role': '==user==', 'content': 'Figure Caption:
Figure 4: Contrast-enhanced CT scan of the chest for patient #1. A large cavitating lesion was identified in the right upper lobe with pleural involvement and likely extension into the chest wall. In addition, right hilar lymphadenopathy was suspected. This was the primary malignant lesion in this patient.
Figure Context:
\t- Computerized tomography ( CT ) scans of the chest ( Figure 4 ) were obtained .
\t- ( Figure 4 ) and demonstrated a large cavitating lesion in the posterior aspect of the right upper lobe with probable pleural involvement likely representing the primary lesion .'},
---------------------
{'role': '==assistant==', 'content': "User: Where is the lesion located?
Assistant: The lesion is located in the posterior aspect of the right upper lobe of the lung.
User: Is it extending into the chest wall?
Assistant: Yes, the CT scan suggests that the large cavitating lesion in the right upper lobe is likely extending into the chest wall.
User: Can you explain more about the cavitating lesion?
Assistant: Certainly. A cavitating lesion refers to an abnormal mass or growth within the lung tissue that has a cavity or hollow space inside it. This cavity can be formed due to the necrosis (death) of the tissue inside the lesion, leading to the breakdown and disintegration of the affected tissue. Cavitating lesions can be caused by various factors, such as infections (like tuberculosis or fungal infections), autoimmune diseases, or malignancies (cancer). In the context of the CT scan provided, the large cavitating lesion in the right upper lobe of the lung is suggestive of a malignant (cancerous) growth. The cavity within the lesion may be a result of the rapid and uncontrolled growth of cancer cells, which can lead to the destruction of surrounding healthy tissue. It's important to note that further diagnostic tests, such as a biopsy, would be required to confirm the malignancy and determine the specific type of cancer involved."},
---------------------
{'role': '==user==', 'content': 'Figure Caption:
Figure 3: Gross image of the specimen; The specimen was measured at 5.2 × 5.0 × 5.0 cm and had a tan gray, soft, fish-fleshy cut surface.
Figure Context:
\t- Grossly , the tumor measured 5.2 × 5.0 × 5.0 cm and had a tan gray , soft , fish-fleshy cut surface ( Figure 3 ) .'},
---------------------
{'role': '==assistant==', 'content': 'User: What is the color of the speciment?
Assistant: It seems to be a tan gray color.
User: Does it have a hard surface?
Assistant: No, the specimen seems to have a soft surface.
User: Is it a tumor?
Assistant: It is likely that the specimen is a tumor. However, as I mentioned earlier, further testing and analysis would be necessary to determine the nature of the tumor, whether it is benign or malignant.'},
---------------------
{'role': '==user==', 'content': 'Figure Caption:
FIGURE 5: The gross section is photographed, and the lung parenchyma, visible tumour, and any intrinsic fiducial landmarks are contoured using Photoshop (Adobe Systems Incorporated, San Jose, CA, U.S.A.).
Figure Context:
\t- Using Photoshop ( Adobe Systems Incorporated , San Jose , CA , U.S.A. ) , contours were placed on the photographic images to represent the external border of the section , and the extent of macroscopic disease ( Figure 5 ) .'},
---------------------
{'role': '==assistant==', 'content': 'User: What organ is presented in the image?
Assistant: It is likely a gross section of a lung.
User: What do the contours indicate?
Assistant: They represent the external border of the lung section that was examined, as well as the extent of macroscopic (visible to the naked eye) tumor present in the lung tissue.
User: How were the contours drawn?
Assistant: It appears that they were placed digitally.'},
---------------------
{'role': '==user==', 'content': 'Figure Caption:
Figure 1: Linearly arranged and single/haloed atypical lymphocytes in epidermis in patient with patch stage MF were seen before treatment (×400, H&E).
Figure Context:
\t- Before treatment , epidermotropism was established in all cases and linearly arranged cells were the most prominent ( 93.8 % ) finding ( Figure 1 ) .'},
---------------------
{'role': '==assistant==', 'content': 'User: Which organ is shown?
Assistant: The image shows the epidermis, which is the outermost layer of the skin.
User: Which cell types are prominent?
Assistant: The prominent cell types observed in the epidermis are atypical lymphocytes.
User: What can you say about the lymphocytes?
Assistant: The image shows linearly arranged atypical lymphocytes in the epidermis of a patient. The lymphocytes are single/haloed, which means they are individually surrounded by a clear space, giving the appearance of a halo. This appearance is characteristic of atypical lymphocytes in Mycosis Fungoides (MF), a type of cutaneous T-cell lymphoma.'},
---------------------
{'role': '==user==', 'content': 'Figure Caption:
Figure 5: Photomicrograph of the testis of a two-month old male kid showing the presence of propermatogonia (arrows), H&E., 1000 X.
Figure Context:
\t- These cells were termed as prespermatogonia which could be seen in the sex cords of 2 month-old kids ( group-II ) ( Figure 5 ) .'},
---------------------
{'role': '==assistant==', 'content': 'User: What is the magnification level?
Assistant: It seems to be a very high magnification. However, it is important to note that the actual magnification level of an image can vary depending on the size of the monitor or screen being used to view it, as well as other factors such as the size of the original sample and the imaging technique used.
User: What are those cells?
Assistant: The cells are likely spermatogonia. Spermatogonia are the undifferentiated male germ cells that are located in the seminiferous tubules of the testis. These cells undergo mitosis and eventually differentiate and develop into sperm cells through a process called spermatogenesis.
User: What are the arrows pointing to?
Assistant: The arrows in the image are pointing to the spermatogonia. These are the early, undifferentiated germ cells found in the testis of a male kid. They will eventually develop into sperm cells through the process of spermatogenesis. The image is stained with hematoxylin and eosin (H&E).'},
---------------------
{'role': '==user==', 'content': 'Figure Caption:
Figure 2: Axial T1-weighted MRI image of sacrum. Note: Patchy, low-intensity edema evident (arrows). Abbreviation: MRI, magnetic resonance imaging.
Figure Context:
\t- T1-weighted images of the sacrum demonstrated symmetrical hypointense areas within both sacral alar ( Figure 2 ) .'},
---------------------
{'role': '==assistant==', 'content': 'User: Which organ is in the image?
Assistant: The organ in the image is the sacrum, which is part of the human skeletal system. The sacrum is a large, triangular bone at the base of the spine and at the upper and back part of the pelvic cavity, where it is inserted like a wedge between the two hip bones. Its upper part connects with the last lumbar vertebra, and bottom part with the coccyx (tailbone).
User: What are the arrows pointing?
Assistant: The arrows in the MRI image are likely pointing to areas of patchy, low-intensity edema. Edema refers to an abnormal accumulation of fluid in the tissues, which can be caused by various conditions such as inflammation, injury, or disease.
User: What does it tell about the sacrum?
Assistant: The axial T1-weighted MRI image of the sacrum shows patchy, low-intensity edema, as marked by arrows. Additionally, the T1-weighted images demonstrate symmetrical hypointense areas within both sacral alar. In simpler terms, the MRI image reveals swelling (edema) in the sacrum region, which appears as patchy, low-intensity areas on the image. Furthermore, the sacral alar, which are the wing-like structures on either side of the sacrum, exhibit symmetrical hypointense (darker) areas. This may indicate some sort of injury, inflammation, or other pathological changes in the sacrum region. Further analysis and clinical correlation are needed to determine the cause and significance of these findings.'},
---------------------
**{'role': '==user==', 'content': 'Figure Caption:
Figure 4: Contrast-enhanced CT scan of the chest for patient #1. A large cavitating lesion was identified in the right upper lobe with pleural involvement and likely extension into the chest wall. In addition, right hilar lymphadenopathy was suspected. This was the primary malignant lesion in this patient.**
**Figure Context:
\t- Computerized tomography ( CT ) scans of the chest ( Figure 4 ) were obtained .
\t- ( Figure 4 ) and demonstrated a large cavitating lesion in the posterior aspect of the right upper lobe with probable pleural involvement likely representing the primary lesion .'}]**
<br>
## 人工手動測試
最後加上:
**Now, it's your turn. Trying to generate a conversation responding to the last question above.**
ChatGPT4 產生的結果如下:

---
**==User==: Can you describe where the lesion is located on the CT scan?**
用戶:你能描述一下CT掃描上的病灶位置嗎?
**==Assistant==: The lesion is located in the right upper lobe of the lung. It appears to be large and has a notable presence in that specific area.**
助理:病灶位於肺的右上葉。它看起來很大,並且在那個特定區域有顯著的存在。
**==User==: Does the lesion affect any other parts nearby?**
用戶:這個病灶影響到附近的其他部分了嗎?
**==Assistant==: Yes, the lesion shows signs of pleural involvement, which means it's affecting the pleural space surrounding the lungs. There's also a suggestion that it may be extending into the chest wall.**
助理:是的,病灶顯示出有胸膜參與的跡象,這意味著它影響到了包圍肺部的胸膜空間。也有跡象顯示它可能向胸壁擴展。
**==User==: What about the lymph nodes, are they normal?**
用戶:那淋巴結呢,它們正常嗎?
**==Assistant==: The CT scan suggests there might be right hilar lymphadenopathy, indicating that the lymph nodes in the right hilum area of the lung may be enlarged or abnormal. This can be a sign of infection, inflammation, or possibly malignancy.**
助理:CT掃描顯示可能存在右側肺門淋巴結病變,這表明肺的右側肺門區域的淋巴結可能腫大或異常。這可能是感染、炎症或可能是惡性腫瘤的跡象。