pytorch-seq2seq-example

授权协议 Readme
开发语言 Python
所属分类 神经网络/人工智能、 自然语言处理
软件类型 开源软件
地区 不详
投 递 者 端木冷勋
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Batched Seq2Seq ExampleBased on the seq2seq-translation-batched.ipynb from practical-pytorch, but more extra features.

This example runs grammatical error correction task where the source sequence is a grammatically erroneuous English sentence and the target sequence is an grammatically correct English sentence. The corpus and evaluation script can be download at: https://github.com/keisks/jfleg.

Extra features

  • Cleaner codebase
  • Very detailed comments for learners
  • Implement Pytorch native dataset and dataloader for batching
  • Correctly handle the hidden state from bidirectional encoder and past to the decoder as initial hidden state.
  • Fully batched attention mechanism computation (only implement general attention but it's sufficient). Note: The original code still uses for-loop to compute, which is very slow.
  • Support LSTM instead of only GRU
  • Shared embeddings (encoder's input embedding and decoder's input embedding)
  • Pretrained Glove embedding
  • Fixed embedding
  • Tie embeddings (decoder's input embedding and decoder's output embedding)
  • Tensorboard visualization
  • Load and save checkpoint
  • Replace unknown words by selecting the source token with the highest attention score. (Translation)

Cons

Comparing to the state-of-the-art seq2seq library, OpenNMT-py, there are some stuffs that aren't optimized in this codebase:

  • Use CuDNN when possible (always on encoder, on decoder when input_feed=0)
  • Always avoid indexing / loops and use torch primitives.
  • When possible, batch softmax operations across time. (this is the second complicated part of the code)
  • Batch inference and beam search for translation (this is the most complicated part of the code)

How to speed up RNN training?

Several ways to speed up RNN training:

  • Batching
  • Static padding
  • Dynamic padding
  • Bucketing
  • Truncated BPTT

See "Sequence Models and the RNN API (TensorFlow Dev Summit 2017)" for understanding those techniques.

You can use torchtext or OpenNMT's data iterator for speeding up the training. It can be 7x faster! (ex: 7 hours for an epoch -> 1 hour!)

Acknowledgement

Thanks to the author of OpenNMT-py @srush for answering the questions for me! See https://github.com/OpenNMT/OpenNMT-py/issues/552

  • pytorch入门(3)pytorch-seq2seq模型  https://github.com/IBM/pytorch-seq2seq/ 此模型不包含embedding,且最大长度为10 Get Started Prepare toy dataset # Run script to generate the reverse toy dataset # The generated data is

  • LIGHTNINGMODULE LightningModule将PyTorch代码整理成5个部分: Computations (init). Train loop (training_step) Validation loop (validation_step) Test loop (test_step) Optimizers (configure_optimizers) Minimal Exam

  • 以下是对pytorch 1.0版本 的seq2seq+注意力模型做法语--英语翻译的理解(这个代码在pytorch0.4上也可以正常跑): 1 # -*- coding: utf-8 -*- 2 """ 3 Translation with a Sequence to Sequence Network and Attention 4 ************************

  • 之前在学习深度学习的时候,一直这个包困扰着我,看了看网上的资源,找了找,给大家分享一下。如果有需要的请拿走,不谢。 import collections import math import os import random import sys import tarfile import time import zipfile from tqdm import tqdm from IPytho

  • 构造词典,要把输入的字符串转换id,首先把字符和id的映射定义好字典 WORD_DICT_URL = "https://paddlenlp.bj.bcebos.com/data/dict.txt" # Loads vocab. vocab_path = "./dict.txt" if not os.path.exists(vocab_path): # d

  • 循环神经网络的从零开始实现 首先,我们读取周杰伦专辑歌词数据集: import time import math import numpy as np import torch from torch import nn, optim import torch.nn.functional as F import sys sys.path.append("..") device = torch.d

 相关资料
  • seq2seq 是 Google 开源的一款用于 TensorFlow 的通用编码器&解码器框架(encoder-decoder framework),可用于机器翻译、文本摘要、会话建模、图像描述等。 设计目标/特性 通用性:Google 最初为机器翻译开发了这个框架,但是后来用于各种其他任务,包括摘要、会话建模和图像描述。只要你的问题可以以一种格式编码输入数据,并解码为另一种格式,你应该能够使用

  • 这是一个使用 seq2seq 模型对联(对对联)的项目,是用 Tensorflow 写的。要求: Tensorflow Python 3.6 Dataset 打开 couplet.py,配置文件位置和超参数。然后运行python couplet.py来训练这个模型。你可以在 Tensorbloard 看到 training loss 和 bleu score。当你发现 loss 停止下降时,你可能

  • 我试图在Pytorch中实现seq2seq模型,我对批处理有一些问题。例如,我有一批数据,其尺寸是 [batch_sizesequence_lengthsencoding_dimension] 其中,批次中每个示例的序列长度不同。 现在,我通过将批处理中的每个元素填充到最长序列的长度来完成编码部分。 通过这种方式,如果我向我的网络输入一个与上述形状相同的批次,我会得到以下输出: 输出,形状 隐藏状

  • 本文向大家介绍什么是seq2seq model相关面试题,主要包含被问及什么是seq2seq model时的应答技巧和注意事项,需要的朋友参考一下 参考回答: Seq2seq属于encoder-decoder结构的一种,利用两个RNN,一个作为encoder一个作为decoder。Encoder负责将输入序列压缩成指定长度的向量,这个向量可以看作这段序列的语义,而decoder负责根据语义向量生成

  • PyTorch 是一个 Torch7 团队开源的 Python 优先的深度学习框架,提供两个高级功能: 强大的 GPU 加速 Tensor 计算(类似 numpy) 构建基于 tape 的自动升级系统上的深度神经网络 你可以重用你喜欢的 python 包,如 numpy、scipy 和 Cython ,在需要时扩展 PyTorch。 在粒度级别上,PyTorch 是一个由以下组件组成的库: 通常使

  • 我们已经在前两节中表征并变换了不定长的输入序列。但在自然语言处理的很多应用中,输入和输出都可以是不定长序列。以机器翻译为例,输入可以是一段不定长的英语文本序列,输出可以是一段不定长的法语文本序列,例如 英语输入:“They”、“are”、“watching”、“.” 法语输出:“Ils”、“regardent”、“.” 当输入和输出都是不定长序列时,我们可以使用编码器—解码器(encoder-de