TensorFlow/Adversarial
From charlesreid1
Adversarial Neural Networks
Adversarial neural networks use an architecture consisting of two separate neural networks - one network attempts to learn how to accomplish a task, and another network attempts to differentiate between the output of the first network and the "real" output.
TensorFlow Examples of Adversarial Neural Networks
Adversarial Crypto
This adversarial crypto neural network attempts to learn how to protect communications using the adversarial architecture.
Link to paper: "Learning to Protect Communications with Adversarial Neural Cryptography": https://arxiv.org/abs/1610.06918
Link to code: https://github.com/tensorflow/models/tree/master/research/adversarial_crypto
Running
To train the network:
$ python train_eval.py
The approach used by the training is to train the "defender" network (representing the Alice-Bob channel) until it is sufficiently well-trained, then reset the "attacker" network (representing the eavesdropper Eve) from scratch to give the eavesdropper multiple opportunities to find weaknesses in the cryptosystem.
The Network
We'll step through the code line-by-line again. Here's the link to the code: https://github.com/tensorflow/models/blob/master/research/adversarial_crypto/train_eval.py
Obligatory license info:
# Copyright 2016 The TensorFlow Authors All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ==============================================================================
Some info about the network:
- There are actually 3 neural networks involved: Alice, Bob, and Eve
- Alice takes inputs in_m (message), in_k (key) and outputs the ciphertext
- Bob takes inputs in_k (key), ciphertext and attempts to output the plaintext
- Even takes input ciphertext (no key) and also attempts to output the plaintext
The file starts with imports/declarations to be compatible with Python 3:
# TensorFlow Python 3 compatibility from __future__ import absolute_import from __future__ import division from __future__ import print_function import signal import sys from six.moves import xrange # pylint: disable=redefined-builtin import tensorflow as tf
Hyperparameter flags can be set on the command line:
flags = tf.app.flags
flags.DEFINE_float('learning_rate', 0.0008, 'Constant learning rate')
flags.DEFINE_integer('batch_size', 4096, 'Batch size')
FLAGS = flags.FLAGS
The FLAGS stuff does not seem to be defined anywhere in the documentation, so the usage is not clear here. But, as an author on TF project states here, it is intended to make demos more convenient, and essentially wraps argparse.