Skip to content
Snippets Groups Projects
dummy_model.py 2.37 KiB
Newer Older
spmohanty's avatar
spmohanty committed
from typing import List, Union
spmohanty's avatar
spmohanty committed
import random
import os

spmohanty's avatar
spmohanty committed
from .base_model import ShopBenchBaseModel

# Set a consistent seed for reproducibility
spmohanty's avatar
spmohanty committed
AICROWD_RUN_SEED = int(os.getenv("AICROWD_RUN_SEED", 3142))
spmohanty's avatar
spmohanty committed
class DummyModel(ShopBenchBaseModel):
Dipam Chakraborty's avatar
Dipam Chakraborty committed
    """
spmohanty's avatar
spmohanty committed
    A dummy model implementation for ShopBench, illustrating how to handle both
    multiple choice and other types of tasks like Ranking, Retrieval, and Named Entity Recognition.
    This model uses a consistent random seed for reproducible results.
Dipam Chakraborty's avatar
Dipam Chakraborty committed
    """
spmohanty's avatar
spmohanty committed

Dipam Chakraborty's avatar
Dipam Chakraborty committed
    def __init__(self):
spmohanty's avatar
spmohanty committed
        """Initializes the model and sets the random seed for consistency."""
spmohanty's avatar
spmohanty committed
        random.seed(AICROWD_RUN_SEED)
spmohanty's avatar
spmohanty committed
    def predict(self, prompt: str, is_multiple_choice: bool) -> str:
Dipam Chakraborty's avatar
Dipam Chakraborty committed
        """
spmohanty's avatar
spmohanty committed
        Generates a prediction based on the input prompt and task type.
spmohanty's avatar
spmohanty committed
        For multiple choice tasks, it randomly selects a choice.
        For other tasks, it returns a list of integers as a string,
        representing the model's prediction in a format compatible with task-specific parsers.
spmohanty's avatar
spmohanty committed
        Args:
            prompt (str): The input prompt for the model.
            is_multiple_choice (bool): Indicates whether the task is a multiple choice question.
spmohanty's avatar
spmohanty committed
        Returns:
            str: The prediction as a string representing a single integer[0, 3] for multiple choice tasks,
                        or a string representing a comma separated list of integers for Ranking, Retrieval tasks,
                        or a string representing a comma separated list of named entities for Named Entity Recognition tasks.
                        or a string representing the (unconstrained) generated response for the generation tasks
spmohanty's avatar
spmohanty committed
                        Please refer to parsers.py for more details on how these responses will be parsed by the evaluator.
Dipam Chakraborty's avatar
Dipam Chakraborty committed
        """
spmohanty's avatar
spmohanty committed
        possible_responses = [1, 2, 3, 4]
spmohanty's avatar
spmohanty committed

        if is_multiple_choice:
spmohanty's avatar
spmohanty committed
            # Randomly select one of the possible responses for multiple choice tasks
            return str(random.choice(possible_responses))
spmohanty's avatar
spmohanty committed
        else:
spmohanty's avatar
spmohanty committed
            # For other tasks, shuffle the possible responses and return as a string
            random.shuffle(possible_responses)
            return str(possible_responses)
            # Note: As this is dummy model, we are returning random responses for non-multiple choice tasks.
            # For generation tasks, this should ideally return an unconstrained string.