Project Dependencies:
- Python 3 🐍
Setting up a Python 3 environment with venv:
# Create the environment
$ python3 -m venv ~/PythonEnv/thesis
# Activate it
$ . ~/PythonEnv/thesis/bin/activateInstalling Requirements:
$ pip install -r requirements.txt./src/preprocess/- A directory containing classes needed for preprocessing the data for the different classifiers.
data_prep_base.py- An abstract base class that implements methods to create
PandasDataFramefromtsvandcsvfiles. - Also Implements some methods to get
Xandy, split the data intotrainandtestsets, and more. - Classes inheriting from the base class must implement the
initmethod.
data_prep_hsaofl.py- Implements methods to get the dataset ready for the model introduced here - This includes extracting features etc.
- the
get_X_y_feature_namesmethod takes in a dataset as aPandasDataFrameand returnsX,y, andfeature_names, ready as inputs for the corresponding classifier. - The dataset this is designed for can be found in
./data/raw/HateSpeechAndOffensiveLanguage/labeled_data.csv.
data_prep_offenseval.py- Implements functionality to read in a file and turn it into
X,y_a,y_b,y_c, corresponding to the different subtasks as they are defined in theOffensEvaltask.
./src/feature_extraction/- A directory containing modules for extracting different features from the dataset.
tokenize.py: Tokenize a sentence. Excludes stopwords and punctuation.bag_of_words.py: Create BOW representation from list of sentences.tfidf_from_bow.py: Transform a BOW representation to atf-idfrepresentation.sentiment_score_english.py: Get a sentiment score for a sentence. -1 is negative, 0 is neutral, +1 is positive.w2v_embeddings.py: Create a W2V Model based on the input corpus. Returns embeddings for the input corpus.w2i.py: Takes in a list of sentences and returns a list of lists of integers, where each integer represent a word. The default behaviour is to pad the sequence so all sequences have the same length once outputted.
./src/classifiers/- A directory containing all the classifiers implemented.
classifier_base.py- An abstract base class that implements methods to compute
confusion_matrix,f1_score,recall,precisionaccuracyand a method to plot theconfusion_matrix. - Also requires all classes that inherit from it to implement
init,fitandpredictmethods.
classifier_hsaofl.py- Implements the model introduced here
- A script showing how it can be used can be found in
./src/scripts/test_hsaofl_classifier.py.
classifier_bi_lstm.py- BI-LSTM + Multilayer Perceptron Classifier
sudo ./fastText/fasttext skipgram -dim 300 -input ./data/processed/OffensEval2019/start-kit/training-v1/fasttext-dataset.txt -output ./models/fast_text/OffensEval_EN_300dfrom pyfasttext import FastText
model_path = "./models/fast_text/OffensEval_EN_300d.bin"
model = FastText(model_path)
emb = model["@USER"]$ ./fastText/fasttext print-word-vectors fast_text_pre_trained/cc.en.300.bin < ./data/processed/OffensEval2019/start-kit/training-v1/fasttext-dataset-no-labels.txt > ./fast_text_pre_trained/EN_OffensEval_300d.vec- Automated Hate Speech Detection and the Problem of Offensive Language
- OffensEval 2019
- Deep Learning for Hate Speech Detection
- FastText Pretrained Embeddings
@inproceedings{hateoffensive,
title = {Automated Hate Speech Detection and the Problem of Offensive Language},
author = {Davidson, Thomas and Warmsley, Dana and Macy, Michael and Weber, Ingmar},
booktitle = {Proceedings of the 11th International AAAI Conference on Web and Social Media},
series = {ICWSM '17},
year = {2017},
location = {Montreal, Canada},
pages = {512-515}
}
@inproceedings{grave2018learning,
title={Learning Word Vectors for 157 Languages},
author={Grave, Edouard and Bojanowski, Piotr and Gupta, Prakhar and Joulin, Armand and Mikolov, Tomas},
booktitle={Proceedings of the International Conference on Language Resources and Evaluation (LREC 2018)},
year={2018}
}