没有
pytorch-fast-elmo的Python项目详细描述
Pythorch快速elmo
简介
一个具有以下功能的快速elmo实现:
- 更低的执行开销。核心组件在libtorch中重新实现,以减少python执行开销(45%加速)。
- {STR 1 }更灵活的设计。通过重新设计工作流,用户可以很容易地扩展或更改EMO行为。
基准
硬件:
- CPU:I7-7800X
- GPU:1080ti
选项:
- 批量:32
- 预热迭代:20
- 测试迭代次数:1000
- 字长:[1,20]
- 句子长度:[1,30]
- 随机种子:10000
Item | Mean Of Durations (ms) | cumtime(synchronize)% |
---|---|---|
Fast ELMo (CUDA, no synchronize) | 31 | N/A |
AllenNLP ELMo (CUDA, no synchronize) | 56 | N/A |
Fast ELMo (CUDA, synchronize) | 47 | 26.13% |
AllenNLP ELMo (CUDA, synchronize) | 57 | 0.02% |
Fast ELMo (CPU) | 1277 | N/A |
AllenNLP ELMo (CPU) | 1453 | N/A |
使用量
请先安装torch==1.0.0。然后,只需运行此命令进行安装。
pip install pytorch-fast-elmo
FastElmo的行为应该与allennlp的ELMo相同。
frompytorch_fast_elmoimportFastElmo,batch_to_char_idsoptions_file='/path/to/elmo_2x4096_512_2048cnn_2xhighway_options.json'weight_file='/path/to/elmo_2x4096_512_2048cnn_2xhighway_weights.hdf5'elmo=FastElmo(options_file,weight_file)sentences=[['First','sentence','.'],['Another','.']]character_ids=batch_to_ids(sentences)embeddings=elmo(character_ids)
如果已禁用bilm-tf中的char_cnn,或已将char cnn表示导出到权重文件,请使用FastElmoWordEmbedding。
frompytorch_fast_elmoimportFastElmoWordEmbedding,load_and_build_vocab2id,batch_to_word_idsoptions_file='/path/to/elmo_2x4096_512_2048cnn_2xhighway_options.json'weight_file='/path/to/elmo_2x4096_512_2048cnn_2xhighway_weights.hdf5'vocab_file='/path/to/vocab.txt'embedding_file='/path/to/cached_elmo_embedding.hdf5'elmo=FastElmoWordEmbedding(options_file,weight_file,# Could be omitted if the embedding weight is in `weight_file`.word_embedding_weight_file=embedding_file,)vocab2id=load_and_build_vocab2id(vocab_file)sentences=[['First','sentence','.'],['Another','.']]word_ids=batch_to_word_ids(sentences,vocab2id)embeddings=elmo(word_ids)
cli命令:
# Cache the Char CNN representation. fast-elmo cache-char-cnn ./vocab.txt ./options.json ./lm_weights.hdf5 ./lm_embd.hdf5 # Export word embedding. fast-elmo export-word-embd ./vocab.txt ./no-char-cnn.hdf5 ./embd.txt
学分
这个包是用Cookiecutter和audreyr/cookiecutter-pypackage项目模板创建的。
历史记录
0.1.0(2019-01-02)
- pypi上的第一个版本。