kandi background
Explore Kits

contextualizing-hate-speech-models-with-explanations | Official code release for ACL 2020 paper | Natural Language Processing library

 by   BrendanKennedy Python Version: Current License: MIT

 by   BrendanKennedy Python Version: Current License: MIT

Download this library from

kandi X-RAY | contextualizing-hate-speech-models-with-explanations Summary

contextualizing-hate-speech-models-with-explanations is a Python library typically used in Artificial Intelligence, Natural Language Processing applications. contextualizing-hate-speech-models-with-explanations has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. However contextualizing-hate-speech-models-with-explanations build file is not available. You can download it from GitHub.
Official code release for ACL 2020 paper Contextualizing Hate Speech Classifiers with Post hoc Explanation.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • contextualizing-hate-speech-models-with-explanations has a low active ecosystem.
  • It has 10 star(s) with 6 fork(s). There are 3 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 1 open issues and 1 have been closed. On average issues are closed in 1 days. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of contextualizing-hate-speech-models-with-explanations is current.
This Library - Support
Best in #Natural Language Processing
Average in #Natural Language Processing
This Library - Support
Best in #Natural Language Processing
Average in #Natural Language Processing

quality kandi Quality

  • contextualizing-hate-speech-models-with-explanations has 0 bugs and 0 code smells.
This Library - Quality
Best in #Natural Language Processing
Average in #Natural Language Processing
This Library - Quality
Best in #Natural Language Processing
Average in #Natural Language Processing

securitySecurity

  • contextualizing-hate-speech-models-with-explanations has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • contextualizing-hate-speech-models-with-explanations code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
This Library - Security
Best in #Natural Language Processing
Average in #Natural Language Processing
This Library - Security
Best in #Natural Language Processing
Average in #Natural Language Processing

license License

  • contextualizing-hate-speech-models-with-explanations is licensed under the MIT License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
This Library - License
Best in #Natural Language Processing
Average in #Natural Language Processing
This Library - License
Best in #Natural Language Processing
Average in #Natural Language Processing

buildReuse

  • contextualizing-hate-speech-models-with-explanations releases are not available. You will need to build from source code and install.
  • contextualizing-hate-speech-models-with-explanations has no build file. You will be need to create the build yourself to build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
  • It has 7180 lines of code, 474 functions and 36 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
This Library - Reuse
Best in #Natural Language Processing
Average in #Natural Language Processing
This Library - Reuse
Best in #Natural Language Processing
Average in #Natural Language Processing
Top functions reviewed by kandi - BETA

kandi has reviewed contextualizing-hate-speech-models-with-explanations and discovered the below as its top functions. This is intended to give you an instant insight into contextualizing-hate-speech-models-with-explanations implemented functionality, and help decide if they suit your requirements.

  • Run the main function .
  • Performs occlude of input .
  • Load a pretrained model from a pretrained model .
  • Validate the model .
  • Convert examples to features .
  • Perform aggregation on the input text .
  • Forward the decoder .
  • Performs training on a model .
  • Explain summation of a model .
  • Build a mapping from TF to pytorch model .

contextualizing-hate-speech-models-with-explanations Key Features

Official code release for ACL 2020 paper "Contextualizing Hate Speech Classifiers with Post hoc Explanation"

Requirements

copy iconCopydownload iconDownload
conda create -n expl-reg python==3.7.4
conda activate expl-reg
# modify CUDA version as yours
conda install pytorch=0.4.1 cuda90 -c pytorch
pip install nltk numpy scikit-learn scikit-image matplotlib torchtext
# requirements from pytorch-transformers
pip install tokenizers==0.0.11 boto3 filelock requests tqdm regex sentencepiece sacremoses

Running experiments

copy iconCopydownload iconDownload
chmod +x ./scripts/*
./scripts/gab_soc.sh

Gab Hate Corpus

copy iconCopydownload iconDownload
{"text_id":31287737,"Text":"How is that one post not illegal? He is calling for someone to commit a specific crime or he will do it himself. ","im":0,"cv":0,"ex":0,"hd":0,"mph":0,"gen":0,"rel":0,"sxo":0,"rae":0,"nat":0,"pol":0,"vo":0,"idl":0}

Stormfront corpus

copy iconCopydownload iconDownload
doc_id	text	is_hate
0	Somehow we 'll have our own Texas site , some day .	0

NYT corpus

copy iconCopydownload iconDownload
,nyt_text,hate,keyword
9,"The object of much of the criticism by moderates and liberals is the austere, almost harsh brand of Islam dominant in Saudi Arabia, which, because of its oil wealth and custodianship of Islam's holiest places, Mecca and Medina, has enormous influence in the Muslim world. This branch of Islam is often called Wahhabism.",0,muslim

Reference

copy iconCopydownload iconDownload
@inproceedings{kennedy2020contextualizing,
   author = {Kennedy*, Brendan and Jin*, Xisen and Mostafazadeh Davani, Aida and Dehghani, Morteza and Ren, Xiang},
   title = {Contextualizing {H}ate {S}peech {C}lassifiers with {P}ost-hoc {E}xplanation},
   year = {to appear},
   booktitle = {Proceedings of the 58th {A}nnual {M}eeting of the {A}ssociation for {C}omputational {L}inguistics}
} 

Community Discussions

Trending Discussions on Natural Language Processing
  • number of matches for keywords in specified categories
  • Apple's Natural Language API returns unexpected results
  • Tokenize text but keep compund hyphenated words together
  • Create new boolean fields based on specific bigrams appearing in a tokenized pandas dataframe
  • ModuleNotFoundError: No module named 'milvus'
  • Which model/technique to use for specific sentence extraction?
  • Assigning True/False if a token is present in a data-frame
  • How to calculate perplexity of a sentence using huggingface masked language models?
  • Mapping values from a dictionary's list to a string in Python
  • What are differences between AutoModelForSequenceClassification vs AutoModel
Trending Discussions on Natural Language Processing

QUESTION

number of matches for keywords in specified categories

Asked 2022-Apr-14 at 13:32

For a large scale text analysis problem, I have a data frame containing words that fall into different categories, and a data frame containing a column with strings and (empty) counting columns for each category. I now want to take each individual string, check which of the defined words appear, and count them within the appropriate category.

As a simplified example, given the two data frames below, i want to count how many of each animal type appear in the text cell.

df_texts <- tibble(
  text=c("the ape and the fox", "the tortoise and the hare", "the owl and the the 
  grasshopper"),
  mammals=NA,
  reptiles=NA,
  birds=NA,
  insects=NA
)

df_animals <- tibble(animals=c("ape", "fox", "tortoise", "hare", "owl", "grasshopper"),
           type=c("mammal", "mammal", "reptile", "mammal", "bird", "insect"))

So my desired result would be:

df_result <- tibble(
  text=c("the ape and the fox", "the tortoise and the hare", "the owl and the the 
  grasshopper"),
  mammals=c(2,1,0),
  reptiles=c(0,1,0),
  birds=c(0,0,1),
  insects=c(0,0,1)
)

Is there a straightforward way to achieve this keyword-matching-and-counting that would be applicable to a much larger dataset?

Thanks in advance!

ANSWER

Answered 2022-Apr-14 at 13:32

Here's a way do to it in the tidyverse. First look at whether strings in df_texts$text contain animals, then count them and sum by text and type.

library(tidyverse)

cbind(df_texts[, 1], sapply(df_animals$animals, grepl, df_texts$text)) %>% 
  pivot_longer(-text, names_to = "animals") %>% 
  left_join(df_animals) %>% 
  group_by(text, type) %>% 
  summarise(sum = sum(value)) %>% 
  pivot_wider(id_cols = text, names_from = type, values_from = sum)

  text                                   bird insect mammal reptile
  <chr>                                 <int>  <int>  <int>   <int>
1 "the ape and the fox"                     0      0      2       0
2 "the owl and the the \n  grasshopper"     1      0      0       0
3 "the tortoise and the hare"               0      0      1       1

To account for the several occurrences per text:

cbind(df_texts[, 1], t(sapply(df_texts$text, str_count, df_animals$animals, USE.NAMES = F))) %>% 
  setNames(c("text", df_animals$animals)) %>% 
  pivot_longer(-text, names_to = "animals") %>% 
  left_join(df_animals) %>% 
  group_by(text, type) %>% 
  summarise(sum = sum(value)) %>% 
  pivot_wider(id_cols = text, names_from = type, values_from = sum)

Source https://stackoverflow.com/questions/71871613

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install contextualizing-hate-speech-models-with-explanations

You can download it from GitHub.
You can use contextualizing-hate-speech-models-with-explanations like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Reuse Pre-built Kits with contextualizing-hate-speech-models-with-explanations
Consider Popular Natural Language Processing Libraries
Try Top Libraries by BrendanKennedy
Compare Natural Language Processing Libraries with Highest Support
Compare Natural Language Processing Libraries with Highest Quality
Compare Natural Language Processing Libraries with Highest Security
Compare Natural Language Processing Libraries with Permissive License
Compare Natural Language Processing Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.