OpenCompass/opencompass/multimodal/models/visualglm/post_processor.py
Yike Yuan 3f601f420b
[Feat] Support public dataset of visualglm and llava. (#265)
* [Feat] Add public dataset support of VisualGLM.

* [Feat] Refactor LLaVA.

* [Feat] Add public dataset support of LlaVA.

* [Fix] Add  arg.
2023-08-25 15:44:32 +08:00

32 lines
847 B
Python

from typing import Any
import torch
class VisualGLMBasePostProcessor:
"""Base post processor for VisualGLM."""
def __init__(self) -> None:
pass
def __call__(self, output_token: torch.tensor, tokenizer: Any,
input_len: int) -> str:
return tokenizer.decode(output_token[input_len:])
class VisualGLMVSRPostProcessor(VisualGLMBasePostProcessor):
"""VSR post processor for VisualGLM."""
def __init__(self) -> None:
super().__init__()
def __call__(self, output_token: torch.tensor, tokenizer: Any,
input_len: int) -> str:
output_text = tokenizer.decode(output_token[input_len:])
if 'yes' in output_text.lower():
return 'yes'
elif 'no' in output_text.lower():
return 'no'
else:
return 'unknown'