Giter Club home page Giter Club logo

tda4atd's Introduction

Artificial Text Detection via Examining the Topology of Attention Maps (EMNLP 2021)

This repository contains code base for the paper which introduces a novel method for artificial text detection (ATD) based on Topological Data Analysis (TDA) which has been understudied in the field of NLP.

Despite the prominent performance of existing ATD method, they still lack interpretability and robustness towards unseen text generation models. To this end, we propose three types of interpretable TDA features for this task, and empirically show that the features derived from the BERT model outperform count- and neural-based baselines up to 10% on three common datasets, and tend to be the most robust towards unseen GPT-style generation models as opposed to existing methods. The probing analysis of the features reveals their sensitivity to the surface and syntactic properties. The results demonstrate that TDA is a promising line with respect to NLP tasks, specifically the ones that incorporate surface and structural information.

We briefly list the features below, and refer the reader to the paper for more details:

  • Topological features (Betti numbers, the number of edges, the number of strong connected components, etc.);
  • Features derived from barcodes (the sum of lengths of bars, the variance of lengths of bars, the time of birth/death of the longest bar, etc.);
  • Features based on distance to patterns (attention to previous token, attention to punctuation marks, attention to CLS-token, etc.).

Dependencies

The code base requires:

  • python 3.8.3
  • matplotlib 3.3.1
  • networkx 2.5.1
  • numpy 1.19.1
  • pandas 1.1.1
  • ripserplusplus 1.1.2
  • scipy 1.5.2
  • sklearn 0.23.2
  • tqdm 4.46.0
  • transformers 4.3.0

Usage

  • For calculating topological invariants by thresholds (Section 4.1), use features_calculation_by_thresholds.ipynb.
  • For calculating barcodes (Section 4.2) and template (Section 4.3) features, use features_calculation_barcodes_and_templates.ipynb.
  • For making predictions with the logistic regression upon calculated features, use features_prediction_gpt_web.ipynb.
  • The head-wise probing analysis by Jo and Myaeng (2020) is conducted using an open-source implementation.

Cite us

Our paper is accepted to the EMNLP 2021 main conference and is selected for oral session.

@inproceedings{kushnareva-etal-2021-artificial,
    title = "Artificial Text Detection via Examining the Topology of Attention Maps",
    author = "Kushnareva, Laida  and
      Cherniavskii, Daniil  and
      Mikhailov, Vladislav  and
      Artemova, Ekaterina  and
      Barannikov, Serguei  and
      Bernstein, Alexander  and
      Piontkovskaya, Irina  and
      Piontkovski, Dmitri  and
      Burnaev, Evgeny",
    booktitle = "Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing",
    month = nov,
    year = "2021",
    address = "Online and Punta Cana, Dominican Republic",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2021.emnlp-main.50",
    pages = "635--649",
    abstract = "The impressive capabilities of recent generative models to create texts that are challenging to distinguish from the human-written ones can be misused for generating fake news, product reviews, and even abusive content. Despite the prominent performance of existing methods for artificial text detection, they still lack interpretability and robustness towards unseen models. To this end, we propose three novel types of interpretable topological features for this task based on Topological Data Analysis (TDA) which is currently understudied in the field of NLP. We empirically show that the features derived from the BERT model outperform count- and neural-based baselines up to 10{\%} on three common datasets, and tend to be the most robust towards unseen GPT-style generation models as opposed to existing methods. The probing analysis of the features reveals their sensitivity to the surface and syntactic properties. The results demonstrate that TDA is a promising line with respect to NLP tasks, specifically the ones that incorporate surface and structural information.",
}

tda4atd's People

Contributors

danchern97 avatar vmkhlv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tda4atd's Issues

Parallelization in barcode calculation

Hi there, thanks for releasing your work.

I wanted to understand the design behind barcode generation implementation in the codebase.

queue = Queue()
number_of_splits = 2
for i, filename in enumerate(tqdm(adj_filenames, desc='Calculating barcodes')):
    barcodes = defaultdict(list)
    adj_matricies = np.load(filename, allow_pickle=True) # samples X 
    print(f"Matricies loaded from: {filename}")
    ntokens = ntokens_array[i*batch_size*DUMP_SIZE : (i+1)*batch_size*DUMP_SIZE]
    splitted = split_matricies_and_lengths(adj_matricies, ntokens, number_of_splits)
    for matricies, ntokens in tqdm(splitted, leave=False):
        p = Process(
            target=subprocess_wrap,
            args=(
                queue,
                get_only_barcodes,
                (matricies, ntokens, dim, lower_bound)
            )
        )
        p.start()
        barcodes_part = queue.get() # block until putted and get barcodes from the queue
        p.join() # release resources
        p.close() # releasing resources of ripser

Why are barcodes calculated in this synchronous subprocess manner? As I understand it, the dataset is split into 2 (why was 2 chosen as number_of_splits?), then each half is fed into a subprocess for barcode generation iteratively. GPU memory usage is quite low (around 150MB) which makes sense as only one document is considered at a time.

Since pool.starmap is used for other parts of calculation, is there any reason why it was not used for barcode calculation? The below code using starmap is much faster and appears to be correct, please let me know if there's anything I'm missing. Thank you!

nworkers=10
pool = multiprocessing.Pool(nworkers)

args = [(matrices, ntokens, dim, lower_bound) for matrices, ntokens in split_matrices]
all_barcodes = pool.starmap(get_only_barcodes, args)

for barcodes_part in all_barcodes:
    barcodes = unite_barcodes(barcodes, barcodes_part)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.