Skip to main content

Robustness Evaluation of Pre-trained Language Models in the Russian Language

This is a repo with experiments for Robustness Evaluation of Pre-trained Language Models in the Russian Language and a tool ru_attacker for attacking Russian NLP models

Installation

pip install ru_attacker

Usage example

Set model

>>> from ru_attacker.models import RobertaModel
>>> roberta_checkpoints = "Roberta_checkpoints"
>>> ruRoberta = RobertaModel(roberta_checkpoints)

Set dataset

>>> from ru_attacker.models.set_dataset import get_data
>>> data_dir = "TERRa/val.jsonl" 
>>> data = get_data(data_dir)

Set attack

You have to define transformation, goal_function and type_perturbation. constraints and search_method are optional

>>> from ru_attacker.attacks.transformations import BackTranslation  # transformation
>>> from ru_attacker.attacks.goal_function import LabelPreserving  # goal function
>>> from ru_attacker.attacks.constraints import GrammarAcceptability, SemanticSimilarity  # constraints
>>> from ru_attacker.attacks.search_method import GreedySearch  # search method
>>> from ru_attacker.attacks import Attack  # attack wrapper
>>> backtranslation = Attack(
        transformation=BackTranslation(languages=["en", "fr", "de"]),  # you can set languages manually or use the default ones
        goal_function=LabelPreserving(),
        type_perturbation="hypothesis",  # to what part perturbation is applied {"hypothesis", "premise"}
        constraints=[GrammarAcceptability(), SemanticSimilarity()],
        search_method=GreedySearch()
    )

Attack model and view results

>>> results = backtranslation.attack(ruRoberta, data)
                  [Succeeded / Failed / Skipped / Total] 0 / 1 / 0 / 1:
                  entailment --> entailment
                  original premise: """Решение носит символический характер, так как взыскать компенсацию практически невозможно"", - отмечается в сообщении."
                  original hypothesis: Взыскать компенсацию не получится.

                  transformed: Компенсации не будет.

                  

                  [Succeeded / Failed / Skipped / Total] 1 / 1 / 0 / 2:
                  entailment --> not_entailment
                  original premise: Об этом вечером во вторник, 17 января, сообщила пресс-служба Спасательного департамента, отметив, что немецкую противотанковую мину Tellermine 42 обнаружили в на улице Кеэвисе в ходе земляных работ. Спасатели эвакуировали жителей окрестных домов, офисов и складских помещений. Уничтожать мину на месте не стали, поскольку это угрожало повреждению трассы трубопровода.
                  original hypothesis: На улице Кеэвисе жителей эвакуировали из-за мины.

                  transformed: На улице Касери эвакуировали жителей из мин.

Convert results to DataFrame

>>> import pandas as pd
>>> dataframe = pd.DataFrame(results)

Here is Tutorial

Experiments

All the data used in experiments and the results are in data folder (TERRa and results correspondingly).

All experiments can be reproduced in Experiments.ipynb.

Models checkpoints are available via:

Release files for ru-attacker 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ru-attacker 0.0.5
File Size Uploaded
ru_attacker-0.0.5.tar.gz 14.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ru-attacker 0.0.5
File Interpreter ABI Platform
ru_attacker-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 42.6 kB

Release files / ru_attacker-0.0.5.tar.gz

Download URL ru_attacker-0.0.5.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5011870c41d84b940ea3320478ef0f43f40b9986e20edb4fc20969c03c8ff884
BLAKE2b-256 checksum
How to use checksums
7d20c0e5926929ed91f4903efca141f0b23e8af5d6c1713301b99df4153ff4f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.5

Release files / ru_attacker-0.0.5-py3-none-any.whl

Download URL ru_attacker-0.0.5-py3-none-any.whl
Size 27.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5138801118b7d093894740aed6cd95db7592086822274129e7150f382a165fcb
BLAKE2b-256 checksum
How to use checksums
4f7a43415adc5ec0bfea2a8c7153e23392f432e065b51a7a11109c2f94c84c62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page