import logging
from pathlib import Path

import pytorch_lightning as pl

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__file__)


def get_project_dir():
    """Get the path to the project home."""
    path = Path(__file__).parent.parent
    project_dir = path.parent
    return project_dir


class HardNegativeCallback(pl.Callback):
    def __init__(self, max_num_hard_negatives=10, hard_negative_update_interval=10000):
        super().__init__()
        self.max_num_hard_negatives = max_num_hard_negatives
        self.hard_negative_update_interval = hard_negative_update_interval

        self.last_update = 0
        logger.info("Initialized HardNegativeCallback")

    def on_validation_end(self, trainer: pl.Trainer, pl_module):
        if trainer.global_step >= self.last_update + self.hard_negative_update_interval:
            if trainer.train_dataloader.dataset.num_hard_negatives < self.max_num_hard_negatives:
                trainer.train_dataloader.dataset.num_hard_negatives += 1
                logger.info(f"Update number of hard negatives to {trainer.train_dataloader.dataset.num_hard_negatives}")
                self.last_update = trainer.global_step

4e2cf7fa886c8bb71e495f2a94c4ada91a30bd3b
<mask token>


class HardNegativeCallback(pl.Callback):
    <mask token>
    <mask token>

<mask token>
logging.basicConfig(level=logging.INFO)
<mask token>


def get_project_dir():
    """Get the path to the project home."""
    path = Path(__file__).parent.parent
    project_dir = path.parent
    return project_dir


class HardNegativeCallback(pl.Callback):

    def __init__(self, max_num_hard_negatives=10,
        hard_negative_update_interval=10000):
        super().__init__()
        self.max_num_hard_negatives = max_num_hard_negatives
        self.hard_negative_update_interval = hard_negative_update_interval
        self.last_update = 0
        logger.info('Initialized HardNegativeCallback')

    def on_validation_end(self, trainer: pl.Trainer, pl_module):
        if (trainer.global_step >= self.last_update + self.
            hard_negative_update_interval):
            if (trainer.train_dataloader.dataset.num_hard_negatives < self.
                max_num_hard_negatives):
                trainer.train_dataloader.dataset.num_hard_negatives += 1
                logger.info(
                    f'Update number of hard negatives to {trainer.train_dataloader.dataset.num_hard_negatives}'
                    )
                self.last_update = trainer.global_step

<mask token>
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__file__)


def get_project_dir():
    """Get the path to the project home."""
    path = Path(__file__).parent.parent
    project_dir = path.parent
    return project_dir


class HardNegativeCallback(pl.Callback):

    def __init__(self, max_num_hard_negatives=10,
        hard_negative_update_interval=10000):
        super().__init__()
        self.max_num_hard_negatives = max_num_hard_negatives
        self.hard_negative_update_interval = hard_negative_update_interval
        self.last_update = 0
        logger.info('Initialized HardNegativeCallback')

    def on_validation_end(self, trainer: pl.Trainer, pl_module):
        if (trainer.global_step >= self.last_update + self.
            hard_negative_update_interval):
            if (trainer.train_dataloader.dataset.num_hard_negatives < self.
                max_num_hard_negatives):
                trainer.train_dataloader.dataset.num_hard_negatives += 1
                logger.info(
                    f'Update number of hard negatives to {trainer.train_dataloader.dataset.num_hard_negatives}'
                    )
                self.last_update = trainer.global_step

import logging
from pathlib import Path
import pytorch_lightning as pl
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__file__)


def get_project_dir():
    """Get the path to the project home."""
    path = Path(__file__).parent.parent
    project_dir = path.parent
    return project_dir


class HardNegativeCallback(pl.Callback):

    def __init__(self, max_num_hard_negatives=10,
        hard_negative_update_interval=10000):
        super().__init__()
        self.max_num_hard_negatives = max_num_hard_negatives
        self.hard_negative_update_interval = hard_negative_update_interval
        self.last_update = 0
        logger.info('Initialized HardNegativeCallback')

    def on_validation_end(self, trainer: pl.Trainer, pl_module):
        if (trainer.global_step >= self.last_update + self.
            hard_negative_update_interval):
            if (trainer.train_dataloader.dataset.num_hard_negatives < self.
                max_num_hard_negatives):
                trainer.train_dataloader.dataset.num_hard_negatives += 1
                logger.info(
                    f'Update number of hard negatives to {trainer.train_dataloader.dataset.num_hard_negatives}'
                    )
                self.last_update = trainer.global_step

import logging
from pathlib import Path

import pytorch_lightning as pl

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__file__)


def get_project_dir():
    """Get the path to the project home."""
    path = Path(__file__).parent.parent
    project_dir = path.parent
    return project_dir


class HardNegativeCallback(pl.Callback):
    def __init__(self, max_num_hard_negatives=10, hard_negative_update_interval=10000):
        super().__init__()
        self.max_num_hard_negatives = max_num_hard_negatives
        self.hard_negative_update_interval = hard_negative_update_interval

        self.last_update = 0
        logger.info("Initialized HardNegativeCallback")

    def on_validation_end(self, trainer: pl.Trainer, pl_module):
        if trainer.global_step >= self.last_update + self.hard_negative_update_interval:
            if trainer.train_dataloader.dataset.num_hard_negatives < self.max_num_hard_negatives:
                trainer.train_dataloader.dataset.num_hard_negatives += 1
                logger.info(f"Update number of hard negatives to {trainer.train_dataloader.dataset.num_hard_negatives}")
                self.last_update = trainer.global_step
