#StackBounty: #python #tensorflow #bert BERT output should be text_A + text_B = some classification, but it's doing text_A = some c…

Bounty: 250

I am using a code adapted from Predicting Movie Reviews with BERT on TF Hub.ipynb. I am trying to run a comparision between two sentences to retrieve a result out of them.

Some previouscode from Predicting Movie Reviews with BERT on TF Hub.ipynb is needed to run the code I am placing. I used small_bert_bert_uncased_L-4_H-768_A-12_1 as the model.

def getPrediction(in_sentences):
    labels = ["Negative", "Positive"]
    input_examples = [run_classifier.InputExample(guid="", text_a = x[0], text_b = x[1], label = 0) for x in in_sentences] 
    input_features = run_classifier.convert_examples_to_features(input_examples, label_list, MAX_SEQ_LENGTH, tokenizer)
    predict_input_fn = run_classifier.input_fn_builder(features=input_features, seq_length=MAX_SEQ_LENGTH, is_training=False, drop_remainder=False)
    predictions = estimator.predict(predict_input_fn)
   
    return [(sentence, prediction['probabilities'], labels[prediction['labels']]) for sentence, prediction in zip(in_sentences, predictions)]

And texts A and B:

pred_sentences = [
  "Kinetic Monte Carlo simulations have been used to model the evolution of the morphology and the stress in a polycrystalline film. Stress is incorporated into the simulation by considering the processes that occur at the grain boundary as the film grows, in the same way that has been used for analytical models. A section of a grain is simulated by assuming the grain boundary can act as a sink and a source for atoms on the surface; the relative rates of diffusion into and out of the boundary depend on the surface kinetics and the stress. This approach allows the complex interaction between the film growth kinetics, surface morphology evolution, and stress to be investigated. For a decreasing growth rate, the growth mode changes from being dominated by nucleation of new clusters to step-flow. This affects the flux of atoms into the grain boundary and makes the corresponding stress more compressive. The effect of growth interrupts and a barrier to interlayer diffusion are also investigated.",
  "We present a model for compressive stress generation during thin film growth in which the driving force is an increase in the surface chemical potential caused by the deposition of atoms from the vapor. The increase in surface chemical potential induces atoms to flow into the grain boundary, creating a compressive stress in the film. We develop kinetic equations to describe the stress evolution and dependence on growth parameters. The model is used to explain measurements of relaxation when growth is terminated and the dependence of the steady-state stress on growth rate."
]

When I execute:

predictions = getPrediction(pred_sentences)

I realize the output is wrong, because it is not considering text_A and text_B being analized together = some classification.

As you can see the output is text_A = Negative and text_B = Positive:

[('Kinetic Monte Carlo simulations have been used to model the evolution of the morphology and the stress in a polycrystalline film. Stress is incorporated into the simulation by considering the processes that occur at the grain boundary as the film grows, in the same way that has been used for analytical models. A section of a grain is simulated by assuming the grain boundary can act as a sink and a source for atoms on the surface; the relative rates of diffusion into and out of the boundary depend on the surface kinetics and the stress. This approach allows the complex interaction between the film growth kinetics, surface morphology evolution, and stress to be investigated. For a decreasing growth rate, the growth mode changes from being dominated by nucleation of new clusters to step-flow. This affects the flux of atoms into the grain boundary and makes the corresponding stress more compressive. The effect of growth interrupts and a barrier to interlayer diffusion are also investigated.',
  array([-0.672097  , -0.71465003], dtype=float32),
  'Negative'),
 ('We present a model for compressive stress generation during thin film growth in which the driving force is an increase in the surface chemical potential caused by the deposition of atoms from the vapor. The increase in surface chemical potential induces atoms to flow into the grain boundary, creating a compressive stress in the film. We develop kinetic equations to describe the stress evolution and dependence on growth parameters. The model is used to explain measurements of relaxation when growth is terminated and the dependence of the steady-state stress on growth rate.',
  array([-0.74971545, -0.63960826], dtype=float32),
  'Positive')]

How can I fix this?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.