Giter Club home page Giter Club logo

ciphergan's Introduction

CipherGAN

Implementation of CipherGAN, used to obtain the results detailed in Unsupervised Cipher-Cracking Using Neural Networks.
Authors: Aidan N. Gomez, Sīcōng Huang, Ivan Zhang, Bryan M. Li, Muhammad Osama, Łukasz Kaiser

Citing this work

@inproceedings{
    n.2018unsupervised,
    title={Unsupervised Cipher Cracking Using Discrete {GAN}s},
    author={Aidan N. Gomez and Sicong Huang and Ivan Zhang and Bryan M. Li and Muhammad Osama and Lukasz Kaiser},
    booktitle={International Conference on Learning Representations},
    year={2018},
    url={https://openreview.net/forum?id=BkeqO7x0-},
}

Running this code

Call pip install -r CipherGAN/requirements.txt to install all dependencies.

Generating Data

We make use of data generators to generate the TFRecords that are used for training. Of particular note is cipher_generator, which may be used to generate data for the shift and Vigenère ciphers that were tested in the paper.

Sample Call

The settings for the included generators are passed as flags. For example, to generate a word-level Vigenère Cipher (key:CDE) on the Brown Corpus with a sample length of 200, call:

python CipherGAN/data/data_generators/cipher_generator.py \
  --cipher=vigenere \
  --vigenere_key=345 \
  --percentage_training=0.9 \
  --corpus=brown \
  --vocab_size=200 \
  --test_name=vigenere345-brown200-eval \
  --train_name=vigenere345-brown200-train \
  --output_dir=tmp/data \
  --vocab_filename=vigenere345_brown200_vocab.txt

Training

All training can be performed by calling train.py. Training requires the TFRecords generated by the included generators.

Sample Call

Please refer to the flags accepted by train.py for a full set of options.

python -m CipherGAN.train \
  --output_dir=runs/vig345 \
  --test_name="vigenere345-brown200-eval*" \
  --train_name="vigenere345-brown200-train*" \
  --hparam_sets=vigenere_brown_vocab_200

Contributing

We'd love to accept your contributions to this project. Please feel free to open an issue, or submit a pull request as necessary. If you have implementations of this repository in other ML frameworks, please reach out so we may highlight them here.

Acknowledgements

Our thanks to Michal Wiszniewski for his assistance in developing this codebase.
In addition, this repository borrows and builds upon code from:

ciphergan's People

Contributors

aidangomez avatar bryanlimy avatar dependabot[bot] avatar osama 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar

ciphergan's Issues

cipher GAN 交流

您好,我最近在研究cipher GAN,想和你相互交流一下。我的微信:loveanshen 我的QQ:519838354 期待您百忙中的回复!

How to run after training?

I have trained the network but I don't know how to run it. How would I use it to decrypt a text file or string?

About the calculation of GP loss

Hi ~, I have run your code on my computer with default commands mentioned in README.md,
when I track the calculation of GP loss, I found a little bit confusing,

def wasserstein_penalty(discriminator, A_true, A_fake, params,
                        discriminator_params):
  A_interp = sample_along_line(A_true, A_fake, params)
  if params.use_embeddings:
    A_interp = softmax_to_embedding(A_interp, params)
  discrim_A_interp = discriminator(A_interp, discriminator_params, params)
  discrim_A_grads = tf.gradients(discrim_A_interp, [A_interp])

  if params.original_l2:
    l2_loss = tf.sqrt(
        tf.reduce_sum(
            tf.convert_to_tensor(discrim_A_grads)**2, axis=[1, 2]))
    if params.true_lipschitz:
      loss = params.wasserstein_loss * tf.reduce_mean(
          tf.nn.relu(l2_loss - 1)**2)
    else:
      loss = params.wasserstein_loss * tf.reduce_mean((l2_loss - 1)**2)
  else:
    loss = params.wasserstein_loss * (tf.nn.l2_loss(discrim_A_grads) - 1)**2
  return loss

When the A_interp has the shape [64, 100, 256], which can be annotated with [batch_size, seq_len, input_dim], and discrim_A_interp has shape [64, 2, 1], then tf.convert_to_tensor(discrim_A_grads) has shape [1, 64, 100, 256], but you apply reduce_sum on it along axis [1,2] instead of axis [2,3]?

Resuming Training?

Is there any way to resume the training basically when i loaded the data into the same directories with the checkpoints and the graph.pbtxt but still training command said CipherGAN.train is not an attribute for the python. What was the issue and the appropriate way to resume your training?

KeyError: 'data/data_generators/tmp/data/vigenere_brown_vocab_200'

C:\Users\caocao\Anaconda3\python.exe D:/work/gan-pix2pix/CipherGAN-master/CipherGAN-master/train.py --output_dir=runs/vig345 \ --test_name=data/data_generators/tmp/data/vigenere345-brown200-eval* \ --train_name=data/data_generators/tmp/data/vigenere345-brown200-train* \ --hparam_sets=data/data_generators/tmp/data/vigenere_brown_vocab_200
Traceback (most recent call last):
File "D:/work/gan-pix2pix/CipherGAN-master/CipherGAN-master/train.py", line 89, in
tf.app.run()
File "C:\Users\caocao\Anaconda3\lib\site-packages\tensorflow\python\platform\app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "D:/work/gan-pix2pix/CipherGAN-master/CipherGAN-master/train.py", line 85, in main
_run_locally(FLAGS.train_steps, FLAGS.eval_steps)
File "D:/work/gan-pix2pix/CipherGAN-master/CipherGAN-master/train.py", line 42, in _run_locally
hparams = get_hparams(FLAGS.hparam_sets)
File "D:\work\gan-pix2pix\CipherGAN-master\CipherGAN-master\hparams\registry.py", line 20, in get_hparams
curr = _HPARAMS[name]
KeyError: 'data/data_generators/tmp/data/vigenere_brown_vocab_200'

Exception: Unsupported type: <class 'numpy.int32'>

File "D:/work/gan-pix2pix/CipherGAN-master/CipherGAN-master/data/data_generators/cipher_generator.py", line 276, in
cipher_generator()
File "D:/work/gan-pix2pix/CipherGAN-master/CipherGAN-master/data/data_generators/cipher_generator.py", line 270, in cipher_generator
FLAGS.num_shards)
File "D:\work\gan-pix2pix\CipherGAN-master\CipherGAN-master\data\data_generators\generator_utils.py", line 44, in generate_files
sequence_example = to_example(case)
File "D:\work\gan-pix2pix\CipherGAN-master\CipherGAN-master\data\data_generators\generator_utils.py", line 19, in to_example
raise Exception("Unsupported type: %s" % type(v[0]))
Exception: Unsupported type: <class 'numpy.int32'>

How to specify prediction_key for Metric

Hi!

When I run an example from the readme with Accuracy metric in addition to the default MSE, I get the following error:

ValueError: MetricSpec without specifiedValueError: MetricSpec without specified prediction_key requires predictions tensor or single element dict, got {'X': <tf.Tensor 'cycle_gan/transforms/G/Reshape_1:0' shape=(64, 100, 202) dtype=float32>, 'Y': <tf.Tensor 'cycle_gan/transforms/F/Reshape_1:0' shape=(64, 100, 202) dtype=float32>}
requires predictions tensor or single element dict, got {'X': <tf.Tensor 'cycle_gan/transforms/G/Reshape_1:0' shape=(64, 100, 202) dtype=float32>, 'Y': <tf.Tensor 'cycle_gan/transforms/F/Reshape_1:0' shape=(64, 100, 202) dtype=float32>}

How does the correct prediction_key specification for the README example look like?

Best,
Maksym

ModuleNotFoundError: No module named '__main__.hparams'; '__main__' is not a package

Hello,I have a question to ask you. I hope you can help me solve it. I did the calculation according to your method, and the following problem occurred in the second step. I've tried my best to solve it, but I still can't.Questions as follows:

E:\WorkSpace\venv\Scripts\python.exe E:/WorkSpace/CipherGAN/train.py
Traceback (most recent call last):
File "E:/WorkSpace/CipherGAN/train.py", line 5, in
from .hparams.registry import get_hparams
ModuleNotFoundError: No module named 'main.hparams'; 'main' is not a package

Error in the Code

The error arises when I run the start the training the flags of train.py where 1e4 and 1e2 are written they are seen as float values while int must be there otherwise the code gives the error. expecting the --train_steps to be an int or string. 1e4 and 1e2 must be changed to 10000 and 100 respectively so that the code starts running fine. Kindly update it.

Cannot output accuracy

Hello,I encountered a problem.Following the operation of the README, the training was successful. However, the output is xy_mse, and I want to output the accuracy.Therefore, the xy_mse of the train.py file is changed to acc, But the accuracy cannot be output.

I get the following error:
ValueError:MetricSpec without specified prediction_key requires predictions tensor or single element dict, got {'X': <tf.Tensor 'cycle_gan/transforms/G/Reshape_1:0' shape=(64, 100, 202) dtype=float32>, 'Y': <tf.Tensor 'cycle_gan/transforms/F/Reshape_1:0' shape=(64, 100, 202) dtype=float32>}.
I look forward to your answer,best wishes,thank you.

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.