帮我用bert和pytorch等价实现embedding = nn.Embedding.from_pretrained(torch.FloatTensor(pre_trained_embedding), freeze=False)
时间: 2023-05-19 18:01:17 浏览: 224
PyPI 官网下载 | pytorch_pretrained_bert-0.3.0.tar.gz
5星 · 资源好评率100%
当然可以,以下是等价的代码:
```
import torch.nn as nn
embedding = nn.Embedding(pre_trained_embedding.shape[0], pre_trained_embedding.shape[1])
embedding.weight.data.copy_(torch.from_numpy(pre_trained_embedding))
embedding.weight.requires_grad = True
```
阅读全文