code: def match_embeds(
      old_wgts: dict,  # Embedding weights
      old_vocab: list,  # Vocabulary of corpus used for pre-training
      new_vocab: list,  # Current corpus vocabulary
  ) -> dict:
      "Convert the embedding in `old_wgts` to go from `old_vocab` to `new_vocab`."
      bias, wgts = (
          old_wgts.get("1.decoder.bias", None),
          old_wgts["0.encoder.weight"],
      )
      wgts_m = wgts.mean(0)
      new_wgts = wgts.new_zeros((len(new_vocab), wgts.size(1)))
      if bias is not None:
          bias_m = bias.mean(0)
          new_bias = bias.new_zeros((len(new_vocab),))
      old_o2i = (
          old_vocab.o2i
          if hasattr(old_vocab, "o2i")
          else {w: i for i, w in enumerate(old_vocab)}
      )
      for i, w in enumerate(new_vocab):
          idx = old_o2i.get(w, -1)
          new_wgts[i] = wgts[idx] if idx >= 0 else wgts_m
          if bias is not None:
              new_bias[i] = bias[idx] if idx >= 0 else bias_m
      old_wgts["0.encoder.weight"] = new_wgts
      if "0.encoder_dp.emb.weight" in old_wgts:
          old_wgts["0.encoder_dp.emb.weight"] = new_wgts.clone()
      old_wgts["1.decoder.weight"] = new_wgts.clone()
      if bias is not None:
          old_wgts["1.decoder.bias"] = new_bias
      return old_wgts
  
imports: from __future__ import annotations
  from ..basics import *
  from .core import *
  from .data import *
  from .models.core import *
  from .models.awdlstm import *
  from ..callback.rnn import *
  from ..callback.progress import *
  from .models.core import _model_meta
label_desc: Use image node_id 1 for calling a global function with example usage: match_embeds(old_wgts, old_vocab, new_vocab) and returns: old_wgts