How to convert bert model output to json?

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

Code:
from transformers import BertModel, BertConfig

def model_fn():

   config = BertConfig.from_pretrained("x*x*x*x", output_hidden_states=True)
   model = BertModel.from_pretrained("x*x*x*x", 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.
 
/forums/whats-new/news-feed

Unreplied Posts

Predict prices with tensorflow

Carol Vieira Asks: Predict prices with tensorflow
This is a sample of my dataset:

Code:
            dolar   selic       barril  diesel  ipca
data                    
2012-01-02  1.7376  0.039270    193.79  2.040   0.47
2012-01-03  1.7152  0.039270    210.87  2.042   0.26
2012-01-04  1.7152  0.039270    210.87  2.042   0.26
2012-01-05  1.7152  0.039270    210.87  2.042   0.26
2012-01-06  2.0350  0.031976    185.79  2.045   0.07

I need to predict the diesel variable for the next 30, 60 and 90 days. My dataset has values from 2012-01-02 to 2022-03-16.

Code:
        dolar       selic       barril       diesel     ipca
count   3727.000000 3727.000000 3727.000000 3727.000000 3727.000000
mean    3.500505    0.032195    224.446305  3.124171    0.447105
std     1.151149    0.013411    69.854573   0.775228    0.209740
min     1.702400    0.007469    112.040000  2.038000    -0.060000
25%     2.367550    0.024620    175.970000  2.501000    0.250000
50%     3.310300    0.030177    210.930000  3.024000    0.460000
75%     4.077150    0.041957    247.625000  3.530000    0.600000
max     5.937200    0.052531    454.660000  5.359000    0.920000

I know that I should use tensorflow but Which approach should I use and how can I implement it?

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.

What is a "hydrogen-like" or "hydrogenic" atom?

  • Melanie Shebel
  • Chemistry
  • Replies: 0
Melanie Shebel Asks: What is a "hydrogen-like" or "hydrogenic" atom?
I'm studying some chemistry on my own in anticipation of the new school year and in my book, I came across the Rydberg equation for the first time. I worked through some examples and everything was fine until I came across this comment on the question, "Calculate the wavelength of the radiation released when an electron moves from n=5 to n=2":

For future reference: the Rydberg formula only works for hydrogen-like atoms.

What is meant by "hydrogen-like"? I've heard that solving for multi-electron systems is (near) impossible, so I understand why hydrogen is used here, but I don't understand what "hydrogen-like" is.

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.

Identifying chiral centers

  • imaginov
  • Chemistry
  • Replies: 0
imaginov Asks: Identifying chiral centers
The compound below is fexofenadine and the only chirality center, as identified by the textbook is, the one circled in red.

I don't understand why the carbonyl carbon is not a chiral center too. Isn't it attached to a tert-butyl group? So isn't it attached to four different substituent groups? Or is it that the hydroxide group is attached to the carbon by the oxygen, thereby making a 'duplicate' substituent group of the carbon already double bonded to the oxygen?

enter image description here


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.

Tension in a rotating object

  • Splry00
  • Physics
  • Replies: 0
Splry00 Asks: Tension in a rotating object
I'm somewhat stuck on this very simple question, but I can't convince myself of a satisfactory answer. I tried to look through the previous questions asked to avoid asking a duplicate I hope.

Any rotating object... say a rod in this case, sitting stationary in free space, when pushed at one end will cause a rotation about the center of mass. This means the pushed end and other end will move in opposite directions of each other.

The only way that the rod can transmit force down its length is through the interaction of each particle pushing/pulling on the next (tension perpendicular to the length) as it travels down the rod. Once you reach the center of mass, there is no induced rotation. How do the particles past the center of mass receive a push or pull at all if there is a point in the center which has no movement?

Additionally, how does this original force in the positive direction turn into movement in the negative direction past the center of mass? Essentially both of these questions can be answered by an explanation of how the particles inside an object behave when a torque is applied... which I cant find an answer to.

Edit: So I found this other post which asks a very similar question: Why does a rigid body rotate and not simply translate when pushed with an instantaneous force?

I feel that the corded particles explanation answer there is of the form I am imagining for this, but it seems that it doesn't explain the other side rotating backwards.

The particles in the rod near the push start to move forward, which "pull" on the neighboring particles via tension. Then at some point, this tension turns into compression, effectively pushing the particles past the center of mass downward.

Does anyone have a satisfactory internal particle explanation involving tension/compression caused by an initial force at one end which results in the final behavior of rotation of a rod? My understanding of rotational motion feels incomplete to me if I can't explain intuitively why something rotates when pushed off-center besides "if one side goes up, the other must go down".

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.

Relativity... Twin paradox

  • Leo Hani
  • Physics
  • Replies: 0
Leo Hani Asks: Relativity... Twin paradox
Sorry, but I have another stupid question about relativity.

In the twin paradox: Let's say the travelling twin went to Proxima Centauri and back at 0,99c. However, he did not slow down to stop on Earth on the way back. It is rather the second twin who took his own ship and docked his brother's ship somewhere in space on the way back. Now, putting away all the technical problems with docking a ship at 0,99c and assuming that it all went right: What happens with the time in this case?

It is clear that if the first twin would just return to Earth he would meet his brother aged by ten years, while for him only one year passed. But what, when they both join the moving system? Then it's the universe that was moving with the speed of light? Then simultaneously, the travelling twin will meet his brother aged by 36 days and the second twin will meet his brother dead, because 100 years passed?

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.

Latest posts

Top