{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/contextualizing-hate-speech-classifiers-with","title":"Contextualizing Hate Speech Classifiers with Post-hoc Explanation","arxiv_id":"2005.02439","date":"2020-05-05","proceeding":"ACL 2020 6","authors":["Brendan Kennedy","Xisen Jin","Aida Mostafazadeh Davani","Morteza Dehghani","Xiang Ren"],"abstract":"Hate speech classifiers trained on imbalanced datasets struggle to determine if group identifiers like \"gay\" or \"black\" are used in offensive or prejudiced ways. Such biases manifest in false positives when these identifiers are present, due to models' inability to learn the contexts which constitute a hateful usage of identifiers. We extract SOC post-hoc explanations from fine-tuned BERT classifiers to efficiently detect bias towards identity terms. Then, we propose a novel regularization technique based on these explanations that encourages models to learn from the context of group identifiers in addition to the identifiers themselves. Our approach improved over baselines in limiting false positives on out-of-domain data while maintaining or improving in-domain performance. Project page: https://inklab.usc.edu/contextualize-hate-speech/.","url_abs":"https://arxiv.org/abs/2005.02439v3","url_pdf":"https://arxiv.org/pdf/2005.02439v3.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"contextualizing-hate-speech-classifiers-with","repo_url":"https://github.com/BrendanKennedy/contextualizing-hate-speech-models-with-explanations","is_official":1,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"contextualizing-hate-speech-classifiers-with","repo_url":"https://github.com/Ago3/Adversifier","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"none","reach":{"status":"ok","spdx":"NOASSERTION"}},{"paper_slug":"contextualizing-hate-speech-classifiers-with","repo_url":"https://github.com/owaisCS/TestHateSpeech","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[],"methods":[{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"attention-dropout","method_name":"Attention Dropout"},{"method_slug":"bert","method_name":"BERT"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"linear-warmup-with-linear-decay","method_name":"Linear Warmup With Linear Decay"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"weight-decay","method_name":"Weight Decay"},{"method_slug":"wordpiece","method_name":"WordPiece"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2005.02439","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2005.02439"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/owaisCS/TestHateSpeech","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/Ago3/Adversifier","reach":{"status":"ok","spdx":"NOASSERTION"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/BrendanKennedy/contextualizing-hate-speech-models-with-explanations","reach":null}],"summary":{"ran_draft_wrong":4,"ran":2,"ran_honours":1,"unverified":11},"by_repo_kind":{"official":{"samples":3,"ran":2,"repositories":1},"listed":{"samples":15,"ran":5,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"0f786c407fb1ee4c","entry":"swish","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"bert/modeling.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/bert/modeling.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":2,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0f786c407fb1ee4c"}},{"code_sha256_prefix":"d1f57751ec604230","entry":"DotDict","repo":"BrendanKennedy/contextualizing-hate-speech-models-with-explanations","repo_kind":"official","path":"hiex/soc_algo.py","file_url":"https://github.com/BrendanKennedy/contextualizing-hate-speech-models-with-explanations/blob/HEAD/hiex/soc_algo.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d1f57751ec604230"}},{"code_sha256_prefix":"6557fd36dd52f015","entry":"_SamplingAndOcclusionBaseAlgo","repo":"BrendanKennedy/contextualizing-hate-speech-models-with-explanations","repo_kind":"official","path":"hiex/soc_algo.py","file_url":"https://github.com/BrendanKennedy/contextualizing-hate-speech-models-with-explanations/blob/HEAD/hiex/soc_algo.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6557fd36dd52f015"}},{"code_sha256_prefix":"35ef111fc00c21b4","entry":"build_tf_to_pytorch_map","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"bert/modeling_transfo_xl.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/bert/modeling_transfo_xl.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"35ef111fc00c21b4"}},{"code_sha256_prefix":"8d23fbe2b99b840b","entry":"gelu","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"bert/modeling_gpt2.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/bert/modeling_gpt2.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"8d23fbe2b99b840b"}},{"code_sha256_prefix":"fdc64f4c72036ae4","entry":"gelu","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"bert/modeling.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/bert/modeling.py","link_basis":"harvester_set","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"fdc64f4c72036ae4"}},{"code_sha256_prefix":"93228a3eb5c4d179","entry":"sample_logits","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"bert/modeling_transfo_xl_utilities.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/bert/modeling_transfo_xl_utilities.py","link_basis":"harvester_set","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"93228a3eb5c4d179"}},{"code_sha256_prefix":"8075d776e4211fb5","entry":"_SamplingAndOcclusionAlgo","repo":"BrendanKennedy/contextualizing-hate-speech-models-with-explanations","repo_kind":"official","path":"hiex/soc_algo.py","file_url":"https://github.com/BrendanKennedy/contextualizing-hate-speech-models-with-explanations/blob/HEAD/hiex/soc_algo.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"8075d776e4211fb5"}},{"code_sha256_prefix":"8005c9f347f0326a","entry":"acc_and_f1","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"run_model.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/run_model.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"8005c9f347f0326a"}},{"code_sha256_prefix":"a6e55b7bc228bc28","entry":"convert_examples_to_features_sst","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"hiex/soc_algo.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/hiex/soc_algo.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a6e55b7bc228bc28"}},{"code_sha256_prefix":"7151c8535ee0144d","entry":"examples_to_bow","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"run_baselines.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/run_baselines.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7151c8535ee0144d"}},{"code_sha256_prefix":"b1a7180868dd8d6a","entry":"load_tf_weights_in_bert","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"bert/modeling.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/bert/modeling.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"b1a7180868dd8d6a"}},{"code_sha256_prefix":"a62604f618a8cc82","entry":"load_tf_weights_in_gpt2","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"bert/modeling_gpt2.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/bert/modeling_gpt2.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a62604f618a8cc82"}},{"code_sha256_prefix":"46f305675277e757","entry":"load_tf_weights_in_openai_gpt","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"bert/modeling_openai.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/bert/modeling_openai.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"46f305675277e757"}},{"code_sha256_prefix":"1ebc2bf2c3cddc4d","entry":"load_tf_weights_in_transfo_xl","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"bert/modeling_transfo_xl.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/bert/modeling_transfo_xl.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1ebc2bf2c3cddc4d"}},{"code_sha256_prefix":"0e2ab003fa4ca542","entry":"pearson_and_spearman","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"run_model.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/run_model.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0e2ab003fa4ca542"}},{"code_sha256_prefix":"d7e129db40fdbd06","entry":"plot_score_array","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"visualize.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/visualize.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d7e129db40fdbd06"}},{"code_sha256_prefix":"3c241ecfe3749a6d","entry":"simple_accuracy","repo":"owaisCS/TestHateSpeech","repo_kind":"listed","path":"run_model.py","file_url":"https://github.com/owaisCS/TestHateSpeech/blob/HEAD/run_model.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"3c241ecfe3749a6d"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}