火把的预先训练模型
skipthoughts的Python项目详细描述
跳过思考.torch for pytorcb
skip-thinks.torch是skip-thought pretrained models from Theano到pytorch的轻量级移植。
安装
从PIP安装
pip install skipthoughts
从repo安装
git clone https://github.com/Cadene/skip-thoughts.torch.git
cd skip-thoughts.torch/pytorch
python setup.py install
可用的预训练模型
Uniskip
它使用torch的nn.GRU
层和cudnn后端。这是最快的实现,但在CUDNN实现中的每个时间步骤后都会采样丢失…(等于不正确的正则化)
dropuniskip
它使用torch的nn.GRUCell
层和cudnn后端。它比Uniskip稍慢,但是在序列中的所有时间步都会对丢失进行一次采样(良好的正则化)。
巴耶沙努尼斯基普
它使用一个带有火炬后端的自定义GRU层。它至少比uniskip慢两倍,但是对于每个线性(最佳正则化)的所有时间步,都对丢失进行一次采样。
比斯基普
等同于uniskip,但具有双序列gru。
快速示例
importtorchfromtorch.autogradimportVariableimportsyssys.path.append('skip-thoughts.torch/pytorch')fromskipthoughtsimportUniSkipdir_st='data/skip-thoughts'vocab=['robots','are','very','cool','<eos>','BiDiBu']uniskip=UniSkip(dir_st,vocab)input=Variable(torch.LongTensor([[1,2,3,4,0],# robots are very cool 0[6,2,3,4,5]# bidibu are very cool <eos>]))# <eos> token is optionalprint(input.size())# batch_size x seq_lenoutput_seq2vec=uniskip(input,lengths=[4,5])print(output_seq2vec.size())# batch_size x 2400output_seq2seq=uniskip(input)print(output_seq2seq.size())# batch_size x seq_len x 2400