def METHOD_NAME(self, mode, records, logger, global_step, **kwargs):
    """Log training, validation information or test on a dataset."""
    if mode in ["train", "valid"]:
        prefix = f"quesst14_embedding/{mode}"
        for key, val in records.items():
            average = sum(val) / len(val)
            logger.add_scalar(f"{prefix}-{key}", average, global_step=global_step)
    elif mode in ["dev", "eval"]:
        query_embs = records["embs"][: self.test_dataset.n_queries]
        doc_embs = records["embs"][self.test_dataset.n_queries :]
        query_names = records["audio_names"][: self.test_dataset.n_queries]
        doc_names = records["audio_names"][self.test_dataset.n_queries :]
        results = {}
        # Calculate matching scores
        for query_emb, query_name in zip(
            tqdm(query_embs, desc="Query", ncols=0), query_names
        ):
            query_emb = query_emb[0:1].cuda()
            scores = []
            for doc_emb, doc_name in zip(
                tqdm(doc_embs, desc="Doc", ncols=0, leave=False), doc_names
            ):
                with torch.no_grad():
                    doc_emb = doc_emb.cuda()
                    similarities = F.cosine_similarity(query_emb, doc_emb)
                    score = similarities.max().detach().cpu()
                scores.append(score)
            scores = torch.stack(scores)
            if scores.std() < 0.1:
                scores = torch.zeros_like(scores)
            else:
                scores = (scores - scores.mean()) / (scores.std() + 1e-6) + 0.5
            results[query_name] = list(zip(doc_names, scores.tolist()))
        # Determine score threshold
        score_thresh = 0.5
        # Build XML tree
        root = etree.Element(
            "stdlist",
            termlist_filename="benchmark.stdlist.xml",
            indexing_time="1.00",
            language="english",
            index_size="1",
            system_id="benchmark",
        )
        for query_name, doc_scores in results.items():
            term_list = etree.SubElement(
                root,
                "detected_termlist",
                termid=query_name,
                term_search_time="1.0",
                oov_term_count="1",
            )
            for doc_name, score in doc_scores:
                etree.SubElement(
                    term_list,
                    "term",
                    file=doc_name,
                    channel="1",
                    tbeg="0.000",
                    dur="0.00",
                    score=f"{score:.4f}",
                    decision="YES" if score > score_thresh else "NO",
                )
        # Output XML
        etree.ElementTree(root).write(
            str(self.expdir / "benchmark.stdlist.xml"),
            encoding="UTF-8",
            pretty_print=True,
        )
    else:
        raise NotImplementedError