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.
test_comment morality_binary emotion_binary positive_binary (... rest of labels)
We’re exceptionally proud... 0 1 1
CodePudding user response:
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)
CodePudding user response:
you can have an empty dict beforehand and instead of print(f"{label}: {prediction}",)
you can do something like result['label'] = prediction
and later to form the dataframe you can do pd.DataFrame(result, columns=['label', 'prediction'])