Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/ru badwords #93

Merged
merged 5 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions annotators/BadlistedWordsDetector/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ RUN mkdir /src
COPY ./requirements.txt /src/requirements.txt
RUN pip install -r /src/requirements.txt
RUN spacy download en_core_web_sm
RUN spacy download ru_core_news_sm

ARG LANGUAGE
ENV LANGUAGE ${LANGUAGE}

COPY . /src/
WORKDIR /src
Expand Down
199 changes: 199 additions & 0 deletions annotators/BadlistedWordsDetector/badlists/bad_words_ru.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
БЛЯДЬ
БЛЯТЬ
ЕБАТЬ
ПИЗДА
ХЕР
ХУЙ
БЕСПИЗДАЯ
БЛЯ
БЛЯДВА
БЛЯДИАДА
БЛЯДИНА
БЛЯДИСТОСТЬ
БЛЯДКИ
БЛЯДОВАТЬ
БЛЯДОГОН
БЛЯДОСЛОВНИК
БЛЯДУН
БЛЯДЬ
БЛЯХОМУДИЯ
ВЗБЛЯД
ВЗЪЕБНУТЬ
ВЗЪЕБЩИК
ВПИЗДИТЬ
ВПИЗДИТЬСЯ
ВПИЗДРОНИВАТЬ
ВПИЗДРОНИВАТЬСЯ
ВПИЗДЮЛИТЬ
ВПИЗДЯЧИТЬ
ВПИЗЖИВАТЬ
ВПИЗЖИВАТЬСЯ
ВХУЯРИВАНИЕ
ВЫБЛЯДОК
ВЫЕБАТЬ
ВЫЕБОК
ВЫЕБОН
ВЫПИЗДЕТЬСЯ
ВЫПИЗДИТЬ
ВЪЕБАТЬ
ГЛУПИЗДИ
ГРЕБЛЯДЬ
ДЕРЬМОХЕРОПИЗДОКРАТИЯ
ДОЕБАТЬСЯ
ДОПИЗДЕТЬСЯ
ДОХУЙНУТЬ
ЕБАЛКА
ЕБАЛОВО
ЕБАЛЬНИК
ЕБАНАТИК
ЕБАНДЕЙ
ЕБАНУТЫЙ
ЕБАНЬКО
ЕБАРИШКА
ЕБАТОРИЙ
ЕБАТЬСЯ
ЕБАШИТ
ЕБИСТИКА
ЕБЛАН
ЕБЛАНИТЬ
ЕБЛИВАЯ
ЕБЛЯ
ЕБУКЕНТИЙ
ЗАЕБАТЬ
ЗАЕБИСЬ
ЗАЕБАТЬСЯ
ЗАПИЗДЕНЕВАТЬ
ЗАПИЗДЕТЬ
ЗАПИЗДИТЬ
ЗАПИЗЖИВАТЬСЯ
ЗАХУЯРИТЬ
ИСПИЗДИТЬ
ИСХУЯЧИТЬ
МНОГОПИЗДНАЯ
НАБЛЯДОВАЛ
НАЕБАЛОВО
НАЕБАТЬ
НАЕБАТЬСЯ
НАЕБАШИЛСЯ
НАЕБЕНИТЬСЯ
НАЕБНУТЬ
НАХУЕВЕРТЕТЬ
НАХУЙ
НАХЕР
НАХУЯРИВАТЬ
НАХУЯРИТЬСЯ
НАПИЗДЕТЬ
НАПИЗДИТЬ
НАСТОЕБАТЬ
НЕВЪЕБЕННЫЙ
НЕХУЙ
ОБЕРБЛЯДЬ
ОБЪЕБАЛОВО
ОБЪЕБАТЕЛЬСТВО
ОБЪЕБАТЬ
ОБЪЕБАТЬСЯ
ОБЪЕБОС
ОПИЗДЕНЕВАТЬ
ОПИЗДИХУИТЕЛЬНЫЙ
ОПИЗДОУМЕЛ
ОСТОПИЗДЕЛО
ОСТОПИЗДЕТЬ
ОСТОХУЕТЬ
ОТПИЗДИТЬ
ОТХУЯРИВАТЬ
ОТЪЕБАТЬСЯ
ОХУЕННЫЙ
ОХУИТЕЛЬНЫЙ
ОХУЯЧИВАТЬ
ОХУЯЧИТЬ
ПЕРЕЕБАТЬ
ПЕРЕХУЯРИВАТЬ
ПЕРЕХУЯРИТЬ
ПИЗДАБОЛ
ПИЗДАКРЫЛ
ПИЗДАНУТЬ
ПИЗДАНУТЬСЯ
ПИЗДЕЛИТЬСЯ
ПИЗДЕТЬ
ПИЗДЕЦ
ПИЗДИТЬ
ПИЗДОБЛОШКА
ПИЗДОБРАТ
ПИЗДОБРАТИЯ
ПИЗДОВЛАДЕЛЕЦ
ПИЗДОДУШИЕ
ПИЗДОЛЕТ
ПИЗДОЛИЗ
ПИЗДОМАНИЯ
ПИЗДОПЛЯСКА
ПИЗДОСТРАДАЛЕЦ
ПИЗДОСТРАДАНИЯ
ПИЗДОХУЙ
ПИЗДОШИТЬ
ПИЗДРИК
ПИЗДУЙ
ПИЗДУН
ПИЗДЮК
ПИЗДЮЛИ
ПИЗДЮЛИНА
ПИЗДЮЛЬКА
ПИЗДЮЛЯ
ПИЗДЮРИТЬ
ПИЗДЮХАТЬ
ПИЗДЮШНИК
ПОДЗАЕБАТЬ
ПОДЗАЕБЕНИТЬ
ПОДНАЕБНУТЬ
ПОДНАЕБНУТЬСЯ
ПОДЪЕБНУТЬ
ПОЕБАТЬ
ПОЕБЕНЬ
ПОПИЗДЕТЬ
ПОПИЗДИЛИ
ПОХЕР
ПОХУЙ
ПОХУЯРИЛИ
ПРИЕБАТЬСЯ
ПРИПИЗДЕТЬ
ПРИПИЗДИТЬ
ПРИХУЯРИТЬ
ПРОБЛЯДЬ
ПРОЕБАТЬ
ПРОЕБАТЬСЯ
ПРОПИЗДИТЬ
РАЗЪЕБАЙ
РАЗЪЕБАТЬСЯ
РАСПИЗДОН
РАСПИЗДЯЙСТВО
РАСХУЮЖИТЬ
СУХОПИЗДАЯ
СХУЯРИТЬ
СЪЕБАТЬСЯ
ТРЕПЕЗДОН
ТРЕПЕЗДОНИТ
ТУЕБЕНЬ
ТУПИЗДЕНЬ
УЕБАТЬ
УПИЗДИТЬ
ХУЕВ
ХУЕВАТЕНЬКИЙ
ХУЕВАТО
ХУЕБРАТИЯ
ХУЕГЛОТ
ХУЕГРЫЗ
ХУЕДИН
ХУЕЛЕС
ХУЕМАН
ХУЕМЫРЛО
ХУЕПУТАЛО
ХУЕСОС
ХУЕТА
ХУЕТЕНЬ
ХУЙЛО
ХУЙНУТЬ
ХУЯЦИЯ
ХУЛИ
ХУЯ
ХУЯК
ХУЯЧИТЬ
ШИРОКОПИЗДАЯ
2 changes: 1 addition & 1 deletion annotators/BadlistedWordsDetector/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ flask==1.1.1
gunicorn==19.9.0
requests==2.22.0
sentry-sdk==0.12.3
spacy==3.0.5
spacy==3.2.0
click==7.1.2
24 changes: 16 additions & 8 deletions annotators/BadlistedWordsDetector/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


sentry_sdk.init(getenv("SENTRY_DSN"))
LANGUAGE = getenv("LANGUAGE", "ENGLISH")

logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO)
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -82,12 +83,12 @@ def __init__(self, path):
Args:
path: Path object to badlist file, one badlisted phrase per line
"""
self.name = path.stem
self.name = path.stem.replace("_ru", "")
self.badlist = set()
with path.open() as f:
for _phrase in f:
phrase = _phrase.split(",")[0]
tokenized = en_nlp(phrase.strip().lower())
tokenized = nlp_pipeline(phrase.strip().lower())
self.badlist.add(" ".join([str(token) for token in tokenized]))
lemmatized_variants = lemmatize(tokenized)
for lemmatized in lemmatized_variants:
Expand Down Expand Up @@ -143,18 +144,25 @@ def collect_ngrams(utterance: Doc, max_ngram: int):
return all_ngrams


en_nlp = spacy.load("en_core_web_sm", exclude=["senter", "ner"])
if LANGUAGE == "RUSSIAN":
nlp_pipeline = spacy.load("ru_core_news_sm", exclude=["senter", "ner"])
badlists_dir = Path("./badlists")
badlists_files = [f for f in badlists_dir.iterdir() if f.is_file() and "_ru" in f.name]

badlists_dir = Path("./badlists")
badlists_files = [f for f in badlists_dir.iterdir() if f.is_file()]
badlists = [Badlist(file) for file in badlists_files]
logger.info(f"badlisted_words initialized with following badlists: {badlists}")
else:
nlp_pipeline = spacy.load("en_core_web_sm", exclude=["senter", "ner"])
badlists_dir = Path("./badlists")
badlists_files = [f for f in badlists_dir.iterdir() if f.is_file() and "_ru" not in f.name]

badlists = [Badlist(file) for file in badlists_files]
logger.info(f"badlisted_words initialized with following badlists: {badlists}")
badlists = [Badlist(file) for file in badlists_files]
logger.info(f"badlisted_words initialized with following badlists: {badlists}")


def check_for_badlisted_phrases(sentences):
result = []
docs = list(en_nlp.pipe([s.lower() for s in sentences]))
docs = list(nlp_pipeline.pipe([s.lower() for s in sentences]))
for doc in docs:
ngrams = collect_ngrams(doc, max([bl.max_ngram for bl in badlists]))
result += [{blist.name: blist.check_set_of_strings(ngrams) for blist in badlists}]
Expand Down
13 changes: 10 additions & 3 deletions annotators/BadlistedWordsDetector/test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import requests
from os import getenv


def main():
url = "http://0.0.0.0:8018/badlisted_words"

request_data = {
"sentences": ["any fucks in this sentence", "good one", "fucked one"],
}
LANGUAGE = getenv("LANGUAGE", "ENGLISH")
if LANGUAGE == "RUSSIAN":
request_data = {
"sentences": ["пизда настала", "застрахуйте уже его", "пошел нахер!"],
}
else:
request_data = {
"sentences": ["any fucks in this sentence", "good one", "fucked one"],
}

result = requests.post(url, json=request_data).json()
gold_result = [{"bad_words": True}, {"bad_words": False}, {"bad_words": True}]
Expand Down
2 changes: 2 additions & 0 deletions assistant_dists/dream_russian/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ services:
badlisted-words:
env_file: [.env]
build:
args:
LANGUAGE: RUSSIAN
context: annotators/BadlistedWordsDetector/
command: flask run -h 0.0.0.0 -p 8018
environment:
Expand Down