O
ozil
Guest
ozil Asks: How to convert bert model output to json?
I have fine-tuned a Bert model and testing my output from different layers. I tested this in sagemaker , with my own custom script (see below) and the output i get is of BaseModelOutputWithPoolingAndCrossAttentions class. How can i convert the output of this , specially the tensor values from the last_hidden_state to json?
inference.py
model output
I have fine-tuned a Bert model and testing my output from different layers. I tested this in sagemaker , with my own custom script (see below) and the output i get is of BaseModelOutputWithPoolingAndCrossAttentions class. How can i convert the output of this , specially the tensor values from the last_hidden_state to json?
inference.py
Code:
from transformers import BertModel, BertConfig
def model_fn():
config = BertConfig.from_pretrained("xxx", output_hidden_states=True)
model = BertModel.from_pretrained("xxx", config=config)
....
def predict_fn():
....
return model(inputs)
model output
Code:
BaseModelOutputWithPoolingAndCrossAttentions(
last_hidden_state=
tensor([[[-1.6968, 1.9364, -2.1796, -0.0819, 1.8027, 0.3540, 1.3269, 0.1532],
[-0.4969, 0.4169, 0.5677, 1.0968, 0.0742, 1.5354, 0.9387, 0.0343]]])
device='cuda:0', grad_fn=<NativeLayerNormBackward>),
hidden_states=None,
attentions=None,
...
SolveForum.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your thoughts here to help others.