Skip to content

gsig123/thesis_hate_speech_detection

Repository files navigation

Multilingual Hate Speech Detection

Master's Thesis // IT University of Copenhagen

Table of Contents

  1. Project Setup
  2. Preprocessing
  3. Features
  4. Classifiers
  5. References
  6. Contributors

Project Setup

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/activate

Installing Requirements:

$ pip install -r requirements.txt

Preprocessing

  • ./src/preprocess/
  • A directory containing classes needed for preprocessing the data for the different classifiers.

Base Class

  • data_prep_base.py
  • An abstract base class that implements methods to create Pandas DataFrame from tsv and csv files.
  • Also Implements some methods to get X and y, split the data into train and test sets, and more.
  • Classes inheriting from the base class must implement the init method.

Automated Hate Speech Detection and the Promblem of Offensive Language Data Prep

  • 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_names method takes in a dataset as a Pandas DataFrame and returns X, y, and feature_names, ready as inputs for the corresponding classifier.
  • The dataset this is designed for can be found in ./data/raw/HateSpeechAndOffensiveLanguage/labeled_data.csv.

OffensEval

  • 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 the OffensEval task.

Feature Extraction

  • ./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 a tf-idf representation.
  • 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.

Classifiers

  • ./src/classifiers/
  • A directory containing all the classifiers implemented.

Base Class

  • classifier_base.py
  • An abstract base class that implements methods to compute confusion_matrix, f1_score, recall, precision accuracy and a method to plot the confusion_matrix.
  • Also requires all classes that inherit from it to implement init, fit and predict methods.

Automated Hate Speech Detection and the Promblem of Offensive Language Classifier

  • 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.

Bi LSTM

  • classifier_bi_lstm.py
  • BI-LSTM + Multilayer Perceptron Classifier

FastText

Create Word Embeddings from vocabulary using FastText

sudo ./fastText/fasttext skipgram -dim 300 -input ./data/processed/OffensEval2019/start-kit/training-v1/fasttext-dataset.txt -output ./models/fast_text/OffensEval_EN_300d

Use a FastText model to get embeddings for a word

from pyfasttext import FastText

model_path = "./models/fast_text/OffensEval_EN_300d.bin"
model = FastText(model_path)
emb = model["@USER"]

Create Word Embeddings using pre-trained FastText Model

$ ./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

References

Links

Citations

@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}
}

Contributors

About

The repository for my master thesis at the IT University of Copenhagen, spring 2019.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors