Giter VIP home page Giter VIP logo

detect-shortcuts's Introduction

Rule-Mining for shortcut discovery (VQA-CE)

vqa-ce

This repo contains the rule mining pipeline described in the article : Beyond Question-Based Biases: Assessing Multimodal Shortcut Learning in Visual Question Answering by Corentin Dancette, Rémi Cadène, Damien Teney and Matthieu Cord (https://arxiv.org/abs/2104.03149). It also provides the VQA-CE dataset.

Website here: https://cdancette.fr/projects/vqa-ce/

This code was developped with python 3.7 and pytorch 1.7.0.

VQA-CE

The VQA-CE counterexamples subset can be downloaded here :

The "easy" subset can be obtained by substracting counterexamples and hard from all question_ids.

Usage

Installing requirements

First, you need to install gminer. Follow instructions at https://github.com/cdancette/GMiner.

For python requirements, run pip install -r requirements.txt. This will install pytorch, numpy and tqdm.

Visual Question Answering (VQA)

Download VQA and COCO data

First, run ./download.sh. Data will be downloaded in the ./data directory.

Run the rule mining pipeline

Then run python vqa.py --gminer_path <path_to_gminer> to run our pipeline on the VQA v2 dataset. You can change the parameters, see the end of the vqa.py file or run python vqa.py --help.

This will save in logs/vqa2 various files containing the rules found in the dataset, the question_ids for easy and counterexamples splits, and the predictions made by the rule model.

To evaluate predictions, you can use the multimodal library:

pip install multimodal
python -m multimodal vqa2-eval -p logs/vqa2/rules_predictions.json --split val

Other task

fit

You can use our library to extract rule for any other dataset.

To do so, you can use the fit function in our rule_mining.py It takes the following arguments : fit(dataset, answer_ids, gminer_support=0.01, gminer_max_length=0, gminer_path=None), where :

  • dataset is a list of transactions. Each transaction is a list of integers describing tokens.
  • answer_ids is a list of integers, describing answer ids. They should be contained between 0 and max answer id.
  • gminer_support is the minimum support used to mine frequent itemset.
  • gminer_max_length: minimum length of an itemset. By default no minimum length
  • gminer_path: path to the gminer binary you compiled (see top of the readme).

The function returns a list of rules, contained in namedtuples: Rule = namedtuple("Rule", ["itemset", "ans", "sup", "conf"]).

The itemset contains the input token ids, ans is the answer id, sup and conf are the support and the confidence of this rule.

match_rules

We provide a function to get, for each example in your dataset, all rules matching its input.

match_rules(dataset, rules, answers=None, bsize=500)

This will return (matching_rules, correct_rules), where matching_rules is a list of the same length as the dataset, giving for each example, the matching rules.

You can use this to build your counterexamples subset (examples where all rules are incorrect), or your easy subset (where at least one rule is correct).

detect-shortcuts's People

Contributors

cdancette avatar

Stargazers

 avatar  avatar  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

Forkers

wsgan001

detect-shortcuts's Issues

Malloc() issue with vqa.py

Hi @cdancette,
I am writing because I had a mallo() error while running your script on a VM with Tesla M60 GPU and I am getting this error after the print of the top 20 rules. Have you already had this kind of error? How you solved it? I also checked if the RAM usage reached the limit, but at that point in the code was using only 4MiB of RAM.
Thank you for your help.
Cattura

.json

Hello, I'm very interested in your work, but I can't produce easy.json and hard.json same with yours; when I run the code, I got different counterexamples.json, but I didn't modify any parameters; Can you release your easy.json and hard.json? thank you very much.

About the randomness of the algorithm

Thanks for your effort and advice before! I generated the results using published code, and I found that my results in hard.json have a similarity of 86.9% with the provided hard.json, and of 97.3% with counterexamples.json.
I could understand that this algorithm should have a certain degree of randomness, and I just want to make sure whether you have checked about this? Is this degree of randomness normal? Or does this simply mean I run something wrong?

Great work! I want to get the rules, but it seems cost too much GPU memory.

I think your work is excellent and takes lots of efforts! I try to get the rules in my server, however, the cuda is out of memory in line 182 of rule_mining...

Is it possible and convenient for you to provide the rules? And I want to inquire that is it possible to use less CUDA memory to reproduce your work?

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.