Skip to content

Commit cb68f8c

Browse files
committed
Add a simple result parameter to make predict_pair to only get predicted result with hash
1 parent 61f8260 commit cb68f8c

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

indra/statements/classifier.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,26 @@ def build_pair_input(self, subject, object):
197197

198198
return df
199199

200-
def predict_pair(self, subject, object):
200+
def predict_pair(self, subject, object, simple_result=False):
201201
df_input = self.build_pair_input(subject, object)
202202

203203
if df_input.empty:
204-
return df_input
204+
return {} if simple_result else df_input
205205

206206
X = df_input[self.feature_cols].copy()
207207

208208
df_input["pred_prob"] = self.model.predict_proba(X)[:, 1]
209209
df_input["pred_label"] = self.model.predict(X)
210210

211+
if simple_result:
212+
hash_to_label = {}
213+
for _, row in df_input.iterrows():
214+
label = int(row["pred_label"])
215+
hashes = row["hash"]
216+
for stmt_hash in hashes:
217+
hash_to_label[stmt_hash] = label
218+
return hash_to_label
219+
211220
first_cols = ["subject", "object", "type", "pred_prob", "pred_label"]
212221
other_cols = [col for col in df_input.columns if col not in first_cols]
213222
df_input = df_input[first_cols + other_cols]

0 commit comments

Comments
 (0)