# Utilizing Machine Learning for Detecting Harmful Situations by Audio and Text
## 4 Methodology Description
### Methods Used for Classification via Text Features  
We started with the database of Hebrew text sentences and applied different ML methods to the sentences. The text used as input for the different ML methods is given in the following formats:  
1. **TF-IDF** vectors: [62] generated by Sklearn Tfidf Vectorizer ([[https://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.TfidfVectorizer.html](https://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.TfidfVectorizer.html)]([https://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.TfidfVectorizer.html](https://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.TfidfVectorizer.html)), accessed on 15 March 2023). 2. **Heb-BERT** format, as explained below. 3. Fine-Tuned Heb-BERT: Heb-BERT vectors, fine-tuned on our dataset, as explained below. We further explain the Hebert and fine-tuned Heb-BERT formats used for text vectorization. **BERT** (bidirectional encoder representations from transformers) is a transformer-based ML technique developed for natural language processing (NLP) pretraining. A transformer is an attentional mechanism that learns relationships between words (or subwords) in a text. It has two separate mechanisms: an encoder that reads the text input and a decoder that produces a prediction of the task. To improve the classification accuracy, we used pre-trained embedding models for text inputs. Because our dataset was composed of Hebrew sentences, we used the pre-trained **Heb-BERT** model [5] to transform the sentences into embedded structures. Heb-BERT is based on the BERT architecture [4]. Similar to BERT, it is used for diverse NLP tasks, especially for sentiment analysis. As described in Section 5.1, using classical ML methods on embedded inputs improves the accuracy of the classification. Finally, we ran the BERT fine-tuning method on the Heb-BERT model for sentiment analysis, as described by [PERSON] ([[https://skimai.com/fine-tuning-bert-for-sentiment-analysis/](https://skimai.com/fine-tuning-bert-for-sentiment-analysis/)]([https://skimai.com/fine-tuning-bert-for-sentiment-analysis/](https://skimai.com/fine-tuning-bert-for-sentiment-analysis/)), accessed on 15 March 2023). These three text formats, namely, term frequency-inverse document frequency ( TF-IDF), Heb-BERT, and fine-tuned Heb-BERT transformers, were applied to the Hebrew dataset, and the resulting vectors were used as inputs to the ML methods. Our results, presented in Section 5, show that the fine-tuned Heb-BERT transformer achieved the highest accuracy in detecting insulting and unsafe situations. Thus, when combining text and audio information, we use BERT and fine-tuned BERT combined with the vectorized representation of the audio, as explained in Section 4.3. We considered the following classical ML methods for classification based on text content:  
1. **MLP**: A fully connected neural network with the following layers: the first hidden layer size is identical to the input size, followed by a hidden layer of size 100 and 50. The tanh activation function was used in all hidden layers. The final output layer consisted of a sigmoid neuron for binary classification, and three softmax neurons for the task of trinary classification (neutral, insulting, or unsafe sentences). The loss function was the weighted cross-entropy, and training was performed using the ADAM optimizer with a learning rate of 0.0001. 2. **SVM**: A set of supervised learning methods used for classification (see Section 4.2 for additional details). 3. **KNeighbors**: An unsupervised learning method based on a similarity measure between data-points (see Section 4.2 for additional details). 4. **Random Forest**: An ensemble learning method for classification (see Section 4.2 for additional details). 5. **ExtraTrees**: A method that combines the predictions of several decision trees. 6. **Logistic regression**: A model that is used when the value of the target variable is categorical in nature.