def update_init_roberta_model_state(state):
    """
   update the state_dict of a Roberta model for initializing
   weights of the BertRanker
   """
    for k in list(state.keys()):
        if ".lm_head." in k or "version" in k:
            del state[k]
            continue
        # remove 'encoder/decoder.sentence_encoder.' from the key
        assert k.startswith("encoder.sentence_encoder.") or k.startswith(
            "decoder.sentence_encoder."
        ), f"Cannot recognize parameter name {k}"
        if "layernorm_embedding" in k:
            new_k = k.replace(".layernorm_embedding.", ".emb_layer_norm.")
            state[new_k[25:]] = state[k]
        else:
            state[k[25:]] = state[k]
        del state[k]

   update the state_dict of a Roberta model for initializing
   weights of the BertRanker
   
understand_icl/fairseq/examples/discriminative_reranking_nmt/models/discriminative_reranking_model.py