'use simpletransformers.language_representation to extract embedding from bert
i want to extract embedding from each post using bert and save it as . mat file I use anaconda jupterlab
from simpletransformers.language_representation import RepresentationModel
!pip3 install torch torchvision torchaudio
import torch
from torch import Tensor
model = RepresentationModel(
model_type="bert",
model_name="bert-base-uncased",
args=model_args,
use_cuda=False
)
c=1
for index, row in df4.iterrows():
post= row['new posts']
label=row['gt']
word_vector= model.encode_sentences(post, combine_strategy=None)
scipy.io.savemat(r"/Documents/embedding_bert/post"+ str(c) +".mat", {'myposts': word_vector,'label': label ,'post_no':c})
c=c+1
I got error in
word_vector= model.encode_sentences(post, combine_strategy=None)
the error is
Unable to convert output to PyTorch tensors format, PyTorch is not installed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
