Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Construct a data frame with pandas

I wish to construct a data frame from the data I’m showcasing here. Can anyone help me in the right direction? Thanks a lot in advance!!

test_comment = "We’re exceptionally proud of the 62,000 employees who work in our restaurants, along with the hundreds of Russian suppliers who support our business, and our local franchisees. "

# tokenizing comment ^
encoding = tokenizer.encode_plus(
  test_comment,
  add_special_tokens=True,
  max_length=512,
  return_token_type_ids=False,
  padding="max_length",
  return_attention_mask=True,
  return_tensors='pt',
)

# returning probability values for each label
_, test_prediction = trained_model(encoding["input_ids"], encoding["attention_mask"])
test_prediction = test_prediction.flatten().numpy()

for label, prediction in zip(LABEL_COLUMNS, test_prediction):
  print(f"{label}: {prediction}",)

[0 if x <= 0.5 else 1 for x in test_prediction]

OUTCOME:

morality_binary: 0.433603435754776
emotion_binary: 0.5506623983383179
positive_binary: 0.6030590534210205
negative_binary: 0.022853979840874672
care_binary: 0.1553395688533783
fairness_binary: 0.2245887666940689
authority_binary: 0.11432072520256042
sanctity_binary: 0.0428963303565979
harm_binary: 0.032407380640506744
injustice_binary: 0.029283544048666954
betrayal_binary: 0.013294332660734653
subversion_binary: 0.02164781652390957
degradation_binary: 0.019699573516845703

PREFERED OUTCOME:
… if outcome is above 0.5, insert 1, else 0 in data frame.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

test_comment                   morality_binary     emotion_binary   positive_binary  (... rest of labels)
We’re exceptionally proud...   0                   1                1

>Solution :

Create DataFrame by constructor with cast comapred values by greater like 0.5 to 1 else 0 by casting to integers:

df = pd.DataFrame([(test_prediction > 0.5).astype(int)], columns=LABEL_COLUMNS)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading