I don’t know how BERT can be used as an embedding layer, but in your previous code snippet you were trying to assign the model output as the weight parameter to an embedding layer, which sounds strange at least.
An embedding layer can be seen as a lookup table, which accepts indices (i.e. sparse inputs) and maps it to feature tensors (i.e. dense outputs).
Your current code doesn’t seem to be using PyTorch so I don’t know if it could work or not.