English
File size: 5,219 Bytes
cbff41a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import random
import pandas as pd

ques_patch = pd.read_csv('./utils/question_list.csv', header=None)  
ques_patch = ques_patch[0].tolist()

ques_wsi = pd.read_csv('./utils/question_wsi_list.csv', header=None)  
ques_wsi = ques_wsi[0].tolist()

def patch_formatting_itp(examples, tokenizer):
    question = random.choice(ques_patch)
    answer = examples["txt"]
    text = f"<|Question|>{question}" + f"<|Answer|>{answer}{tokenizer.eos_token}"
    # text = f"<DES> {answer}{tokenizer.eos_token}"
    examples["text"] = text
    return examples

def patch_formatting_vqap(examples, tokenizer):
    question = examples["question"]
    answer = examples["answer"]
    question = question.replace("<image>\n", "")
    question = question.replace("<image>", "")
    text = f"<|Question|>{question}" + f"<|Answer|>{answer}{tokenizer.eos_token}"
    examples["text"] = text
    return examples

# CNX-PathLLM/MultiConversation
# [{'from': 'human', 'value': 'What are the key features of this image that suggest chronic pancreatitis?'},
# {'from': 'gpt', 'value': 'The presence of duct dilatation, fibrosis, and pancreatic tissue necrosis are indicative of chronic pancreatitis.}]
def patch_formatting_vmc(examples, tokenizer): # image conversations
    conversation = examples["conversations"]
    conversation = ast.literal_eval(conversation)
    text = ""
    for sentence in conversation:
        sentence['value'] = sentence['value'].replace("<image>\n", "")
        sentence['value'] = sentence['value'].replace("<image>", "")
        if sentence['from'] == 'human':
            text += f"<|Question|>{sentence['value']}"
        elif sentence['from'] == 'gpt':
            text += f"<|Answer|>{sentence['value']}{tokenizer.eos_token}"
    examples["text"] = text
    return examples

def patch_formatting_ytb(examples, tokenizer):
    text = examples['conversations'].replace("<image>\n", "").replace("<image>", "")
    question = ast.literal_eval(text[1:-1].split('\n')[0])['value'].replace("\n", "")
    answer = ast.literal_eval(text[1:-1].split('\n')[1])['value'].replace("\n", "")
    text = f"<|Question|>{question}" + f"<|Answer|>{answer}{tokenizer.eos_token}"
    # text = f"<DES>{answer}{tokenizer.eos_token}"
    examples["text"] = text
    return examples

def wsi_formatting_des(examples, tokenizer):
    question = random.choice(ques_wsi)
    answer = examples["description"]
    text = f"<|Question|>{question}" + f"<|Answer|>{answer}{tokenizer.eos_token}"
    examples["text"] = text
    examples["text_input"] = question
    return examples

def wsi_formatting_qa_open(examples, tokenizer):
    question = examples["question"]
    answer = examples["answer"]
    text = f"<|Question|>{question}" + f"<|Answer|>{answer}{tokenizer.eos_token}"
    examples["text"] = text
    examples["text_input"] = question
    return examples

def wsi_formatting_qa_close(examples, tokenizer, prompt_tag=False):
    question = examples["question"]
    answer = examples["answer"]
    if answer.lower() in ['yes', 'no']:
        prompt = f" Please provide only the answer (either Yes or No) for the following statement. Do not include any explanations or additional text. Just give Yes or No."
    else:
        prompt = f" Please provide only the answer (for example, A. [Answer Text], B. [Answer Text], etc.) for the following question. Do not include any explanations or additional text. Just give the letter followed by the corresponding answer."
    
    if prompt_tag:
        text = f"<|Question|>{question}<|Prompt|>{prompt}" + f"<|Answer|>{answer}{tokenizer.eos_token}"
    else:
        text = f"<|Question|>{question}" + f"<|Answer|>{answer}{tokenizer.eos_token}"

    examples["text"] = text
    examples["text_input"] = question
    return examples

def wsi_formatting_des_test(examples, tokenizer):
    question = random.choice(ques_wsi)
    answer = examples["description"]
    text = f"<|Question|>{question}" + f"<|Answer|>"
    examples["text"] = text
    examples["answer"] = answer
    examples["question"] = question
    examples["text_input"] = question
    return examples

def wsi_formatting_qa_open_test(examples, tokenizer):
    question = examples["question"]
    answer = examples["answer"]
    text = f"<|Question|>{question}" + f"<|Answer|>"
    examples["text"] = text
    examples["text_input"] = question
    return examples

def wsi_formatting_qa_close_test(examples, tokenizer, prompt_tag=True):
    question = examples["question"]
    answer = examples["answer"]
    if answer.lower() in ['yes', 'no']:
        prompt = f" Please provide only the answer (either Yes or No) for the following statement. Do not include any explanations or additional text. Just give Yes or No."
    else:
        prompt = f" Please provide only the answer (for example, A. [Answer Text], B. [Answer Text], etc.) for the following question. Do not include any explanations or additional text. Just give the letter followed by the corresponding answer."
    
    if prompt_tag:
        text = f"<|Question|>{question}<|Prompt|>{prompt}" + f"<|Answer|>"
    else:
        text = f"<|Question|>{question}" + f"<|Answer|>"

    examples["text"] = text
    examples["text_input"] = question
    return examples