Git Product home page Git Product logo

golden-gate-clip's Introduction

โญ ๐ŸŒ‰ Golden Gate CLIP โœจ๐Ÿค– ๐Ÿฅณ ๐ŸŒ‰


Changes 21/June/24

  • Add i-clip-golden-gate-getter-TEXT-all-c_fc-from-wordlist.py
  • Obtains top (by activation value) text transformer features for wordlist
  • Example alltexts.txt contains "strange" CLIP self-predicted words describing Gaussian noise in images

Inspired by Anthrophic's Golden Gate Claude, this repo obtains CLIP Vision Transformer feature activations for a set of images, compares which feature indices are present in all images, and then manipulates the activation value for that neuron in the CLIP Vision Transformer MLP c_fc (Fully Connected Layer).

Result: CLIP predicts "San Francisco, Bay Area, sf, sfo" even for an image that it otherwise (rightfully!) describes as being noise.

CLIP-golden-gate

  • To reproduce: python run_clipga-goldengate-manipulate-neuron-activation.py --image_path noise/ggnoise.png
  • ...And run the files starting with "i-" as-is to get the activation values I used in above code.

To make your own:

  • Edit the folder name in the two files starting with "i-" to be e.g. photos of your cat.
  • Resulting text files show you which feature numbers (indices) are present in all images.
  • This helps to distinguish between vases, sofas, and other things not always around your cat from your actual cat.
  • If none, the "cat" might not be salient in some images. Check the "-all" files manually**!
  • ** I intend to make this easier in the future, by displaying outliers so you can remove them.
  • For now, .json / .csv can be opened with a text editor and manually CTRL+F compared.

  • For best results, manipulate Layer 21, 22 features (penultimate and 3rd layer near the output).
  • Features <=~5 (input) encode simple lines and zigzags --> near output: Multimodal complex features.
  • Check "run_clipga-", I explained how to manipulate activations in the #code #comments!

๐Ÿซค Limitation: Needs at least somewhat similar images (e.g. Golden Gate Bridge <-> Any random bridge) to work when manipulating the activation value on a single layer. You'd likely have to coherently trick CLIP into the right activations over multiple layers to make it totally obsessed about the Golden Gate Bridge like GG Claude was. However, this toolkit is a great start!

โš ๏ธ *Files starting with "x-" allow you to obtain absolutely every activation value in CLIP, including Multihead Attention, projection layer, individual patches (image tokens) + CLS. If you have a use for them, I am assuming you'll need no introduction on how to use them. Enjoy!


Original CLIP Gradient Ascent Script: Used with permission by Twitter / X: @advadnoun

  • GG Bridge images: Via Google & Google Image Search, downsized to minimum resolution 336x336 pixels, limited to 5 (fair use).

~ CLIP's ADVERB neuron activation value + 1000, gazing at the GG Bridge ~

adverb-neuron-good

golden-gate-clip's People

Contributors

zer0int avatar

Watchers

Kostas Georgiou avatar  avatar

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.