Transformer与OCR

由于OCR是序列到序列,NMT或者通用的任务Transformer也是Sequence 2 Sequence。而OCR识别经典论文是CRNN,其中是CNN+RNN+softmax,这个RNN可以试试LSTM,GRU,或者其他变种。也可以是机器翻译的端到端的序列识别。
本文试图分析Transformer与OCR任务,试图将Transformer替换CRNN中的LSTM

N-Grams

N-grams refer to the process of combining the nearby words together for representation purposes where N represents the number of words to be combined together.

  • For eg, consider a sentence, “Natural Language Processing is essential to Computer Science.”
  • A 1-gram or unigram model will tokenize the sentence into one word combinations and thus the output will be “Natural, Language, Processing, is, essential, to, Computer, Science”
  • A bigram model on the other hand will tokenize it into combination of 2 words each and the output will be “Natural Language, Language Processing, Processing is, is essential, essential to, to Computer, Computer Science”
  • Similarly, a trigram model will break it into “Natural Language Processing, Language Processing is, Processing is essential, is essential to, essential to Computer, to Computer Science” , and a n-gram model will thus tokenize a sentence into combination of n words together.

1、LSTM与Transformer

  • Transformer实际上是google的论文『attention is all you need』首先提出来的。
  • LSTM是T时刻输出依赖T时刻输入与T-1时刻的状态,必须串行计算,因此输出效率慢,同时LSTM实际上还是不能解决长期依赖问题。(李宏毅-LSTM本质上还是短依赖)。Transformer试图解决长期依赖问题,同时可以并行计算输出。
  • 主要引入attention机制。

下面本文详细介绍attention机制。到底干了什么,导致这么厉害。

2、attention

直观感受

3、

  • attention是具有可学参数的前馈神经网络层,他可以帮助我们捕捉输入序列之间各个元素之间的关系。注意力机制有多重形式,可以是soft也是可以是hard。对于图像而言,soft是整个image对于attention都是available的,而hard 是一个patch对于attention是available的。
    Transformer与OCR_第1张图片
  • 当人到一个新的场景下,看到一幅image,人眼会首先attention一个部分,然后,试图理解这部分,以这部分为基础,然后去寻找下一个需要或者感兴趣attention的位置,然后一直往复,直到看完整个图,理解整个图。
  • 如何寻找下一个感兴趣location,是CNN到sequence的识别任务。这部分任务做好了,OCR的多角度识别或者混排也就自然解决了。
  • google使用强化学习,找到下一个需要attention的location。Recurrent Models of Visual Attention

Ref

[1] https://towardsdatascience.com/natural-language-processing-from-basics-to-using-rnn-and-lstm-ef6779e4ae66

你可能感兴趣的:(pytorch,Algorithm)