# Utilizing Machine Learning for Detecting Harmful Situations by Audio and Text
## 5 Experimental Result
### Results on Text-Based Inputs  
First, we utilized classical ML methods for insulting and unsafe sentence detection using text sources. We ran each ML method over three different text sources: TF-IDF transformer applied to the sentences, Heb-BERT representation of the sentences, and Heb-BERT fine-tuned on our training set, where for each fold of the experiment, the Heb-BERT was trained on a different training sets (according to the fold), and then the result layer was used to create embedded vectors for all sentences. We used the weighted cross-entropy loss function in all ML methods, except for the KNN and voting methods. The voting method classified the examples using the majority rule of the classification of the following ML classifiers: random forests, extra trees, KNN, SVM, and ridge classifier. For the TF-IDF inputs, the NB classifier was also considered in the voting process. Our results are presented in Table 5 for insulting sentence detection, Table 6 for unsafe situation detection, and Table 7 for all three categories of classification. \begin{table}
\begin{tabular}{l l l l} \hline \hline
**Model** & **Tfidf** & **BERT** & **Fine-Tuned BERT** \\ \hline MLP & 0.72 & 0.75 & 0.82 \\ SVM & 0.72 & 0.72 & 0.83 \\ K Neighbors & 0.66 & 0.69 & 0.83 \\ Random Forest & 0.72 & 0.73 & 0.83 \\ Extra Trees & 0.72 & 0.74 & 0.83 \\ Logistic Regression & 0.72 & 0.69 & 0.83 \\ Naive Bayes & 0.69 & - & - \\ Voting & 0.71 & 0.74 & 0.83 \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Accuracy of unsafe sentences detection based on text only. \begin{table}
\begin{tabular}{l l l l} \hline \hline
**Model** & **Tfidf** & **BERT** & **Fine-Tuned BERT** \\ \hline MLP & 0.72 & 0.83 & 0.86 \\ SVM & 0.75 & 0.84 & 0.86 \\ K Neighbors & 0.69 & 0.83 & 0.86 \\ Random Forest & 0.71 & 0.84 & 0.86 \\ Extra Trees & 0.74 & 0.84 & 0.87 \\ Logistic Regression & 0.75 & 0.83 & 0.86 \\ Naive Bayes & 0.75 & - & - \\ Voting & 0.75 & 0.84 & 0.86 \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Accuracy of insulting sentences detection based on text only. Generally, using BERT inputs significantly improves the accuracy of insulting sentence detection for all ML classifiers, and running fine-tuning on BERT sentences results in an additional improvement. However, for unsafe sentence detection, the use of BERT sentences slightly improved the accuracy, while the use of fine-tuned BERT significantly improved the detection accuracy. For three-category classification, the use of BERT did not improve the accuracy, while the use of fine-tuned inputs significantly improved the accuracies of all ML methods. In addition, different ML methods achieved different accuracies for TF-IDF inputs. The best results were obtained for the SVM and voting classifiers for the binary problems and three-category classification problems, respectively. However, the variance of the accuracy of different classifiers reduced, and nearly disappeared, when moving from TF-IDF inputs to Heb-BERT and fine-tuned Heb-BERT inputs, probably because most of the learning on the FT-based input was executed during the fine-tuning on the BERT examples. Comparing other scores, a similar impact was observed when moving from TF-ITF inputs to BERT and fine-tuned BERT models. Table 8 shows the average F1 score for the SVM, MLP, and voting methods on the different text-based inputs (TF-IDF, BERT, and fine-tuned BERT), and for the different types of classification problems (insulting sentence, unsafe sentence, and three-category detections). We can conclude that application of ML to fine-tuned BERT vectors can dramatically improve the accuracy and other factors such as the F1 score and that the difference between the accuracy of the results obtained by different ML methods is reduced when using the fine-tuned BERT inputs. In addition, for the three-category classification, the use of Heb-BERT inputs reduces the average accuracy and average F1-score for most of the ML methods, but the use of fine-tuned BERT inputs increases the accuracy and F1 score for all the ML methods examined.