Update modeling_gpt2vision.py
Browse files- modeling_gpt2vision.py +21 -1
modeling_gpt2vision.py
CHANGED
|
@@ -77,4 +77,24 @@ class GPT2Vision(PreTrainedModel):
|
|
| 77 |
inputs_embeds=inputs_embeds, **generate_config
|
| 78 |
)
|
| 79 |
|
| 80 |
-
return tokenizer.batch_decode(output_ids, skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
inputs_embeds=inputs_embeds, **generate_config
|
| 78 |
)
|
| 79 |
|
| 80 |
+
return tokenizer.batch_decode(output_ids, skip_special_tokens=True)
|
| 81 |
+
|
| 82 |
+
def answer_question(
|
| 83 |
+
self,
|
| 84 |
+
image_embeds,
|
| 85 |
+
question,
|
| 86 |
+
tokenizer,
|
| 87 |
+
chat_history="",
|
| 88 |
+
result_queue=None,
|
| 89 |
+
**kwargs,
|
| 90 |
+
):
|
| 91 |
+
prompt = f"<image>\n\n{chat_history}Question: {question}\n\nAnswer: "
|
| 92 |
+
answer = self.generate(
|
| 93 |
+
image_embeds,
|
| 94 |
+
prompt,
|
| 95 |
+
tokenizer,
|
| 96 |
+
eos_text="<|endoftext|>",
|
| 97 |
+
max_new_tokens=256,
|
| 98 |
+
**kwargs,
|
| 99 |
+
)[0]
|
| 100 |
+
return answer
|