没有

pytorch-fast-elmo的Python项目详细描述


Pythorch快速elmo

https://img.shields.io/pypi/v/pytorch_fast_elmo.svghttps://img.shields.io/travis/cnt-dev/pytorch-fast-elmo.svghttps://img.shields.io/badge/License-MIT-yellow.svg

简介

一个具有以下功能的快速elmo实现:

  • 更低的执行开销。核心组件在libtorch中重新实现,以减少python执行开销(45%加速)。
  • {STR 1 }更灵活的设计。通过重新设计工作流,用户可以很容易地扩展或更改EMO行为。

基准

硬件:

  • CPU:I7-7800X
  • GPU:1080ti

选项:

  • 批量:32
  • 预热迭代:20
  • 测试迭代次数:1000
  • 字长:[1,20]
  • 句子长度:[1,30]
  • 随机种子:10000
ItemMean Of Durations (ms)cumtime(synchronize)%
Fast ELMo (CUDA, no synchronize)31N/A
AllenNLP ELMo (CUDA, no synchronize)56N/A
Fast ELMo (CUDA, synchronize)4726.13%
AllenNLP ELMo (CUDA, synchronize)570.02%
Fast ELMo (CPU)1277N/A
AllenNLP ELMo (CPU)1453N/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

学分

这个包是用Cookiecutteraudreyr/cookiecutter-pypackage项目模板创建的。

历史记录

0.1.0(2019-01-02)

  • pypi上的第一个版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Eclipse内存分析器(MAT):不显示当前正在运行的进程   java Apache Velocity:转义字符不能作为关联数组键用于PHP   不截断零的java格式十进制输出   在另一个类文件中调用时返回空值的java getter   java集合获取连接   java解析json使用Gson登录系统应用程序强制关闭   java DelferredResult带有两个请求的ajax请求   java可降低功耗,同时应使用无线   java BoxLayout无法共享错误?   java如何使用计时器制作闹钟   java使用OAuth2保护RESTWeb服务:一般原则   java在一个jframe上显示多个图像和按钮