【论文阅读笔记】Cross-lingual Language Model Pretraining

Facebook推出的XLM模型在跨语言预训练领域取得重大突破,实验显示在XNLI、无监督及有监督机器翻译任务上超越现有最佳水平。XLM包含MLM、CLM和TLM三种模型,通过跨语言单词嵌入预训练,显著提升了无监督机器翻译性能。

本文是FaceBook AI Team在2019年一月发布的文章。

       近一年来,NLP领域发展势头强劲,从ELMO到LSTM再到去年最牛叉的Google Bert,在今年年初,Facebook又推出了XLM模型,在跨语言预训练领域表现抢眼。实验结果显示XML在XNLI任务上比原来的state-of-the-art直接高了4.9个百分点;在无监督机器翻译WMT’16 German-English中,比原来的state-of-the-art高了9个BLEU;在有监督的机器翻译WMT’16 Romanian-English中,比原来的state-of-the-art高了4个BLEU。

【摘要】

        最近的研究已经证明了生成预训练对于英语自然语言理解的有效性。在这项工作中,我们将这种方法扩展到多种语言并展示跨语言预训练的有效性。我们提出了两种学习跨语言语言模型(XLM)的方法:一种是无监督方式,只依赖于单语言数据,另一种是监督,利用新的跨语言语言模型目标来利用并行数据。我们获得了关于跨语言分类,非监督和监督机器翻译的最新结果。

【跨语言模型】

文中第三部分主要解释三个模型MLM,CLM和TLM

1.Shared sub-word vocabulary

      以前的研究表明,对于共享相同的字母、数字符号的语言,使用Byte Pair Encoding (BPE)能够显著的提升嵌入空间的对齐效果。本文学习在单语料库中从随机多项式分布中采样句子进行BPE学习。

2.Causal Language Modeling (CLM)

      使用Transformer在给定前序词语的情况下预测下一个词的概率。

3.Masked Language Modeling (MLM)

     本文的方法与Devlin等人的MLM之间的差异在于使用任意数量的句子(截断为256个token)而不是使用句子对。对比较频繁的输出采用与频率倒数的平方根成正比的权重从多项式分布中进行子采样。

4.Translation Language Modeling (TLM)

      本文的TLM是对MLM的扩展,直接连接平行的句子而不是只考虑单语言的文本流。在源句子和目标句子中随机掩盖一部分词语。这样为了预测在英语句子中掩盖的单词,该模型可以倾向于周围的英语单词或法语翻译,鼓励模型对齐英语和法语表示。也就是说,如果英语单词不足以推断出蒙面的英语单词,那么该模型可以利用法语语境(个人认为这点比较有想法)。为了便于对齐,还重置了目标句子的位置。本文提出的TLM如下,结合了BERT和MLM:

【跨语言模型预训练】

这是文中第四部分,主要阐述一下内容:

  1. 用于初始化查找表的预训练的跨语言单词嵌入的质量对无监督机器翻译模型的性能有显著影响。本文采用跨语言模型对整个无监督翻译的编码和解码器进行完整的预训练。
  2. 监督机器翻译

这部分是进行实验比较。

  1. 资源较少的语言模型

对于资源较少的语言,可以使用字符或数据较相似的资源较多的语言进行预训练。

  1. 无监督的跨语言词嵌入

本文的词嵌入是通过提出的XLM模型获得,从余弦相似度、L2距离和跨语言词语相似度几个维度评估嵌入质量,在SemEval’17 cross-lingual word similarity task进行评估测试。

【实验结果】

此处不再列出,感兴趣的可以看原文。

Here are some methods to defend against cross - lingual prompt injection: ### Input Validation and Sanitization - **Character and Syntax Checks**: Validate the input to ensure it only contains expected characters and follows the correct syntax for the language and the system's requirements. For example, if the system expects only alphanumeric characters in a certain field, reject inputs with special characters that could be used for injection. ```python import re def validate_input(input_str): pattern = r'^[a-zA-Z0-9]+$' return bool(re.match(pattern, input_str)) input_text = "validinput123" if validate_input(input_text): print("Input is valid.") else: print("Input may be malicious.") ``` - **Length Limitation**: Set reasonable length limits for user inputs. Long inputs may be more likely to contain malicious injection attempts. ### Encoding and Escaping - **Proper Encoding**: Use appropriate encoding for user inputs, such as UTF - 8. This can prevent some encoding - related injection attacks. - **Escaping Special Characters**: Escape special characters in the input to prevent them from being interpreted as part of a malicious command. For example, in SQL, characters like single quotes (' ) need to be properly escaped. ```python import sqlite3 def escape_input(input_str): return input_str.replace("'", "''") input_text = "O'Connor" escaped_text = escape_input(input_text) conn = sqlite3.connect('example.db') cursor = conn.cursor() query = f"SELECT * FROM users WHERE name = '{escaped_text}'" cursor.execute(query) ``` ### Context - Aware Filtering - **Understand the Context**: Analyze the context in which the input is used. For example, if the input is used in a translation context, filter out words or phrases that are not relevant to normal translation requests and may be injection attempts. - **Language - Specific Rules**: Apply language - specific rules and filters. Different languages have different grammar, vocabulary, and common patterns. Use these to identify abnormal inputs. ### Model - Based Detection - **Anomaly Detection Models**: Train machine learning or deep learning models to detect abnormal patterns in user inputs. These models can be trained on a large dataset of normal and malicious inputs. ```python import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense # Assume X_train and y_train are pre - processed training data model = Sequential([ Dense(64, activation='relu', input_shape=(input_dim,)), Dense(32, activation='relu'), Dense(1, activation='sigmoid') ]) model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']) model.fit(X_train, y_train, epochs=10, batch_size=32) ``` ### Isolation and Sandboxing - **Isolate User Inputs**: Run operations involving user inputs in isolated environments or sandboxes. This can prevent malicious code from affecting the main system. For example, use containerization technologies like Docker to isolate translation tasks.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值