This is a reranker fine tuning script. I am getting "ValueError: zero-size array to reduction operation minimum which has no identity" error at the end of the first epoch possibly during the process of evaluation. Can you tell me what went wrong?
import logging
import torch
from datasets import load_dataset, Dataset, Features, Value
from sentence_transformers import CrossEncoder, CrossEncoderTrainer, CrossEncoderTrainingArguments
from sentence_transformers.cross_encoder.evaluation import CrossEncoderRerankingEvaluator
from sentence_transformers.cross_encoder.losses import CachedMultipleNegativesRankingLoss

# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Configuration
BASE_MODEL_NAME = "cl-nagoya/ruri-v3-pt-130m"
DATASET_NAME = "cl-nagoya/ruri-v3-dataset-reranker"
OUTPUT_MODEL_NAME = "cl-nagoya/ruri-v3-reranker-130m"
OUTPUT_DIR = "./ruri-v3-reranker-training"
MAX_SEQ_LEN = 1024
BATCH_SZ = 64
NEG_SIZE = 4

def generate_pairs(dataset):
    """
    Generator function to yield (query, document, score) pairs from the dataset.
    """
    for example in dataset:
        # Positive pair
        yield {
            "query": example['anc'],
            "positive": [example['pos']],
            "negative": example['neg'][:NEG_SIZE],
        }

def main():
    # 1. Load Dataset
    raw_dataset = load_dataset(DATASET_NAME)

    # 2. Create Datasets using generator for train and test splits
    # Split the original dataset first to maintain data distribution
    dataset_splits = raw_dataset['train'].train_test_split(test_size=39680, seed=42)

    # Create Dataset objects from generators
    train_dataset = Dataset.from_generator(
        lambda: generate_pairs(dataset_splits['train']),
        features=Features({
            "query": Value("string"),
            "positive": Value("string"),
            "negative": Value("string")
        })
    )

    eval_dataset = Dataset.from_generator(
        lambda: generate_pairs(dataset_splits['test']),
        features=Features({
            "query": Value("string"),
            "posiive": Value("string"),
            "negative": Value("string")
        })
    )

    logger.info(f"Original dataset size: {len(raw_dataset)}")
    logger.info(f"Transformed training pairs: {train_dataset.num_rows}")
    logger.info(f"Transformed evaluation pairs: {eval_dataset.num_rows}")

    # Load a model
    model = CrossEncoder(BASE_MODEL_NAME, model_kwargs={"torch_dtype": torch.bfloat16})

    # Initialize the evaluator
    reranking_evaluator = CrossEncoderRerankingEvaluator(
        samples=generate_pairs(dataset_splits['test']),
        name="ruri-v3",
        batch_size=BATCH_SZ,
        show_progress_bar=True,
    )
    results = reranking_evaluator(model)

    device = 'cuda' if torch.cuda.is_available() else 'cpu'
    logger.info(f"Training on device: {device}")

    training_args = CrossEncoderTrainingArguments(
        output_dir=OUTPUT_DIR,
        eval_strategy="epoch",
        save_strategy="epoch",
        learning_rate=2e-5,
        per_device_train_batch_size=BATCH_SZ,  # Adjust based on GPU memory
        per_device_eval_batch_size=BATCH_SZ,
        num_train_epochs=5,
        weight_decay=0.01,
        load_best_model_at_end=True,
        metric_for_best_model="eval_ruri-v3_ndcg@10",
        bf16=True,
        logging_dir='./logs',
        logging_steps=93,
        report_to="none",
        seed=42
    )

    reranking_loss = CachedMultipleNegativesRankingLoss(model=model, num_negatives=4, mini_batch_size=32)

    # 6. Initialize Trainer
    trainer = CrossEncoderTrainer(
        model=model,
        args=training_args,
        train_dataset=train_dataset,
        loss=reranking_loss,
        evaluator=reranking_evaluator,
    )

    # 7. Train
    logger.info("Starting fine-tuning...")
    trainer.train()
    evaluator(model)


    # 8. Save the Model
    logger.info(f"Saving fine-tuned model to {OUTPUT_MODEL_NAME}")
    model.save_pretrained(OUTPUT_MODEL_NAME)

    logger.info("Fine-tuning complete.")

if __name__ == "__main__":
    main()