jakezhaojb / arae Goto Github PK
View Code? Open in Web Editor NEWCode for the paper "Adversarially Regularized Autoencoders (ICML 2018)" by Zhao, Kim, Zhang, Rush and LeCun
License: BSD 3-Clause "New" or "Revised" License
Code for the paper "Adversarially Regularized Autoencoders (ICML 2018)" by Zhao, Kim, Zhang, Rush and LeCun
License: BSD 3-Clause "New" or "Revised" License
Hi!
I found that when I load the model back using autoencoder.load_state_dict(torch.load(ae_path))
etc., it leads to low accuracy (around 0.3) even though the model achieves around 0.8 accuracy in evaluate_autoencoder during training.
I have to use torch.load(ae_path)
and torch.save(autoencoder, f)
to get away this problem.
Probably it is a pytorch bug, as discussed here: https://discuss.pytorch.org/t/saving-and-loading-a-model-in-pytorch/2610/6
Hi, when I run run_snli.py, it does not work. :'(
python run_snli.py --data_path ./data/snli_lm --no_earlystopping
then..I encountered the TypeError as below. Do you know any solutions?
Traceback (most recent call last):
File "run_snli.py", line 103, in
exec(open("train.py").read())
File "", line 434, in
File "", line 389, in train
File "", line 247, in train_ae
File "C:\Users\hsko0\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 489, in call
result = self.forward(*input, **kwargs)
File "D:\Generation\ARAE\lang\models.py", line 174, in forward
hidden = self.encode(indices, lengths, noise)
File "D:\Generation\ARAE\lang\models.py", line 199, in encode
std=self.noise_r)
TypeError: normal() received an invalid combination of arguments - got (means=Tensor, std=float, ), but expected one of:
hi,
I download your given max-length-15 model, and run this code, but the result is very bad:
Sentence interpolations:
A Asian Lady A There
A An A A A
A An A A A
The The A A A
The A a someone A
couple black pushes skinny is
brown Asian woman female child
brown Asian man female child
yellow female man girl couple
fence young man is couple
fishes dog an asleep the
dog black swings surfing is
dog child eats is is
dog player a is wearing
plays lady plays playing wearing
as you see, I even can't generate normal sentence, so I just wonder why I didn't get good result.
is that because of the model, or I need to run many times to get good result?
According to the Algorithm1 in the paper, L_G=errG_real-errG_fake.
However, in your pytorch implementation, only errG_fake is backpropagated.
Why? How does it affect the performance if you backpropagate both?
I got this error while training a full model yesterday:
Traceback (most recent call last):
File "train.py", line 526, in <module>
train_gan_d(train_data[random.randint(0, niter)])
IndexError: list index out of range
This happened for the last batch of the last epoch.
The relevant code block:
# train gan ----------------------------------
for k in range(niter_gan):
# train discriminator/critic
for i in range(args.niters_gan_d):
# feed a seen sample within this epoch; good for early training
errD, errD_real, errD_fake = \
train_gan_d(train_data[random.randint(0, niter)])
It is possible that train_data
can be populated with less elements than niter
in the batchify
function?
The argument list I had was pretty minimal: python train.py --data_path /path/to/billion-word-data --cuda --no_earlystopping
In the paper the semi-supervised learning is described. How can I use this code to do the semi-supervised tasks?
I followed README.md and ran
python train.py --data_path ./data
But then I got the following errors:
{'dropout': 0.0, 'lr_ae': 1, 'load_vocab': '', 'nlayers': 1, 'batch_size': 64, 'beta1': 0.5, 'gan_gp_lambda': 0.1, 'nhidden': 128, 'vocab_size': 30000, 'niters_gan_schedule': '', 'niters_gan_d': 5, 'lr_gan_d': 0.0001, 'grad_lambda': 0.01, 'sample': False, 'arch_classify': '128-128', 'clip': 1, 'hidden_init': False, 'cuda': True, 'log_interval': 200, 'device_id': '0', 'temp': 1, 'seed': 1111, 'maxlen': 25, 'lowercase': True, 'data_path': './data', 'lambda_class': 1, 'lr_classify': 0.0001, 'outf': 'yelp_example', 'noise_r': 0.1, 'noise_anneal': 0.9995, 'lr_gan_g': 0.0001, 'niters_gan_g': 1, 'arch_g': '128-128', 'z_size': 32, 'epochs': 25, 'niters_ae': 1, 'arch_d': '128-128', 'emsize': 128, 'niters_gan_ae': 1}
Original vocab 9599; Pruned to 9603
Number of sentences dropped from ./data/valid1.txt: 0 out of 38205 total
Number of sentences dropped from ./data/valid2.txt: 0 out of 25278 total
Number of sentences dropped from ./data/train1.txt: 0 out of 267314 total
Number of sentences dropped from ./data/train2.txt: 0 out of 176787 total
Vocabulary Size: 9603
382 batches
252 batches
4176 batches
2762 batches
Loaded data!
Seq2Seq2Decoder(
(embedding): Embedding(9603, 128)
(embedding_decoder1): Embedding(9603, 128)
(embedding_decoder2): Embedding(9603, 128)
(encoder): LSTM(128, 128, batch_first=True)
(decoder1): LSTM(256, 128, batch_first=True)
(decoder2): LSTM(256, 128, batch_first=True)
(linear): Linear(in_features=128, out_features=9603, bias=True)
)
MLP_G(
(layer1): Linear(in_features=32, out_features=128, bias=True)
(bn1): BatchNorm1d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(activation1): ReLU()
(layer2): Linear(in_features=128, out_features=128, bias=True)
(bn2): BatchNorm1d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(activation2): ReLU()
(layer7): Linear(in_features=128, out_features=128, bias=True)
)
MLP_D(
(layer1): Linear(in_features=128, out_features=128, bias=True)
(activation1): LeakyReLU(negative_slope=0.2)
(layer2): Linear(in_features=128, out_features=128, bias=True)
(bn2): BatchNorm1d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(activation2): LeakyReLU(negative_slope=0.2)
(layer6): Linear(in_features=128, out_features=1, bias=True)
)
MLP_Classify(
(layer1): Linear(in_features=128, out_features=128, bias=True)
(activation1): ReLU()
(layer2): Linear(in_features=128, out_features=128, bias=True)
(bn2): BatchNorm1d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(activation2): ReLU()
(layer6): Linear(in_features=128, out_features=1, bias=True)
)
Training...
Traceback (most recent call last):
File "train.py", line 574, in <module>
train_ae(1, train1_data[niter], total_loss_ae1, start_time, niter)
File "train.py", line 400, in train_ae
output = autoencoder(whichdecoder, source, lengths, noise=True)
File "/localhome/imd/anaconda2/envs/Pytorch/lib/python3.5/site-packages/torch/nn/modules/module.py", line 491, in __call__
result = self.forward(*input, **kwargs)
File "/groups/branson/home/imd/Documents/project/ARAE/yelp/models.py", line 143, in forward
hidden = self.encode(indices, lengths, noise)
File "/groups/branson/home/imd/Documents/project/ARAE/yelp/models.py", line 160, in encode
batch_first=True)
File "/localhome/imd/anaconda2/envs/Pytorch/lib/python3.5/site-packages/torch/onnx/__init__.py", line 56, in wrapper
if not might_trace(args):
File "/localhome/imd/anaconda2/envs/Pytorch/lib/python3.5/site-packages/torch/onnx/__init__.py", line 130, in might_trace
first_arg = args[0]
IndexError: tuple index out of range
The paper only focuses on discrete data and it doesn't provide examples on continuous data.
I was running the Pretrained Version in Pytorch,
by downloading the files in google drive and then run python generate.py --load_path ./maxlen30
the CUDA is 8.0 and python is running in 3.5
However error message RuntimeError: invalid argument 2: dimension 2 out of range of 2D tensor at /pytorch/torch/lib/TH/generic/THTensor.c:24
Came out and I am not sure how to solve this problem.
Did you had similar problems
I will upload the whole error message.
(tensorflow) slcf@slcf:~/ARAE/pytorch$ python3 generate.py --load_path ./maxlen30/
{'noprint': False, 'ngenerations': 10, 'temp': 1, 'ninterpolations': 5, 'seed': 1111, 'outf': './generated.txt', 'steps': 5, 'load_path': './maxlen30/', 'sample': False}
Loading models from./maxlen30/
Traceback (most recent call last):
File "generate.py", line 135, in
main(args)
File "generate.py", line 74, in main
maxlen=model_args['maxlen'])
File "/home/slcf/ARAE/pytorch/models.py", line 325, in generate
sample=sample)
File "/home/slcf/ARAE/pytorch/models.py", line 270, in generate
inputs = torch.cat([embedding, hidden.unsqueeze(1)], 2)
File "/usr/local/lib/python3.5/dist-packages/torch/autograd/variable.py", line 897, in cat
return Concat.apply(dim, *iterable)
File "/usr/local/lib/python3.5/dist-packages/torch/autograd/_functions/tensor.py", line 316, in forward
ctx.input_sizes = [i.size(dim) for i in inputs]
File "/usr/local/lib/python3.5/dist-packages/torch/autograd/_functions/tensor.py", line 316, in
ctx.input_sizes = [i.size(dim) for i in inputs]
RuntimeError: invalid argument 2: dimension 2 out of range of 2D tensor at /pytorch/torch/lib/TH/generic/THTensor.c:24
I am wondering how to use this code to perform the "offset vector transformation" examples in the paper, such as substituting "clapping" with "walking" and altering the entire input sentence to fit the new word.
I found that in the function train_gan_d(),
the loss_fake and loss_real are in the opposite direction with the original paper.
I was wondering is it correct or not?
Line 242-244 function evaluate_autoencoder
, train.py
:
all_accuracies += \
torch.mean(max_indices.eq(masked_target).float()).data[0]
bcnt += 1
Since masks in batches are different, in each batch there'll be a different number of indices being compared. The average of average is equal to the average of all if and only if all the chunks are of the same size, which is not the case here. The all_accuracies
calculated here is inaccurate.
Besides, in line 233 in function evaluate_autoencoder
, train.py
:
output = autoencoder(source, lengths, noise=True)
During the evaluation, the autoencoder seems to be "cheating" here. The correct word vector of the last word is given, and this is not the case when the autoencoder is doing the real inference. The actual accuracy will be a lot lower. The sentence-level accuracy is way lower than word-level accuracies as well. When the decoder fails to generate "<eos>", the whole sentence is wrong, but in word-level accuracies, the sentence is (n-1)/n correct.
I found that the provided weights work quite well when I generate samples.
However, if I train the model with the provided script(the same setting), the result is very pool.
Are there any changes in the code?
With the current code structure, evaluation and saving of the models only happens when the --no_earlystopping
is not provided.
Ideally we would like some form of evaluation to happen even when not using LM (not sure if possible) and perhaps saving the models at the end of each epoch regardless of the arguments provided.
Since this should be a simple change, let me know if you are currently open to accepting PRs.
Hi
Should this https://github.com/jakezhaojb/ARAE/blob/master/pytorch/experiments/vector.py#L71 be np.mean(means, axis=0)
?
When using the following command for training:
python train.py --data_path PATH_TO_PROCESSED_DATA --enc_grad_norm False
"enc_grad_norm" is still "True". Should this be fixed in this way?
conda create -n pytorch python=3.5 anaconda
source activate pytorch
conda install pytorch torchvision cuda80 -c soumith
python train.py --data_path PATH_TO_PROCESSED_DATA --cuda --kenlm_path PATH_TO_KENLM_DIRECTORY
Training...
Traceback (most recent call last):
File "train.py", line 516, in
train_ae(train_data[niter], total_loss_ae, start_time, niter)
File "train.py", line 352, in train_ae
output = autoencoder(source, lengths, noise=True)
File "/home/$USER/anaconda2/envs/pytorch/lib/python3.5/site-packages/torch/nn/modules/module.py", line 224, in call
result = self.forward(*input, **kwargs)
File "/home/$USER/workspace/ARAE/pytorch/models.py", line 174, in forward
hidden = self.encode(indices, lengths, noise)
File "/home/$USER/workspace/ARAE/pytorch/models.py", line 202, in encode
hidden = torch.div(hidden, norms.expand_as(hidden))
File "/home/$USER/anaconda2/envs/pytorch/lib/python3.5/site-packages/torch/autograd/variable.py", line 725, in expand_as
return Expand.apply(self, (tensor.size(),))
File "/home/$USER/anaconda2/envs/pytorch/lib/python3.5/site-packages/torch/autograd/_functions/tensor.py", line 111, in forward
result = i.expand(*new_size)
RuntimeError: The expanded size of the tensor (300) must match the existing size (64) at non-singleton dimension 1. at /opt/conda/conda-bld/pytorch_1502008109146/work/torch/lib/THC/generic/THCTensor.c:323
In the README
there's no mention of how you generate the train.txt and test.txt for the OneB dataset. Could you clarify how do you do that?
Thanks!
Hello I'm looking at the experiments section and a script called walk.py
is mentioned in the README, but it seems to be missing.
Kindly suggest how to generate sentences (after training) conditioned on a label for eg., positive sentiment along with the conditioning on latent z.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.