Commit ·
a55dbd1
1
Parent(s): 7cec2af
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,8 @@ with open(os.path.join("models", "toxic_comment_preprocessor_classnames.bin"), "
|
|
| 14 |
text_preprocessor, class_names = cloudpickle.load(model_file_obj)
|
| 15 |
interpreter = tf.lite.Interpreter(model_path=os.path.join("models", "toxic_comment_classifier_hf_distilbert.tflite"))
|
| 16 |
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def inference(text):
|
| 19 |
text = text_preprocessor.preprocess(pd.Series(text))[0]
|
|
@@ -29,7 +31,9 @@ def inference(text):
|
|
| 29 |
interpreter.set_tensor(input_details[0]["index"], attention_mask)
|
| 30 |
interpreter.set_tensor(input_details[1]["index"], input_ids)
|
| 31 |
interpreter.invoke()
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
result_df = pd.DataFrame({'class': class_names, 'prob': tflite_pred})
|
| 34 |
result_df.sort_values(by='prob', ascending=True, inplace=True)
|
| 35 |
return result_df
|
|
|
|
| 14 |
text_preprocessor, class_names = cloudpickle.load(model_file_obj)
|
| 15 |
interpreter = tf.lite.Interpreter(model_path=os.path.join("models", "toxic_comment_classifier_hf_distilbert.tflite"))
|
| 16 |
|
| 17 |
+
def sigmoid(x):
|
| 18 |
+
return 1 / (1 + np.exp(-x))
|
| 19 |
|
| 20 |
def inference(text):
|
| 21 |
text = text_preprocessor.preprocess(pd.Series(text))[0]
|
|
|
|
| 31 |
interpreter.set_tensor(input_details[0]["index"], attention_mask)
|
| 32 |
interpreter.set_tensor(input_details[1]["index"], input_ids)
|
| 33 |
interpreter.invoke()
|
| 34 |
+
tflite_logits = interpreter.get_tensor(output_details["index"])[0]
|
| 35 |
+
tflite_pred = sigmoid(tflite_logits)
|
| 36 |
+
|
| 37 |
result_df = pd.DataFrame({'class': class_names, 'prob': tflite_pred})
|
| 38 |
result_df.sort_values(by='prob', ascending=True, inplace=True)
|
| 39 |
return result_df
|