Generating News Headlines with Recurrent Neural Networks

Generating News Headlines with Recurrent Neural Networks


背景知识

seq2seq 的模型一般都是如下的结构 :
这里写图片描述

encoder 部分用单层或者多层 神经网络 将输入进行编码,decoder 部分是一个语言模型。这种生成式的问题都可以归结为求解一个条件概率问题 p(word|context),在 context 条件下,将词表中每一个词的概率值都算出来,用概率最大的那个词作为生成的词,依次生成摘要中的所有词。这里的关键在于如何表示 context,每种模型最大的不同点都在于 context 的不同,这里的 context 可能只是 encoder 的表示,也可能是 attention 和 encoder 的表示。decoder 部分通常采用 beam search 算法来做生成。
所以我们关注的问题是:
- 如何表达context?
- p(word|context)怎么求?


文本摘要 (Abstractive Sentence Summarization)

这里探讨的是用 abstractive 的方式来解决 sentence-level 的文本摘要问题,问题的定义比较简单,输入是一个长度为 M 的文本序列,输出是一个长度为 N 的文本序列,这里 M>>N,并且输出文本的意思和输入文本的意思基本一致,输入输出都可能是一句话,也可能是多句话。并且,输入输出拥有相同的词汇表。

Generating News Headlines with Recurrent Neural Networks

概要

这篇论文有三个发现:
1. 一个encoder-decoder recurrent neural network with LSTM units 和 attention框架去生成一个文本的摘要,可以取得较好的效果。
2. 神经网络如何决定哪些输入数据应该被关注。
3. simplified attention mechanism中不同神经元的功能,并且观察到,simplified attention mechanism比the more complex attention mechanism有更好的表现。

模型

decoder在输出每个word的时候,使用attention mechanism。对于每个输出的词,attention mechanism都计算出每个输入words的权值,权值累加和为1。在处理完每个输入words后,计算最后一层隐藏层生成的加权平均值,将这个值作为context和当前最后一层隐藏层一起输入到softmax layer。
论文里提出两种attention mechanism:
第一种: complex attention
模型中的 attention weights 是用 encoder 中每个词最后一层 hidden layer 的表示与当前 decoder 最新一个词最后一层 hidden layer 的表示做点乘,然后归一化来表示的。
具体公式:

  1. 当输出 t 个word的时候,怎么计算输入words在t位置的attention weight:
    ayt(t)=exp(hTxthyt)Ttexp(hTxthyt)

    hxt 表示处理第t个输入word后,最后一层隐藏层生成
    hyt 表示当前decoding的最后一层隐藏层生成
  2. softmax function:
    oyt=Wcocyt+Whohyt+bo

    cyt 是当前decodering步骤下的context
    hyt 是当前decodering步骤下的最后一层隐藏层生成
    Wco,Whobo 是模型的参数

具体过程:

  1. 输入word为[x1,x2,x3,…,xT],其隐藏层最后一层为[h1,h2,h3,…,hT];
  2. 输出word为[y1,y2,y3,…,yT], 其隐藏层最后一层为[o1,o2,o3,…,oT];
  3. 通过上面的公式,计算每个输出word对应的attention weight为[a1,a2,a3,…,aT];
  4. 计算每个输出word对应的context=a1h1+a2h2+a3h3+…+aThT;
  5. 算出输出第i个word对应的context和oi一起输入softmax layer算出对应的第i个word.

具体图示:

这里写图片描述

第二种:Simple attention
这个模型将最后一层 hidden layer 细分了不同的作用。将 encoder和decoder 部分在每个词最后一层 hidden layer 的表示分为两块,一小块用来计算 attention weights 的,另一大块用来作为 encoder 的表示。计算attention weights的公式做相应的改变,计算context的公式不变。
具体图示:

这里写图片描述


注:这里只是对论文模型的理解,不包括其他内容。有兴趣,可以自行阅读原文。

### Instant Neural Graphics Primitives with Multiresolution Hash Encoding Multiresolution hash encoding is a technique that allows the representation of high-frequency details in neural fields, such as images or volumes, while maintaining efficiency during training and inference. This method divides space into multiple resolutions using an octree structure to efficiently store information at different levels of detail[^1]. The core idea behind instant neural graphics primitives (INGP) lies in combining multiresolution grid-based feature vectors encoded through hashing techniques. By mapping spatial coordinates into discrete indices within grids, this approach can capture intricate patterns without requiring excessive memory resources. The use of hash tables enables fast lookups when accessing these features. For implementing INGP: - **Octree Construction**: An adaptive octree is constructed based on scene complexity; finer divisions occur where more detail exists. - **Feature Vectors Storage**: Each node contains low-dimensional learnable parameters representing local geometry properties. - **Hash Function Application**: Spatial positions are transformed via modulo operations followed by random projections onto higher dimensions before being fed into networks for learning purposes. This combination results in models capable of generating highly detailed outputs from compact representations learned directly from data samples provided during training phases. ```python import torch.nn.functional as F def get_grid_coordinates(xyz, level): """Convert continuous xyz coordinates to integer grid cell ids.""" scale = 2**(level - 1) coords = ((xyz + 1.) * scale).long() return coords % (scale*2) def apply_hashing(coords, table_size=1<<20): """Apply simple modular arithmetic hashing function""" hashed_coords = [] primes = [1, 2654435761, 805459861] for i in range(3): h = int((coords[:,i]*primes[i])%table_size) hashed_coords.append(h) return torch.stack(hashed_coords,dim=-1) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值