Giter VIP home page Giter VIP logo

sentiment-discovery's Introduction

** DEPRECATED **

This repo has been deprecated. Please visit Megatron-LM for our up to date Large-scale unsupervised pretraining and finetuning code.

If you would still like to use this codebase, see our tagged releases and install required software/dependencies that was available publicly at that date.

PyTorch Unsupervised Sentiment Discovery

This codebase contains pretrained binary sentiment and multimodel emotion classification models as well as code to reproduce results from our series of large scale pretraining + transfer NLP papers: Large Scale Language Modeling: Converging on 40GB of Text in Four Hours and Practical Text Classification With Large Pre-Trained Language Models. This effort was born out of a desire to reproduce, analyze, and scale the Generating Reviews and Discovering Sentiment paper from OpenAI.

The techniques used in this repository are general purpose and our easy to use command line interface can be used to train state of the art classification models on your own difficult classification datasets.

This codebase supports mixed precision training as well as distributed, multi-gpu, multi-node training for language models (support is provided based on the NVIDIA APEx project). In addition to training language models, this codebase can be used to easily transfer and finetune trained models on custom text classification datasets.

For example, a Transformer language model for unsupervised modeling of large text datasets, such as the amazon-review dataset, is implemented in PyTorch. We also support other tokenization methods, such as character or sentencepiece tokenization, and language models using various recurrent architectures.

The learned language model can be transferred to other natural language processing (NLP) tasks where it is used to featurize text samples. The featurizations provide a strong initialization point for discriminative language tasks, and allow for competitive task performance given only a few labeled samples. For example, we consider finetuning our models on the difficult task of multimodal emotion classification based on a subset of the plutchik wheel of emotions.

plutchik fig

Created by Robert Plutchik, this wheel is used to illustrate different emotions in a compelling and nuanced way. He suggested that there are 8 primary bipolar emotions (joy versus sadness, anger versus fear, trust versus disgust, and surprise versus anticipation) with different levels of emotional intensity. For our classification task we utilize tweets from the SemEval2018 Task 1E-c emotion classification dataset to perform multilabel classification of anger, anticipation, disgust, fear, joy, sadness, surprise, and trust. This is a difficult task that suffers from real world classification problems such as class imbalance and labeler disagreement.

semeval results

On the full SemEval emotion classification dataset we find that finetuning our model on the data achieves competitive state of the art performance with no additional domain-specific feature engineering.

semeval leaderboard

ReadMe Contents

Setup

Install

Install the sentiment_discovery package with python3 setup.py install in order to run the modules/scripts within this repo.

Python Requirements

At this time we only support python3.

  • numpy
  • pytorch (>= 0.4.1)
  • pandas
  • scikit-learn
  • matplotlib
  • unidecode
  • sentencepiece
  • seaborn
  • emoji

Pretrained models

We've included our sentencepiece tokenizer model and vocab as a zip file:

We've included a transformer language model base as well as a 4096-d mlstm language model base. For examples on how to use these models please see our finetuning and transfer sections. Even though these models were trained with FP16 they can be used in FP32 training/inference.

We've also included classifiers trained on a subset of SemEval emotions corresponding to the 8 plutchik emotions (anger, anticipation, disgust, fear, joy, sadness, surprise, and trust):

Lastly, we've also included already trained classification models for SST and IMDB binary sentiment classification:

To use classification models that reproduce results from our original large batch language modeling paper please use the following commit hash and set of models.

We did not include pretrained models leveraging ELMo. To reproduce our papers' results with ELMo, please see our available resources.

Each file has a dictionary containing a PyTorch state_dict consisting of a language model (lm_encoder keys) trained on Amazon reviews and a classifier (classifier key) as well as accompanying args necessary to run a model with that state_dict.

Data Downloads

In the ./data folder we've provided processed copies of the Binary Stanford Sentiment Treebank (Binary SST), IMDB Movie Review, and the SemEval2018 Tweet Emotion datasets as part of this repository. In order to train on the amazon dataset please download the "aggressively deduplicated data" version from Julian McAuley's original site. Access requests to the dataset should be approved instantly. While using the dataset make sure to load it with the --loose-json flag.

Usage

In addition to providing easily reusable code of the core functionalities (models, distributed, fp16, etc.) of this work, we also provide scripts to perform the high-level functionalities of the original paper:

  • sentiment classification of input text
  • unsupervised reconstruction/language modeling of a corpus of text (+ script for launching distributed workers)
  • transfer of learned language model to perform sentiment analysis on a specified corpus
  • sampling from language model to generate text (possibly of fixed sentiment) + heatmap visualization of sentiment in text

Classifying text

Classify an input csv/json using one of our pretrained models or your own. Performs classification on Binary SST by default. Output classification probabilities are saved to a .npy file

python3 run_classifier.py --load_model ama_sst.pt                               # classify Binary SST
python3 run_classifier.py --load_model ama_sst_16.pt --fp16                     # run classification in fp16
python3 run_classifier.py --load_model ama_sst.pt --text-key <text-column> --data <path.csv>     # classify your own dataset

See here for more documentation.

Training Language Models (+ Distributed/FP16 Training)

Train a language model on a csv/json corpus. By default we train a weight-normalized, 4096-d mLSTM, with a 64-d character embedding. This is the first step of a 2-step process to training your own sentiment classifier. Saves model to lang_model.pt by default.

python3 pretrain.py                                                               #train a large model on imdb
python3 pretrain.py --model LSTM --nhid 512                                       #train a small LSTM instead
python3 pretrain.py --fp16 --dynamic-loss-scale                                   #train a model with fp16
python3 -m multiproc pretrain.py                                                  #distributed model training
python3 pretrain.py --data ./data/amazon/reviews.json --lazy --loose-json \       #train a model on amazon data
  --text-key reviewText --label-key overall --optim Adam --split 1000,1,1 
python3 pretrain.py --tokenizer-type SentencePieceTokenizer --vocab-size 32000 \  #train a model with our sentencepiece tokenization
  --tokenizer-type bpe --tokenizer-path ama_32k_tokenizer.model 
python3 pretrain.py --tokenizer-type SentencePieceTokenizer --vocab-size 32000 \  #train a transformer model with our sentencepiece tokenization
  --tokenizer-type bpe --tokenizer-path ama_32k_tokenizer.model --model transformer \
  --decoder-layers 12 --decoder-embed-dim 768 --decoder-ffn-embed-dim 3072 \
  --decoder-learned-pos --decoder-attention-heads 8
bash ./experiments/train_mlstm_singlenode.sh                                      #run our mLSTM training script on 1 DGX-1V
bash ./experiments/train_transformer_singlenode.sh                                #run our transformer training script on 1 DGX-1V 

For more documentation of our language modeling functionality look here

In order to learn about our language modeling experiments and reproduce results see the training reproduction section in analysis.

For information about how we achieve numerical stability with FP16 training see our fp16 training analysis.

Sentiment Transfer

Given a trained language model, this script will featurize text from train, val, and test csv/json's. It then uses sklearn logistic regression to fit a classifier to predict sentiment from these features. Lastly it performs feature selection to try and fit a regression model to the top n most relevant neurons (features). By default only one neuron is used for this second regression.

python3 transfer.py --load mlstm.pt                                 #performs transfer to SST, saves results to `<model>_transfer/` directory
python3 transfer.py --load mlstm.pt --neurons 5                     #use 5 neurons for the second regression
python3 transfer.py --load mlstm.pt --fp16                          #run model in fp16 for featurization step
bash ./experiments/run_sk_sst.sh                                    #run transfer learning with mlstm on imdb dataset
bash ./experiments/run_sk_imdb.sh                                   #run transfer learning with mlstm on sst dataset

Additional documentation of the command line arguments available for transfer can be found here

Classifier Finetuning

Given a trained language model and classification dataset, this script will build a classifier that leverages the trained language model as a text feature encoder. The difference between this script and transfer.py is that the model training is performed end to end: the loss from the classifier is backpropagated into the language model encoder as well. This script allows one to build more complex classification models, metrics, and loss functions than transfer.py. This script supports building arbitrary multilable, multilayer, and multihead perceptron classifiers. Additionally it allows using language modeling as an auxiliary task loss during training and multihead variance as an auxiliary loss during training. Lastly this script supports automatically selecting classification thresholds from validation performance. To measure validation performance this script includes more complex metrics including: f1-score, mathew correlation coefficient, jaccard index, recall, precision, and accuracy.

python3 finetune_classifier.py --load mlstm.pt --lr 2e-5 --aux-lm-loss --aux-lm-loss-weight .02   #finetune mLSTM model on sst (default dataset) with auxiliary loss
python3 finetune_classifier.py --load mlstm.pt --automatic-thresholding --threshold-metric f1     #finetune mLSTM model on sst and automatically select classification thresholds based on the validation f1 score
python3 finetune_classifier.py --tokenizer-type SentencePieceTokenizer --vocab-size 32000 \       #finetune transformer with sentencepiece on SST
  --tokenizer-type bpe tokenizer-path ama_32k_tokenizer.model --model transformer --lr 2e-5 \
  --decoder-layers 12 --decoder-embed-dim 768 --decoder-ffn-embed-dim 3072 \
  --decoder-learned-pos --decoder-attention-heads 8 --load transformer.pt --use-final-embed
python3 finetune_classifier.py --automatic-thresholding --non-binary-cols l1 l2 l3 --lr 2e-5\     #finetune multilayer classifier with 3 classes and 4 heads per class on some custom dataset and automatically select classfication thresholds
  --classifier-hidden-layers 2048 1024 3 --heads-per-class 4 --aux-head-variance-loss-weight 1.   #`aux-head-variance-loss-weight` is an auxiliary loss to increase the variance between each of the 4 head's weights
  --data <custom_train>.csv --val <custom_val>.csv --test <custom_test>.csv --load mlstm.pt
bash ./experiments/se_transformer_multihead.sh                                                    #finetune a multihead transformer on 8 semeval categories

See how to reproduce our finetuning experiments in the finetuning reproduction section of analysis.

Additional documentation of the command line arguments available for finetune_classifier.py can be found here

Acknowledgement

A special thanks to our amazing summer intern Neel Kant for all the work he did with transformers, tokenization, and pretraining+finetuning classification models.

A special thanks to @csarofeen and @Michael Carilli for their help developing and documenting our RNN interface, Distributed Data Parallel model, and fp16 optimizer. The latest versions of these utilities can be found at the APEx github page.

Thanks to @guillitte for providing a lightweight pytorch port of openai's sentiment-neuron repo.

This project uses the amazon review dataset collected by J. McAuley

Thanks

Want to help out? Open up an issue with questions/suggestions or pull requests ranging from minor fixes to new functionality.

May your learning be Deep and Unsupervised.

sentiment-discovery's People

Contributors

kantneel avatar raulpuric avatar sufuf3 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  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

sentiment-discovery's Issues

Crash when generating heatmap

I put the next text in a text file and run:

python3 generate.py --load_model imdb_clf.pt --gen_length -1 --visualize --text "$(cat review.txt)

review.txt cointains:

Unsurprisingly, this motivation dries up as soon as Deadpool goes on his first X-mission (while wearing a hilarious trainee T-shirt, as if he were a red-shirting freshman on a football team). In trying to protect the confused teen mutant Russell (played by Julian Dennison from the brilliant Hunt For The Wilderpeople), Deadpool screws upโ€”and sets into motion events that catch the eye of time-traveling ass-kicker Cable (Josh Brolin).

While for many paragraphs it works producing nice heat-map, for this text i get the following error:

Traceback (most recent call last):
  File "generate.py", line 230, in <module>
    chrs, vals = process_text(args.text, model, input, args.temperature, neuron, mask, args.overwrite, polarity)
  File "generate.py", line 154, in process_text
    ch, val = model_step(model, input, neuron, mask, overwrite, polarity)
  File "generate.py", line 129, in model_step
    out, _ = model(input)
  File "/root/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/root/work/sentiment-discovery/model/model.py", line 36, in forward
    output, hidden = self.rnn(emb, reset_mask=reset_mask)
  File "/root/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/root/anaconda3/lib/python3.6/site-packages/apex-0.1-py3.6.egg/apex/RNN/RNNBackend.py", line 149, in forward
  File "/root/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/root/anaconda3/lib/python3.6/site-packages/apex-0.1-py3.6.egg/apex/RNN/cells.py", line 37, in forward
  File "/root/anaconda3/lib/python3.6/site-packages/apex-0.1-py3.6.egg/apex/RNN/cells.py", line 62, in mLSTMCell
  File "/root/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py", line 994, in linear
    output = input.matmul(weight.t())
RuntimeError: cublas runtime error : the GPU program failed to execute at /opt/conda/conda-bld/pytorch_1524586445097/work/aten/src/THC/THCBlas.cu:249
/opt/conda/conda-bld/pytorch_1524586445097/work/aten/src/THC/THCTensorIndex.cu:306: void indexSelectSmallIndex(TensorInfo<T, IndexType>, TensorInfo<T, IndexType>, TensorInfo<long, IndexType>, int, int, IndexType, long) [with T = float, IndexType = unsigned int, DstDim = 2, SrcDim = 2, IdxDim = -2]: block: [0,0,0], thread: [32,0,0] Assertion `srcIndex < srcSelectDimSize` failed.
[...]

Note i installed PyTorch 0.4.0 with conda.

Minimal sentiment classification code

I'm trying to expose the pre-trained models over REST, such that an HTTP POST request with a list of strings returns a response with their corresponding sentiment scores. The command line args can be replaced with their defaults.

I noticed that configure_data.py is being used to split the input data into train, test & validation batches & is also calling methods from data_utils module to prepare the data for training

train_data, val_data, test_data = data_config.apply(args)

But, is there a simpler way to pass in a list of strings to the classify method?

def classify(model, text):

UnboundLocalError: local variable 'cell' referenced before assignment

I forked your project and changed it in order to test it for my language. I faced the following error during the run of transfer:

transform:   0%|                                                           | 0/1 [00:00<?, ?batch/s]
Traceback (most recent call last):
  File "transfer.py", line 403, in <module>
    main()
  File "transfer.py", line 247, in main
    trXt, trY = transform(model, train_data, args)
  File "transfer.py", line 130, in transform
    cell, _ = get_outs(text_batch, length_batch)
  File "transfer.py", line 116, in get_outs
    cell_out, lm_or_encoder_out = model(text_batch, length_batch, args.get_hidden)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 489, in __call__
    result = self.forward(*input, **kwargs)
  File "/content/model/model.py", line 156, in forward
    return cell, None
UnboundLocalError: local variable 'cell' referenced before assignment

Do you have any solution for this problem?
I would appreciate it if you could help me figure this out.

This is the forked project and This is a colab notebook which contains my test.

Dataloader workers created subprocess more and more after each epoch

Dataloader workers created more and more subprocess in every epoch. this led to severe memory loss after each epoch end. Finally my CPU memory used up and the program crashed.

The only thing i can do is trying to set 1 epoch and more iters. But the dataloader seems also exist memory leak slowly, and i do not know it's due to the pytorch dataloader or shardloader.

Thank you very much.

running problems in classify.py

Hi,
I try to use

python3 transfer.py --load_model sst_clf.pt   

But the script does not run properly with following error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
Traceback (most recent call last):
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\spawn.py", line 106, in spawn_main
  File "classifier.py", line 155, in <module>
    exitcode = _main(fd)
    ypred = classify(model, train_data)
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\spawn.py", line 115, in _main
  File "classifier.py", line 119, in classify
    prepare(preparation_data)
    for i, data in enumerate(text):
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\spawn.py", line 226, in prepare
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\site-packages\torch\utils\data\dataloader.py", line 451, in __iter__
    _fixup_main_from_path(data['init_main_from_path'])
    return _DataLoaderIter(self)
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\spawn.py", line 278, in _fixup_main_from_path
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\site-packages\torch\utils\data\dataloader.py", line 239, in __init__
    run_name="__mp_main__")
    w.start()
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\runpy.py", line 254, in run_path
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\process.py", line 105, in start
    pkg_name=pkg_name, script_name=fname)
    self._popen = self._Popen(self)
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\runpy.py", line 96, in _run_module_code
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\context.py", line 212, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\context.py", line 313, in _Popen
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\runpy.py", line 85, in _run_code
    return Popen(process_obj)
    exec(code, run_globals)
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\popen_spawn_win32.py", line 66, in __init__
  File "D:\my_research\sentiment-discovery\classifier.py", line 155, in <module>
    reduction.dump(process_obj, to_child)
    ypred = classify(model, train_data)
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\reduction.py", line 59, in dump
  File "D:\my_research\sentiment-discovery\classifier.py", line 119, in classify
    ForkingPickler(file, protocol).dump(obj)
    for i, data in enumerate(text):
BrokenPipeError: [Errno 32] Broken pipe
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\site-packages\torch\utils\data\dataloader.py", line 451, in __iter__
    return _DataLoaderIter(self)
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\site-packages\torch\utils\data\dataloader.py", line 239, in __init__
    w.start()
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\process.py", line 105, in start
    self._popen = self._Popen(self)
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\context.py", line 212, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\context.py", line 313, in _Popen
    return Popen(process_obj)
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\popen_spawn_win32.py", line 34, in __init__
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\spawn.py", line 144, in get_preparation_data
    _check_not_importing_main()
  File "C:\Users\teng.fu\AppData\Local\conda\conda\envs\python35\lib\multiprocessing\spawn.py", line 137, in _check_not_importing_main
    is not going to be frozen to produce an executable.''')
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

I add some print cmd in the classify.py and it seems when the classify() function is called,
when entering

with torch.no_grad():

The script start to recreate another model and start the process again, not sure what is happening here...
I only add some print, nothing more.

pytorch version: 0.4.0
cuda version 9.0
python 3.5

Convert version 0.2 to 0.3

We've changed the ordering of our LSTM gates for the mLSTM cell. To make old models you've trained forward compatible with versions >= v0.5 please use the following script.

The google drive models will be updated automatically and ready for download in a couple of hours after this post.

import torch
import sys
import os

inpath = sys.argv[1]
outpath = sys.argv[2]

dp = os.path.dirname(outpath)
if dp!='' and not os.path.exists(dp):
        os.makedirs(dp)

sd= torch.load(inpath)
if 'state_dict' in sd:
    sd = sd['state_dict']

rnn = sd['encoder']['rnn']

def reorder_gates(param):
    if param.size(0) == param.size(1) * 4:
        i,f,o,j = torch.chunk(param, 4)
        return torch.cat([i,f,j,o])
    return param

is_mlstm = sum([p.find('w_mih')!=-1 for p in rnn.keys()])

if not is_mlstm:
    print('no conversion needed')
    exit()

for k, v in rnn.items():
    if k.find('w_ih')!=-1 or k.find('w_hh')!=-1:
        rnn[k] = reorder_gates(v)

torch.save(sd, outpath)

text classification using pretrained models usage?

I tried classifying text using both the Binary SST & Imdb pretrained models. But all 10,000 sentences/examples from my corpus were labeled -1.0 i.e negative sentiment ?

python classifier.py --load_model ~/imdb_clf.pt --test ~/sample10k.csv

My corpus looks like below

$ head -n 4 ~/sample10k.csv
sentence
It was for Infinity cars driving with a family nice snooth ride the XQ 60
"I like the ad, but would like to see more interior shots. Seems to me you are describing interior roominess."
I love the car
The poem was really sweet.
I really liked the car
I love this ad because it seems to talk the real life things that can happen in a car with a family.

Output

$ head sample10k.sentence.label.csv
label,sentence
-1.0,"
It was for Infinity cars driving with a family nice snooth ride the XQ 60 "
-1.0,"
I like the ad, but would like to see more interior shots. Seems to me you are describing interior roominess. "
-1.0,"
I love the car "
-1.0,"
The poem was really sweet. "
-1.0,"
I really liked the car "
-1.0,"
I love this ad because it seems to talk the real life things that can happen in a car with a family. "

Running sentiment-discovery?

I tried following the docs for installing and running the program.

At first I tried

 pip setup.py install
ERROR: unknown command "setup.py"

Next I tried

 python setup.py install

Arguments used to build CUDA extension:
extra_compile_args : ['--std=c++11']
include_dirs:  ['/home/friday/anaconda3/lib/python3.6/site-packages/torch/lib/include', '/home/friday/Documents/Sentiment Analysis/sentiment-discoverylatest/apex_utils/include', '/usr/local/cuda/include']
extra_link_args:  []
library_dirs:  ['/home/friday/anaconda3/lib/python3.6/site-packages/torch/lib', '/usr/local/cuda/lib64']
libraries:  ['cudart', 'cuda', 'ATen']


Compiling cuda modules with nvcc:
nvcc -Xcompiler -fPIC -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_70,code=compute_70 --std=c++11 -O3 -I/home/friday/anaconda3/lib/python3.6/site-packages/torch/lib/include -I/home/friday/Documents/Sentiment Analysis/sentiment-discoverylatest/apex_utils/include -I/usr/local/cuda/include -c /home/friday/Documents/Sentiment Analysis/sentiment-discoverylatest/apex_utils/csrc/kernel.cu -o /home/friday/Documents/Sentiment Analysis/sentiment-discoverylatest/apex_utils/build/kernel.o
nvcc fatal   : Unsupported gpu architecture 'compute_60'
Traceback (most recent call last):
  File "setup.py", line 159, in <module>
    CompileCudaFiles()
  File "setup.py", line 146, in CompileCudaFiles
    subprocess.check_call(nvcc_cmd+file_opts)
  File "/home/friday/anaconda3/lib/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['nvcc', '-Xcompiler', '-fPIC', '-gencode', 'arch=compute_52,code=sm_52', '-gencode', 'arch=compute_60,code=sm_60', '-gencode', 'arch=compute_61,code=sm_61', '-gencode', 'arch=compute_70,code=sm_70', '-gencode', 'arch=compute_70,code=compute_70', '--std=c++11', '-O3', '-I/home/friday/anaconda3/lib/python3.6/site-packages/torch/lib/include', '-I/home/friday/Documents/Sentiment Analysis/sentiment-discoverylatest/apex_utils/include', '-I/usr/local/cuda/include', '-c', '/home/friday/Documents/Sentiment Analysis/sentiment-discoverylatest/apex_utils/csrc/kernel.cu', '-o', '/home/friday/Documents/Sentiment Analysis/sentiment-discoverylatest/apex_utils/build/kernel.o']' returned non-zero exit status 1.

Later just to run the sentiment classifier i ran

 python3 transfer.py --load_model sst_clf.pt --neurons 5
Traceback (most recent call last):
  File "transfer.py", line 20, in <module>
    from apex.reparameterization import apply_weight_norm, remove_weight_norm
  File "/home/friday/anaconda3/lib/python3.6/site-packages/apex/__init__.py", line 18, in <module>
    from apex.interfaces import (ApexImplementation,
  File "/home/friday/anaconda3/lib/python3.6/site-packages/apex/interfaces.py", line 10, in <module>
    class ApexImplementation(object):
  File "/home/friday/anaconda3/lib/python3.6/site-packages/apex/interfaces.py", line 14, in ApexImplementation
    implements(IApex)
  File "/home/friday/anaconda3/lib/python3.6/site-packages/zope/interface/declarations.py", line 404, in implements
    raise TypeError(_ADVICE_ERROR % 'implementer')
TypeError: Class advice impossible in Python3.  Use the @implementer class decorator instead.

So I tried changing the zope.interface versions and apex versions but it still throws error.

Tried to run with native python3 as well as conda3 but it doesn't work.

So anyone can give me an advice or just give me a version controlled list of requirements.txt, It'll be so helpful, Please guys :)

MemoryError - Amazon dataset

Hi,

I get memory error while trying to train on Amazon aggressively deduplicated data. I have 64 GB of memory installed on my system and a 1080ti installed.

I run command inside an LXD container.

root@ub-16-sentiment:~/work/sentiment-discovery# python3 main.py --data /home/adrianc/work/Sentiment/dataset/amazon/aggressive_dedup.json --lazy --loose_json --text_key reviewText --label_key overall --num_shards 1002 --optim Adam --split 1000,1,1
configuring data
Traceback (most recent call last):
  File "main.py", line 135, in <module>
    train_data, val_data, test_data = data_config.apply(args)
  File "/root/work/sentiment-discovery/configure_data.py", line 16, in apply
    return make_loaders(opt)
  File "/root/work/sentiment-discovery/configure_data.py", line 63, in make_loaders
    train = data_utils.make_dataset(**data_set_args)
  File "/root/work/sentiment-discovery/data_utils/__init__.py", line 133, in make_dataset
    binarize_sent=binarize_sent, delim=delim, drop_unlabeled=drop_unlabeled, loose=loose)
  File "/root/work/sentiment-discovery/data_utils/__init__.py", line 103, in handle_lazy
    binarize_sent=binarize_sent, delim=delim, drop_unlabeled=drop_unlabeled, ds=data_set)
  File "/root/work/sentiment-discovery/data_utils/__init__.py", line 54, in get_lazy
    make_lazy(processed_path, ds.X, data_type=data_shard)
  File "/root/work/sentiment-discovery/data_utils/lazy_loader.py", line 33, in make_lazy
    f.write(''.join(strs))
MemoryError

The problem is memory usage get's beyond 64 GB.

Regards,
Adrian

generate with pre-trained models gives gibberish data

When I try to run generate on the pre-trained models included in the repo, I get gibberish output

python3 /sentiment-discovery/generate.py --gen_length 100 --load_model /SDModels/imdb_clf_16.pt
Creating mlstm
/sentiment-discovery/generate.py:112: UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number
neuron = neuron[0]

ยชSยฆ.๏ฟฝ๏ฟฝรŸรฝ;ร™ยทXรœยฟ}รญรธ{รU=๏ฟฝ0รฉ๏ฟฝ)รฒ$EE๏ฟฝร™ยขN'j$ยผรปe๏ฟฝรคยฒ0รƒ(C#ยคยฑ๏ฟฝ๏ฟฝรŸ๏ฟฝรฟ[ร—๏ฟฝfn๏ฟฝxXร”/s๏ฟฝ๏ฟฝยฉ

I have torch

import torch
print (torch.version)
0.4.1

UnicodeEncodeError on data load when using --lazy

I'm back to testing out this library now that I have a setup on top of V100 GPUs, and some of the features definitely seems to work better now.

One problem I have is that when using --lazy, I get a unicode error on data loading, like UnicodeEncodeError: 'ascii' codec can't encode character '\uf04a' in position 13051820: ordinal not in range(128)

As far as I know there are no non-printable characters in my data (and furthermore it works fine when --lazy is off).

running pretrained models on CPU

Do the fp32 pre-trained models default to fp16 when run on CPU? Is the loss of precision when running on the CPU significant such that its not recommended?

Classifier Error

I trained a very simple language model:
python main.py --nhid 64 --save 'lang_model_64.pt'

Then I tried to classify:
python classifier.py --load_model 'lang_model_64.pt' --nhid 64

And this error happend:

RuntimeError: Error(s) in loading state_dict for stackedRNN: Missing key(s) in state_dict: "rnns.0.w_mhh_v", "rnns.0.w_hh_g", "rnns.0.w_hh_v", "rnns.0.w_mhh_g", "rnns.0.w_mih_v", "rnns.0.w_ih_g", "rnns.0.w_ih_v", "rnns.0.w_mih_g".
Unexpected key(s) in state_dict: "rnns.0.w_ih", "rnns.0.w_hh", "rnns.0.w_mih", "rnns.0.w_mhh".

Addressing Encoding Errors

We're working this week on addressing some pain points in our data pipeline.

One particular problem seems to be with the byte encoding of certain words/phrases causing crashes.

While we work to address this problem, it would be helpful if those who've been having issues with certain phrases, respond to this issue with sets of phrases that didn't work (or did work) for them.

Thanks

Heatmap for a given text

Is there a way to generate heatmap for a given text only. No text generation? I assume setting --gen_length to zero could do the job?

name 'cfg' is assigned to before global declaration

Hi,

thanks for providing an implementation of your work!

I would like to test the sentiment discovery on my own dataset, but unfortunately the following error message appears:

python3 text_reconstruction.py --help
  File "text_reconstruction.py", line 30
    global cfg
    ^
SyntaxError: name 'cfg' is assigned to before global declaration

It also appears when running the training command as documented in README.md. I'm using Python3. Please let me know if you need further information!

Thanks,

Stefan

pytorch 0.3 compatibility?

To what degree is the code backwards compatible with pytorch 0.3? I can't easily compile pytorch from source in my current environment, inside a prebuilt docker image.

It seems like if not using dynamic_loss_scale, I can at least train and get a lang_model.pt file with 0.3, is that right?

run_classifier.py: error: unrecognized arguments: --load_model

I'd like to classify my data with a pretrained model.
I followed the instructions on the readme page and tried to run one of these commands:
python3 run_classifier.py --load_model ama_sst.pt # classify Binary SST
python3 run_classifier.py --load_model ama_sst_16.pt --fp16 # run classification in fp16
python3 run_classifier.py --load_model ama_sst.pt --text-key --data <path.csv> # classify your own dataset
But it caused this error: run_classifier.py: error: unrecognized arguments: --load_model

apex error

Somehow it keeps getting errors when running the cmd from colab:

!python3 transfer.py --load_model imdb_clf.pt

It yields error of:
File "transfer.py", line 20, in <module> from apex.reparameterization import apply_weight_norm, remove_weight_norm File "/usr/local/lib/python3.6/dist-packages/apex/__init__.py", line 18, in <module> from apex.interfaces import (ApexImplementation, File "/usr/local/lib/python3.6/dist-packages/apex/interfaces.py", line 10, in <module> class ApexImplementation(object): File "/usr/local/lib/python3.6/dist-packages/apex/interfaces.py", line 14, in ApexImplementation implements(IApex) File "/usr/local/lib/python3.6/dist-packages/zope/interface/declarations.py", line 483, in implements raise TypeError(_ADVICE_ERROR % 'implementer') TypeError: Class advice impossible in Python3. Use the @implementer class decorator instead.

Training fails with multiple GPUs after the 1st epoch

If I fun with multiple, in my case 3 GPUs, with python3 -m multiproc main.py ...., I get the following error after successfully completing the 1st epoch:

Traceback (most recent call last):
File "main.py", line 392, in
val_loss, skipped_iters = train(total_iters, skipped_iters, elapsed_time)
File "main.py", line 305, in train
model.allreduce_params()
File "sentiment-discovery/model/distributed.py", line 41, in allreduce_params
dist.all_reduce(coalesced)
File "/home/tester/anaconda3/lib/python3.6/site-packages/torch/distributed/init.py", line 324, in all_reduce
return torch._C._dist_all_reduce(tensor, op, group)
RuntimeError: [/opt/conda/conda-bld/pytorch_1532579245307/work/third_party/gloo/gloo/transport/tcp/buffer.cc:76] Read timeout [127.0.0.1]:32444
terminate called after throwing an instance of 'gloo::EnforceNotMet'
what(): [enforce fail at /opt/conda/conda-bld/pytorch_1532579245307/work/third_party/gloo/gloo/cuda_private.h:40] error == cudaSuccess. 29 vs 0. Error at: /opt/conda/conda-bld/pytorch_1532579245307/work/third_party/gloo/gloo/cuda_private.h:40: driver shutting down

cannot import name '_unflatten_tensors'

Hi,

data_parallel.py" uses the following import from pytorch:

from torch._utils import _unflatten_tensors

This function was recently removed with this commit so it is not possibly to run the code with the latest PyTorch version.

IndexError during training of language model

Hi,

I wanted to train a language model from the Stanford Sentiment Treebank with this command:

(pyt) stefan@omega:/tmp/stefan_pytorch/sentiment-discovery> python text_reconstruction.py -experiment_dir ./experiments -experiment_name mlstm -model_dir model -cuda \
> -embed_size 64 -rnn_size 4096 -layers 1 -weight_norm -lstm_only -rnn_type mlstm -dropout 0 -persist_state 1 \
> -seq_length 256 -batch_size 32 -lr 0.000125 --optimizer_type=Adam -lr_scheduler LinearLR -epochs 1  \
> -train data/binary_sst/train.csv -valid data/binary_sst/val.csv -test data/binary_sst/test.csv \
> -data_set_type csv -lazy -text_key sentence

But then the following error message appears:

configuring system
configuring model
64
* number of parameters: 86319360
configuring devices
configuring data
configuring learning
entering training epoch 0
Exiting from training early
Traceback (most recent call last):
  File "text_reconstruction.py", line 238, in <module>
    main()
  File "text_reconstruction.py", line 164, in main
    raise ex
  File "text_reconstruction.py", line 139, in main
    inner_lr=cfg.inner_lr, saver=lambda ext, x: saver('e'+str(e)+ext, x))
  File "text_reconstruction.py", line 45, in run_epoch
    epoch_loop(model, data2use, data_fn, persist=is_training, inner_lr=inner_lr, skip_rule='no')):
  File "/tmp/stefan_pytorch/sentiment-discovery/sentiment_discovery/model/run.py", line 17, in epoch_loop
    for hidden, output in run_model(model, data_iter, data_fn):
  File "/tmp/stefan_pytorch/sentiment-discovery/sentiment_discovery/model/run.py", line 13, in run_model
    yield model(**data_dict)
  File "/tmp/stefan_pytorch/sentiment-discovery/sentiment_discovery/model/model_wrapper.py", line 207, in __call__
    _outputs = self._module(*module_input, **module_args)
  File "/tmp/stefan/anaconda3/envs/pyt/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in __call__
    result = self.forward(*input, **kwargs)
  File "/tmp/stefan_pytorch/sentiment-discovery/sentiment_discovery/model/sequence_model.py", line 200, in forward
    hidden_mask = state_mask[:,t].float().unsqueeze(1)
  File "/tmp/stefan/anaconda3/envs/pyt/lib/python3.6/site-packages/torch/autograd/variable.py", line 78, in __getitem__
    return Index.apply(self, key)
  File "/tmp/stefan/anaconda3/envs/pyt/lib/python3.6/site-packages/torch/autograd/_functions/tensor.py", line 89, in forward
    result = i.index(ctx.index)
IndexError: trying to index 2 dimensions of a 1 dimensional tensor

I thought it should also be possible to train a lm model with other (non Amazon) datasets? Thanks :)

Transfer learning fails and cannot be restarted

I have trained a model on my text corpus (full_model.pt) and want to see now how well it does with a labeled dataset. So I labeled the data and ran the following:

python transfer.py --load_model full_model.pt --data ./labeled.csv --neurons 30 --epochs 5 --split 10,1,1
configuring data
generating csv at ./labeled.sentence.label.csv
Creating mlstm
writing results to full_model_transfer/sentiment
transforming train
batch     1/  162 | ch/s 8.56E+03 | time 7.25E+02 | time left 1.17E+05
batch     2/  162 | ch/s 1.39E+04 | time 4.03E+02 | time left 9.02E+04
batch     3/  162 | ch/s 1.33E+04 | time 5.10E+02 | time left 8.68E+04
batch     4/  162 | ch/s 1.13E+04 | time 5.68E+02 | time left 8.71E+04
batch     5/  162 | ch/s 1.29E+04 | time 5.46E+02 | time left 8.64E+04
batch     6/  162 | ch/s 1.13E+04 | time 5.78E+02 | time left 8.66E+04
batch     7/  162 | ch/s 1.33E+04 | time 4.90E+02 | time left 8.46E+04
batch     8/  162 | ch/s 1.19E+04 | time 6.36E+02 | time left 8.58E+04
batch     9/  162 | ch/s 1.27E+04 | time 5.48E+02 | time left 8.51E+04
batch    10/  162 | ch/s 1.27E+04 | time 6.60E+02 | time left 8.61E+04
batch    11/  162 | ch/s 1.40E+04 | time 5.55E+02 | time left 8.54E+04
batch    12/  162 | ch/s 1.36E+04 | time 6.53E+02 | time left 8.59E+04
batch    13/  162 | ch/s 1.11E+04 | time 7.29E+02 | time left 8.71E+04
batch    14/  162 | ch/s 1.30E+04 | time 8.20E+02 | time left 8.90E+04
batch    15/  162 | ch/s 1.51E+04 | time 7.54E+02 | time left 8.99E+04
batch    16/  162 | ch/s 1.39E+04 | time 8.07E+02 | time left 9.11E+04
batch    17/  162 | ch/s 1.11E+04 | time 1.10E+03 | time left 9.45E+04
batch    18/  162 | ch/s 1.25E+04 | time 9.17E+02 | time left 9.60E+04
batch    19/  162 | ch/s 1.25E+04 | time 9.85E+02 | time left 9.77E+04
batch    20/  162 | ch/s 1.19E+04 | time 1.01E+03 | time left 9.94E+04
batch    21/  162 | ch/s 1.28E+04 | time 1.04E+03 | time left 1.01E+05
THCudaCheck FAIL file=/opt/conda/conda-bld/pytorch_1532579245307/work/aten/src/THC/generated/../THCReduceAll.cuh line=317 error=4 : unspecified launch failure
Traceback (most recent call last):
  File "transfer.py", line 328, in <module>
    trXt, trY = transform(model, train_data)
  File "transfer.py", line 138, in transform
    cell = model(text_batch, length_batch, args.get_hidden)
  File "/home/imsm/.conda/envs/jupyterlab/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/imsm/Documents/daniel_tmp/sentimentNvidia/sentiment-discovery-master/model/model.py", line 93, in forward
    cell = get_valid_outs(i, seq_len, cell, last_cell)
  File "/home/imsm/Documents/daniel_tmp/sentimentNvidia/sentiment-discovery-master/model/model.py", line 130, in get_valid_outs
    if (invalid_steps.long().sum() == 0):
RuntimeError: cuda runtime error (4) : unspecified launch failure at /opt/conda/conda-bld/pytorch_1532579245307/work/aten/src/THC/generated/../THCReduceAll.cuh:317

When I try to restart the training it fails immediately with error:

python transfer.py --load_model full_model.pt --data ./labeled.csv --neurons 30 --epochs 5 --split 10,1,1
configuring data
Creating mlstm
Traceback (most recent call last):
  File "transfer.py", line 89, in <module>
    sd = x = torch.load(f)
  File "/home/imsm/.conda/envs/jupyterlab/lib/python3.6/site-packages/torch/serialization.py", line 358, in load
    return _load(f, map_location, pickle_module)
  File "/home/imsm/.conda/envs/jupyterlab/lib/python3.6/site-packages/torch/serialization.py", line 542, in _load
    result = unpickler.load()
  File "/home/imsm/.conda/envs/jupyterlab/lib/python3.6/site-packages/torch/serialization.py", line 508, in persistent_load
    data_type(size), location)
  File "/home/imsm/.conda/envs/jupyterlab/lib/python3.6/site-packages/torch/serialization.py", line 104, in default_restore_location
    result = fn(storage, location)
  File "/home/imsm/.conda/envs/jupyterlab/lib/python3.6/site-packages/torch/serialization.py", line 75, in _cuda_deserialize
    raise RuntimeError('Attempting to deserialize object on a CUDA '
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location='cpu' to map your storages to the CPU.

Some more details:

torch.version.cuda
9.2.148'

python --version
Python 3.6.6

lspci | grep VGA 
04:00.0 VGA compatible controller: ASPEED Technology, Inc. ASPEED Graphics Family (rev 41)
17:00.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)
65:00.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)
b3:00.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)

nvidia-settings --version
nvidia-settings:  version 396.37  (buildmeister@swio-display-x86-rhel47-05)  Tue Jun 12 14:49:22 PDT 2018

uname -a
Linux imsm-gpu2 4.15.0-33-generic #36-Ubuntu SMP Wed Aug 15 16:00:05 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Any ideas?

Minimal prediction code

Not sure if this belongs here, but what are the minimal requirements needed to evaluate a pre-trained model, if I just need to extract text embeddings (to try out transfer learning tasks)?

AssertionError in sentiment_transfer

Hi,

I wanted to use the sentiment transfer script + load my pretrained lm model. But this fails:

python3 sentiment_transfer.py -experiment_dir ./experiments -experiment_name mlstm -model model -cuda -train data/binary_sst/unsup.csv -valid data/binary_sst/unsup.csv -test data/binary_sst/unsup.csv -text_key sentence -label_key label -load_model e1.pt
configuring system
configuring model
64
Traceback (most recent call last):
  File "sentiment_transfer.py", line 119, in <module>
    configure_usage('sentiment_transfer.py')
  File "/tmp/stefan_pytorch/sentiment-discovery/cfg/__init__.py", line 19, in configure_usage
    cfg.configure()
  File "/tmp/stefan_pytorch/sentiment-discovery/cfg/config.py", line 35, in configure
    self.model_config.apply(self, opt)
  File "/tmp/stefan_pytorch/sentiment-discovery/cfg/configure_model.py", line 32, in apply
    lstm_only=lstm_only, saved_path=saved_path)
  File "/tmp/stefan_pytorch/sentiment-discovery/sentiment_discovery/model/__init__.py", line 23, in make_model
    chkpt = restore(model, saved_path)
  File "/tmp/stefan_pytorch/sentiment-discovery/sentiment_discovery/model/serialize.py", line 35, in restore
    assert num_params == len(model.parameters())
AssertionError

With pytorch master, Parameter is a Tensor rather than a Variable

This breaks https://github.com/NVIDIA/sentiment-discovery/blob/master/model/distributed.py#L48 due to AttributeError: 'Parameter' object has no attribute '_execution_engine'

See the April 3rd commit here: https://github.com/pytorch/pytorch/commits/master/torch/nn/parameter.py

For now I will probably try to use the version of pytorch mentioned in the README. (I have a way to compile pytorch now if following my other issue ๐Ÿ‘ )

Multi GPU with transfer.py

This is more of a feature request I guess.
Is it possible to use multiple GPUs for the transfer code. It tried to implement this myself with

model = nn.DataParallel(model)

but that did not work because it needs to call model.module.rnn.

Traceback (most recent call last):
  File "transfer2.py", line 185, in <module>
    trXt, trY = transform(model, train_data)
  File "transfer2.py", line 143, in transform
    model.rnn.reset_hidden(batch_size)
  File "/home/imsm/.conda/envs/jupyterlab/lib/python3.6/site-packages/torch/nn/modules/module.py", line 518, in __getattr__
    type(self).__name__, name))
AttributeError: 'DataParallel' object has no attribute 'rnn'

But if I rename to

modelpar = nn.DataParallel(model)
model = modelpar.module

I'm back to a single GPU. Do I have to call model.module.rnn in every instance or does this not work at all?

Broken Pipe Error - main.py

When trying to run main.py I am getting a broken pipe error. I appreciate any help you can provide in overcoming this! Thank you in advance!


self.queue_manager = _ShardLoaderManager(self.batch_sampler, self.num_workers, self.collate_fn, self.pin_memory, self.timeout)

File "c:\Users\colby\OneDrive\Desktop\Startup\Code\Sentiment_Discovery Model\sentiment-discovery\data_utils\loaders.py", line 256, in init
w.start()
File "C:\ProgramData\Anaconda3\lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)
File "C:\ProgramData\Anaconda3\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\ProgramData\Anaconda3\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "C:\ProgramData\Anaconda3\lib\multiprocessing\popen_spawn_win32.py", line 89, in init
reduction.dump(process_obj, to_child)
File "C:\ProgramData\Anaconda3\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
BrokenPipeError: [Errno 32] Broken pipe

how do i use a pre-trained model on CPU?

I tried the following command.

python3 generate.py --model mLSTM --load_model mlstm.pt --neuron 2388 --visualize

Warning:  apex was installed without --cpp_ext.  Falling back to Python flatten and unflatten.
Warning:  apex was installed without --cuda_ext. Fused syncbn kernels will be unavailable.  Python fallbacks will be used instead.
Warning:  apex was installed without --cuda_ext.  FusedAdam will be unavailable.
Warning:  apex was installed without --cuda_ext.  FusedLayerNorm will be unavailable.
/home/debanjan/miniconda3/envs/dsenv/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
  return f(*args, **kwds)
/home/debanjan/miniconda3/envs/dsenv/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
  return f(*args, **kwds)
Traceback (most recent call last):
  File "generate.py", line 90, in <module>
    sd = torch.load(f)
  File "/home/debanjan/miniconda3/envs/dsenv/lib/python3.6/site-packages/torch/serialization.py", line 358, in load
    return _load(f, map_location, pickle_module)
  File "/home/debanjan/miniconda3/envs/dsenv/lib/python3.6/site-packages/torch/serialization.py", line 542, in _load
    result = unpickler.load()
  File "/home/debanjan/miniconda3/envs/dsenv/lib/python3.6/site-packages/torch/serialization.py", line 508, in persistent_load
    data_type(size), location)
  File "/home/debanjan/miniconda3/envs/dsenv/lib/python3.6/site-packages/torch/serialization.py", line 104, in default_restore_location
    result = fn(storage, location)
  File "/home/debanjan/miniconda3/envs/dsenv/lib/python3.6/site-packages/torch/serialization.py", line 75, in _cuda_deserialize
    raise RuntimeError('Attempting to deserialize object on a CUDA '
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location='cpu' to map your storages to the CPU.

I also tried using model.cpu() when torch.cuda.is_available() is False. I also tried using load with map_location='cpu' ... which led to inconsistencies in tensor/ndarray sizes.

PS: I didn't find a --cpu option in the docs. Others have discussed running a model on the CPU - but I didn't find anything else.
PPS: I am using pytorch-cpu version 0.4.1=py36_cpu_1 from the conda pytorch channel.

Dataloader error using Amazon data

I'm trying to train on Amazon data. However, after preprocessing and after the first iteration I get a dataloader error that 5 arguments expected and only 1 provided:

screenshot from 2018-05-26 17-42-12

I'm using torch 0.4.0 and a single GPU machine.

setup.py not finding libaten

Cloning into 'sentiment-discovery'...
Traceback (most recent call last):
  File "setup.py", line 71, in <module>
    libaten = find(torch_dir, re.compile("libaten", re.IGNORECASE).search, False)
  File "setup.py", line 31, in find
    return list(set(collection))
TypeError: 'NoneType' object is not iterable

I think it might have been a naming change in the newest version of torch. I changed re.compile("libaten", re.IGNORECASE) to re.compile("aten", re.IGNORECASE) and it seems to be working now.

What is BPC in the graphs in the readme?

Is it bits per character, is it therefore the base 2 log of ppl (perplexity per letter (?)) which is output by the training routine?

I'm hoping to clarify what all the numbers mean to make sure I am getting the expected results.

Input file format

Thank your for the awesome model. I would like to train it on a number of longer text documents and was wondering in what format I should pass the texts to the script. Can I just put them all in a single text file and pass that to main.py? Or would it be better to put them in a Json or csv file with one entry per file even though I do not have labels?
Sorry, I am kind of confused since the model is unsupervised but the datasets still have labels.

Real-time generation of heatmap for text

Hey, this is an awesome project.
In the sentiment analysis of the user-input text ,can we make it real-time instead of carriage return for better user experience? For example, user inputs text and its heat-map shows the sentiment simultaneously.

Running on specific gpu(s)

I want to train sentiment discovery on a new dataset using a DGX-1 machine shared machine. For this I can only use a limited set of GPUs. How can I specify to only run the process on GPUs 7 and 8 (6 - 7)?

Error ModuleNotFoundError: No module named 'torch.nn._functions.rnn'

Hi
I clone this project and run python3 setup.py install. everything is ok
but when I run the script
classifier.py --load_model lang_model_transfer/sentiment/sst_clf.pt --d ata data/icbu/icbu_negative_reviews.csv
I get this error:
Traceback (most recent call last): File "classifier.py", line 13, in <module> from apex.reparameterization import apply_weight_norm, remove_weight_norm File "/root/anaconda3/lib/python3.6/site-packages/apex-0.1-py3.6.egg/apex/__init__.py", line 1, in <module> File "/root/anaconda3/lib/python3.6/site-packages/apex-0.1-py3.6.egg/apex/RNN/__init__.py", line 1, in <module> File "/root/anaconda3/lib/python3.6/site-packages/apex-0.1-py3.6.egg/apex/RNN/models.py", line 3, in <module> ModuleNotFoundError: No module named 'torch.nn._functions.rnn'

Unicode Support

I wonder if your model can work on UTF8, and if yes, would you please give me some hints on parameters setting?

Getting: RuntimeError: CUDA error: out of memory

Hi
I met the error below when I tried to run the script
python classifier.py --load_model lang_model_transfer/sentiment/sst_clf.pt --data data/icbu/icbu_test_reviews.csv.
configuring data generating csv at data/icbu/icbu_test_reviews.sentence.label.csv Creating mlstm Traceback (most recent call last): File "classifier.py", line 53, in <module> model.cuda() File "/root/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 258, in cuda return self._apply(lambda t: t.cuda(device)) File "/root/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 185, in _apply module._apply(fn) File "/root/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 185, in _apply module._apply(fn) File "/root/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 185, in _apply module._apply(fn) File "/root/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 191, in _apply param.data = fn(param.data) File "/root/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 258, in <lambda> return self._apply(lambda t: t.cuda(device)) RuntimeError: CUDA error: out of memory

There are only two line of recode in file 'icbu_test_reviews.csv'
Below is the result of nvidia-smi:
$nvidia-smi
Mon Sep 10 20:42:29 2018
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 396.26 Driver Version: 396.26 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 Tesla M40 Off | 00000000:00:08.0 Off | Off |
| N/A 35C P0 61W / 250W | 11558MiB / 12215MiB | 16% Default |
+-------------------------------+----------------------+----------------------+
| 1 Tesla M40 Off | 00000000:00:09.0 Off | Off |
| N/A 32C P0 63W / 250W | 337MiB / 12215MiB | 0% Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 9815 C ...dmin/docker_ml/framework/bin/ml_service 3448MiB |
| 0 20415 C ...dmin/docker_ml/framework/bin/ml_service 7949MiB |
| 0 28935 C ...dmin/docker_ml/framework/bin/ml_service 148MiB |
| 1 9815 C ...dmin/docker_ml/framework/bin/ml_service 108MiB |
| 1 20415 C ...dmin/docker_ml/framework/bin/ml_service 108MiB |
| 1 28935 C ...dmin/docker_ml/framework/bin/ml_service 108MiB |
+-----------------------------------------------------------------------------+

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.