Lecture 17 Machine Translation

目录

      • Statistical MT
      • Neural MT
      • Attention Mechanism
      • Evaluation
      • Conclusion

Machine translation (MT) is the task of translating text from one source language to another target language 在这里插入图片描述

  • why?
    • Removes language barrier
    • Makes information in any languages accessible to anyone
    • But translation is a classic “AI-hard” challenge
    • Difficult to preserve the meaning and the fluency of the text after translation
  • MT is difficult
    • Not just simple word for word translation
    • Structural changes, e.g., syntax and semantics
    • Multiple word translations, idioms(习语,成语,方言)
    • Inflections for gender, case etc
    • Missing information (e.g., determiners) 在这里插入图片描述

Statistical MT

  • earliy MT
    • Started in early 1950s
    • Motivated by the Cold War to translate Russian to English
    • Rule-based system
      • Use bilingual dictionary to map Russian words to English words
    • Goal: translate 1-2 million words an hour within 5 years
  • statistical MT
    • Given French sentence f, aim is to find the best English sentence e

      • a r g m a x e P ( e ∣ f ) argmax_eP(e|f) argmaxeP(ef)
    • Use Baye’s rule to decompose into two components

      • a r g m a x e P ( f ∣ e ) P ( e ) argmax_e\color{blue}{P(f|e)}\color{red}{P(e)} argmaxeP(fe)P(e)
    • language vs translation model

      • a r g m a x e P ( f ∣ e ) P ( e ) argmax_e\color{blue}{P(f|e)}\color{red}{P(e)} argmaxeP(fe)P(e)
      • P ( e ) \color{red}{P(e)} P(e): language model
        • learn how to write fluent English text
      • P ( f ∣ e ) \color{blue}{P(f|e)} P(fe): translation model
        • learns how to translate words and phrases from English to French
    • how to learn LM and TM

      • Language model:
        • Text statistics in large monolingual(仅一种语言的) corpora (n-gram models)
      • Translation model:
        • Word co-occurrences in parallel corpora
        • i.e. English-French sentence pairs
    • parallel corpora

      • One text in multiple languages
      • Produced by human translation
        • Bible, news articles, legal transcripts, literature, subtitles
        • Open parallel corpus: http://opus.nlpl.eu/
    • models of translation

      • how to learn P ( f ∣ e ) P(f|e) P(fe) from paralell text?
      • We only have sentence pairs; words are not aligned in the parallel text
      • I.e. we don’t have word to word translation 在这里插入图片描述
    • alignment

      • Idea: introduce word alignment as a latent variable into the model

        • P ( f , a ∣ e ) P(f,a|e) P(f,ae)
      • Use algorithms such as expectation maximisation (EM) to learn (e.g. GIZA++) 在这里插入图片描述

      • complexity

        • some words are dropped and have no alignment 在这里插入图片描述

        • One-to-many alignment 在这里插入图片描述

        • many-to-one alignment 在这里插入图片描述

        • many-to-many alignment 在这里插入图片描述

    • summary

      • A very popular field of research in NLP prior to 2010s
      • Lots of feature engineering
      • State-of-the-art systems are very complex
        • Difficult to maintain
        • Significant effort needed for new language pairs

Neural MT

  • introduction

    • Neural machine translation is a new approach to do machine translation
    • Use a single neural model to directly translate from source to target
    • from model perspective, a lot simpler
    • from achitecture perspective, easier to maintain
    • Requires parallel text
    • Architecture: encoder-decoder model
      • 1st RNN to encode the source sentence
      • 2nd RNN to decode the target sentence 在这里插入图片描述
  • neural MT

    • The decoder RNN can be interpreted as a conditional language model

      • Language model: predicts the next word given previous words in target sentence y
      • Conditional: prediction is also conditioned on the source sentence x
    • P ( y ∣ x ) = P ( y 1 ∣ x ) P ( y 2 ∣ y 1 , x ) . . . P ( y t ∣ y 1 , . . . , y t − 1 , x ) P(y|x)=P(y_1|x)P(y_2|y_1,x)...P(y_t|\color{blue}{y_1,...,y_{t-1}},\color{red}{x}) P(yx)=P(y1x)P(y2y1,x)...P(yty1,...,yt1,x)

    • training

      • Requires parallel corpus just like statistical MT

      • Trains with next word prediction, just like a language model

      • loss 在这里插入图片描述

        • During training, we have the target sentence
        • We can therefore feed the right word from target sentence, one step at a time
    • decoding at test time 在这里插入图片描述

      • But at test time, we don’t have the target sentence (that’s what we’re trying to predict!)

      • argmax: take the word with the highest probability at every step

      • exposure bias

        • Describes the discrepancy(差异) between training and testing
        • Training: always have the ground truth tokens at each step
        • Test: uses its own prediction at each step
        • Outcome: model is unable to recover from its own error(error propagation) 在这里插入图片描述
      • greedy decoding

        • argmax decoding is also called greedy decoding
        • Issue: does not guarantee optimal probability P ( y ∣ x ) P(y|x) P(yx)
      • exhaustive search decoding

        • To find optimal P ( y ∣ x ) P(y|x) P(yx), we need to consider every word at every step to compute the probability of all possible sequences
        • O ( V n ) O(V^n) O(Vn) where V = vocab size; n = sentence length
        • Far too expensive to be feasible
      • beam search decoding

        • Instead of considering all possible words at every step, consider k best words
        • That is, we keep track of the top-k words that produce the best partial translations (hypotheses) thus far
        • k = beam width (typically 5 to 10)
        • k = 1 = greedy decoding
        • k = V = exhaustive search decoding
        • example: 在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述
      • when to stop

        • When decoding, we stop when we generate token
        • But multiple hypotheses may terminate their sentence at different time steps
        • We store hypotheses that have terminated, and continue explore those that haven’t
        • Typically we also set a maximum sentence length that can be generated (e.g. 50 words)
    • issues of NMT

      • Information of the whole source sentence is represented by a single vector
      • NMT can generate new details not in source sentence
      • NMT tend to generate not very fluent sentences ( × \times ×, usually fluent, a strength)
      • Black-box model; difficult to explain when it doesn’t work
    • summary

      • Single end-to-end model
        • Statistical MT systems have multiple subcomponents
        • Less feature engineering
        • Can produce new details that are not in the source sentence (hallucination:错觉,幻觉)

Attention Mechanism

在这里插入图片描述

  • With a long source sentence, the encoded vector is unlikely to capture all the information in the sentence
  • This creates an information bottleneck(cannot capture all information in a long sentence in a single short vector)
  • attention
    • For the decoder, at every time step allow it to ‘attend’ to words in the source sentence 在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述

    • encoder-decoder with attention 在这里插入图片描述

    • variants

      • attention
        • dot product: s t T h i s_t^Th_i stThi
        • bilinear: s t T W h i s_t^TWh_i stTWhi
        • additive: v^Ttanh(W_ss_t+W_hh_i)
      • c t c_t ct can be injected to the current state ( s t s_t st), or to the input word ( y t y_t yt)
    • summary

      • Solves the information bottleneck issue by allowing decoder to have access to the source sentence words directly(reduce hallucination a bit, direct access to source words, less likely to generate new words not related to source sentence)
      • Provides some form of interpretability (look at attention distribution to see what source word is attended to)
        • Attention weights can be seen as word alignments
      • Most state-of-the-art NMT systems use attention
        • Google Translate (https://slator.com/technology/google-facebook-amazonneural-machine-translation-just-had-its-busiest-month-ever/)

Evaluation

  • MT evaluation
    • BLEU: compute n-gram overlap between “reference” translation(ground truth) and generated translation
    • Typically computed for 1 to 4-gram
      • B L E U = B P × e x p ( 1 N ∑ n N l o g p n ) BLEU=BP\times exp(\frac{1}{N}\sum_n^Nlogp_n) BLEU=BP×exp(N1nNlogpn), where BP → \to “Brevity Penalty” to penalise short outputs
      • p n = #   c o r r e c t   n − g r a m s #   p r e d i c t e d   n − g r a m s p_n=\frac{\# \ correct \ n-grams}{\# \ predicted \ n-grams} pn=# predicted ngrams# correct ngrams
      • B P = m i n ( 1 , o u t p u t   l e n g t h r e f e r e n c e   l e n g t h ) BP=min(1,\frac{output \ length}{reference \ length}) BP=min(1,reference lengthoutput length)

Conclusion

  • Statistical MT
  • Neural MT
    • Nowadays use Transformers rather than RNNs
  • Encoder-decoder with attention architecture is a general architecture that can be used for other tasks
    • Summarisation (lecture 21)
    • Other generation tasks such as dialogue generation

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/27228.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

chatgpt赋能python:Python如何从右往左取数

Python如何从右往左取数 在Python编程中,有时候需要从右往左获取列表、字符串等数据结构的元素,而不是从左往右。这样做的好处在于可以更快地访问最后几个元素,或者进行一些反向操作。本文将介绍Python中从右往左取数的方法。 索引与切片 …

JDBC Utils 详解(通俗易懂)

目录 一、前言 二、JDBCUtils说明 1.背景及起因 : 2.示意图 : 3.JDBCUtils类的定义 三、JDBCUtils应用 1.DML的应用 : 2.DQL的应用 : 四、总结 一、前言 第三节内容,up主要和大家分享一下JDBC Utils方面的内容。注意事项——①代码中的注释也很重要&#x…

性能测试loadrunner

目录 基本概念 性能工具jemeter代码调试 loadrunner实战代码笔记 使用Loadrunner的步骤 性能指标分析结果 基本概念 一、什么是性能: 性能:是用来描述产品除功能外的所具有的速度,效率和能力的综合能力评价。 二、什么是性能测试&…

leetcode61. 旋转链表(java)

旋转链表 leetcode61. 旋转链表题目描述 解题思路代码演示链表专题 leetcode61. 旋转链表 Leetcode链接: https://leetcode.cn/problems/rotate-list/ 题目描述 给你一个链表的头节点 head ,旋转链表,将链表每个节点向右移动 k 个位置。 示例…

基于graalvm和java swing制作一个文件差异对比的原生应用,附源码

文章目录 1、DFDiff介绍2、软件架构3、安装教程3.1、编译为jar包运行3.2、编译为原生应用运行 4、运行效果图5、项目源码地址 1、DFDiff介绍 当前已实现的功能比较两个文件夹内的文件差异,已支持文件差异对比。 2、软件架构 软件架构说明 开发环境是在OpenJDK17&…

数据结构与算法之链表

目录 单链表概念单链表操作循环链表概念循环链表操作双向循环链表概念双向循环链表操作单链表 概念 单链表也叫单向链表,是链表中最简单的一种形式,它的每个节点包含两个域,一个信息域(元素域)和一个链接域。这个链接指向链表中的下一个节点,而最后一个节点的链接域则指…

K-verse 合作伙伴访谈|与 Studio Dragon 一起进入韩剧元宇宙世界

穿越时空的韩剧元宇宙。 Studio Dragon 是全球排名第一的生活创作者 CJ ENM 的子公司,是引领韩剧的韩国代表性戏剧工作室,一个以无限故事内容让世界着迷的优质故事讲述者。 通过与 The Sandbox 的合作,我们将提供一种全新体验,让用…

C++——类型转换

目录 C语言中的类型转换 为什么C需要四种类型转换 1、static_cast 2、reinterpret_cast 3、const_cast 4、dynamic_cast 关于const的典型例题 分析下列结果的原因 原因 C语言中的类型转换 //类型转换int main() {int i 1;// 隐式类型转换double d i;printf("%d,…

Docker是什么、有什么用的介绍

文章目录 1.背景2. Docker 是什么?3.Docker 容器与虚拟机的区别4.Docker 的 6 大优势1、更高效地利用系统资源2、更快的启动时间3、一致的运行环境4、持续交付和部署5、更轻松迁移6、更轻松的维护和拓展 小结 知识搬运工: 原文出自: 原文链接…

一键生成代码

天行健,君子以自强不息;地势坤,君子以厚德载物。 每个人都有惰性,但不断学习是好好生活的根本,共勉! 文章均为学习整理笔记,分享记录为主,如有错误请指正,共同学习进步。…

C++/C按照时间命名保存bin文件

背景 在Linux应用编程过程中,使用C或者C语言保存、读取bin文件是比较常见的需求。这里详细记录一下使用C保存bin文件,也可以使用C语言实现。 代码 C/C语言保存bin文件函数,C中也能使用 正确写入返回0,错误返回-1 // C 保存bi…

ASP.NET Core Web API入门:创建新项目

ASP.NET Core Web API入门:创建新项目 一、引言二、创建新项目三、加入Startup类,并替换Program.cs内容四、编辑Program.cs代码五、修改控制器的路由六、运行项目 一、引言 最近闲着,想着没真正从0-1开发过ASP.NET Core Web API的项目&#…

找不到xinput1_3.dll怎么办?xinput1_3.dll丢失的四个修复方法

在我们打开游戏的或者软件的时候,电脑提示“找不到xinput1_3.dll,无法继续执行此代码”怎么办?相信困扰着不少小伙伴,我再在打开吃鸡的时候,然后花了一上午的时候时间研究,现在终于知道xinput1_3.dll文件是…

中国电子学会2023年05月份青少年软件编程Scratch图形化等级考试试卷三级真题(含答案)

2023-05 Scratch三级真题 分数:100 题数:38 测试时长:60min 一、单选题(共25题,共50分) 1. 关于变量,下列描述错误的是?(A )(2分) A.只能建一个变量 …

Visual Studio 2022 v17.6 正式发布

Visual Studio 17.6 正式发布,这个最新版本提供了一系列强大的工具和功能,旨在使你能够制作出最先进的应用程序。 提高生产力 通过 Visual Studio 2022,目标是帮助你在更短的时间内完成 IDE 内的所有开发任务,在这个版本中&…

OpenPCDet安装、使用方式及自定义数据集训练

OpenPCDet安装、使用方式及自定义数据集训练 个人博客 OpenPCDet安装 # 先根据自己的cuda版本,安装对应的spconv pip install spconv-cu113# 下载OpenPCDet并安装 git clone https://github.com/open-mmlab/OpenPCDet.git cd OpenPCDet pip install -r requireme…

Linux 负载均衡集群 LVS_NAT模式 LVS_DR模式

集群 由多台主机组成,只做一件事,对外表现为一个整体。 只干一件事 :集群 干不同的事:分布式 企业集群分类 负载均衡群集(load balance cluster) 提高系统响应效率,处理更多的访问请…

深度学习的低秩优化:在紧凑架构和快速训练之间取得平衡(上)

论文出处:[2303.13635] Low Rank Optimization for Efficient Deep Learning: Making A Balance between Compact Architecture and Fast Training (arxiv.org) 由于篇幅有限,本篇博客仅引出问题的背景、各种张量分解方法及其分解FC/Conv层的方法&#x…

车牌识别之UI(Tkinter + OpenCV显示Picture和Video)

画一张总图: 图形界面开发 本篇只介绍图形界面开发。 遇到的第一个问题就是选择什么开发语言和技术。因为我之前用Python做过Tkinter的小东西,所以这次还是用Python Tkinter OpenCV来搞吧。 这里面需要注意几个地方: 1. Tkinter 的布局 …

冒泡排序、插入排序、希尔排序、选择排序

一、排序协议的定义 在博客的开头的,我们先给出排序协议的定义。因为我们本篇博客含有多种排序方式,为了使每种排序方法对外调用方式一致,我们需要定义一个排序的相关协议。所有排序的相关类都必须遵循该协议,让此协议来定义具体…
最新文章