Docsity

Machine Translation Techniques and Evaluation, Lecture notes of Natural Language Processing (NLP)

Partial preview of the text

Download Machine Translation Techniques and Evaluation and more Lecture notes Natural Language Processing (NLP) in PDF only on Docsity!

NATURAL LANGUAGE

PROCESSING (21AI62)

Dr. Pushpalatha K

Professor

Sahyadri College of Engineering & Management

Language Divergences and Typology

  • Despite the vast number of languages in the world (approximately 7 , 000 ), certain aspects of human language are universal or near- universal.
  • These universals arise from the functional role of language as a communicative system.
  • Every language has words for essential concepts such as: ▪ Referring to people (pronouns, proper nouns). ▪ Talking about eating and drinking. ▪ Expressing politeness or impoliteness.
  • Every language seems to have nouns and verbs. ▪ All languages have mechanisms to ask questions and issue commands. ▪ Languages have ways to indicate agreement or disagreement.
  • Word Order Typology ▪ Languages differ in the basic word order of verbs, subjects, and objects in simple declarative clauses. ▪ All SVO (Subject-Verb-Object) languages, the verb tends to come between the subject and object. - Languages: German, French, English, Mandarin - Example: "He wrote a letter to a friend.“ (English) ▪ In SOV languages the verb comes at the end of basic clauses. - Languages: Hindi, Japanese - Example: उसने एक दोस्त को पत्र लिखा“ (Hindi) ▪ In VSO languages, the sentence begins with verb - Languages: Irish, Arabic - Example: "katabt risāla li ṣadīq" (Arabic: "wrote letter to friend") ▪ VO Languages: Generally have prepositions - Comes before the noun - e.g., English (He walked to the park), Arabic (kataba ilā l-madrasah) ▪ OV Languages: Generally have postpositions - Comes after the noun - e.g., Japanese (Kare wa kōen ni aruita), Hindo (वह पाकक में चिा गया) ▪ Adjective-Noun Order - SVO Languages: English, Mandarin: ▪ Adjectives typically appear before nouns (e.g., "green witch"). - Other Languages: Spanish, Modern Hebrew: ▪ Adjectives typically appear after nouns (e.g., "bruja verde" - "witch green").
  • Lexical Divergences ▪ It is very important to translate the individual words from one language to another. ▪ For any translation, the appropriate word can vary depending on the context. - EX: The English source-language word bass , can appear in Spanish as the fish lubina or the musical instrument bajo. - English uses the word brother for any male sibling, Chinese and many other languages have distinct words for older brother and younger brother (Mandarin gege and didi, respectively). - In all these cases, translating bass, wall, or brother from English would require a kind of specialization, disambiguating the different uses of a word. ▪ one language places more grammatical constraints on word choice than another. - English marks nouns for whether they are singular or plural. Mandarin doesn’t. ▪ The way that languages differ in lexically dividing up conceptual space may be more complex than this one-to-many translation problem, leading to many-to-many mappings. - Translating English leg, foot, and paw, to French. ▪ when leg is used about an animal it’s translated as French jambe; but about the leg of a journey, as French etape; if the leg is of a chair, we use French pied ▪ One language may have a lexical gap, where no word or phrase, short of an explanatory footnote, can express the exact meaning of a word in the other language. - For example, English does not have a word that corresponds neatly to Mandarin xi`ao or Japanese oyak¯ok¯o
  • Morphological Typology ▪ Languages are often characterized along two dimensions of variation. ▪ The first dimension is the number of morphemes per word - Isolating Languages : Each word generally has one morpheme. ▪ Examples: Vietnamese, Cantonese. - Polysynthetic Languages : A single word may contain many morphemes,

equivalent to a whole sentence in English.

▪ Example: Siberian Yupik ("Eskimo"). ▪ The second dimension is the degree to which morphemes are segmentable,

  • Agglutinative Languages: Morphemes have relatively clean boundaries. ▪ Example: Turkish.
  • Fusion Languages: A single affix may conflate multiple morphemes. ▪ Example: Russian. - Word: "stolom" (table-SG-INSTR-DECL 1 ), where "-om" fuses instrumental, singular, and first declension. ▪ Translating between languages with rich morphology involves handling structure below the word level.
  • Modern translation systems use subword models to manage this complexity.
  • Referential Density in Languages ▪ Languages vary along a typological dimension related to the things they tend to omit. - Some languages, like English, require that we use an explicit pronoun when talking about a referent that is given in the discourse. - In other languages, sometimes pronouns omitted altogether. ▪ Languages that can omit pronouns are called pro-drop languages - Example in Spanish:"[El jefe] dio con un libro. / 0 Mostró su hallazgo a un descifrador ambulante." - Translation: "[The boss] came upon a book. [He] showed his find to a wandering decoder.“ - Even among pro-drop languages, omission frequency varies. ▪ Japanese and Chinese omit pronouns more frequently than Spanish.

Machine Translation using Encoder-Decoder

  • Given a sentence in a source language, the MT task is then to generate a corresponding sentence in a target language.
  • MT uses supervised machine learning ▪ At training time the system is given a large set of parallel sentences (each sentence in a source language matched with a sentence in the target language), and learns to map source sentences into target sentences. ▪ In practice, the sentences are split into a sequence of subword tokens. ▪ The systems are then trained to maximize the probability of the sequence of tokens in the target language y 1 , y 2 , …, y m given the sequence of tokens in the source language x 1 , x 2 ,..x n .
  • The encoder-decoder architecture consists of two components, an encoder and a decoder. ▪The encoder takes the input words x =[x

, x

,..,x

n

] and produces an intermediate context h. h = encoder(x) ▪Decoder takes h and, word by word, generates the output y i+ 1 = decoder(h;y 1 ,…,y i )) ∀ i ∈ [ 1 ,…,m]

  • The wordpiece algorithm for given a training corpus and a desired vocabulary size V,: 1. Initialize the wordpiece lexicon with characters 2. Repeat until there are V wordpieces: (a) Train an n-gram language model on the training corpus, using the current set of wordpieces. (b) Consider the set of possible new wordpieces made by concatenating two wordpieces from the current lexicon. Choose the one new wordpiece that most increases the language model probability of the training corpus.
  • More commonly used tokenization algorithm is called the unigram algorithm or sometimes the SentencePiece algorithm. ▪ In unigram tokenization, the process is started with a huge vocabulary of every individual unicode character plus all frequent sequences of characters (including all space- separated words, for languages with spaces) ▪ the algorithm proceeds iteratively by estimating the probability of each token, tokenizing the input data using various tokenizations ▪ Removes the percentage of tokens that don’t occur in high- probability tokenization, ▪ Iterates until the vocabulary has been reduced down to the desired number of tokens.
  • A sample alignment between sentences in English and French.
  • Sentence alignment takes sentences e 1 ,e 2 ,…,e n and f 1 ,f 2 ,…,f n and finds minimal sets of sentences that are translations of each other, including single sentence mappings like (e 1 ,f 1 ), (e 4 ,f 3 ), (e 5 ,f 4 ), (e 6 ,f 6 ) as well as 2 - 1 alignments (e 2 /e 3 ,f 2 ), (e 7 /e 8 ,f 7 ), and null alignments (f 5 ).
  • To score the similarity of sentences across languages, a multilingual embedding space is used, in which sentences from different languages are in the same embedding space.
  • Then cosine similarity of such embeddings provides a natural scoring function.
  • Cost function between two sentences or spans x,y from the source and target documents respectively is: ▪ where nSents() gives the number of sentences
  • The decoder transformer block includes an extra layer with a special kind of attention, cross-attention (also sometimes called encoder- decoder attention or source attention). ▪ Cross-Attention: Enables the model to consider relationships between different sequences (e.g., input and output).
  • Cross-attention has the same form as the multi-headed self-attention in a normal transformer block. ▪ the queries come from the previous layer of the decoder and the keys and values come from the output of the encoder.
  • the final output of the encoder H enc = h 1 ,.., ht is multiplied by the cross-attention layer’s key weights W K and value weights W V ,
  • The output from the prior decoder layer H dec[i- 1 ] is multiplied by the cross-attention layer’s query weights W Q :
  • The cross attention allows the decoder to attend to each of the source language words as projected into the entire encoder final output representations.
  • The other attention layer in each decoder block, the self-attention layer model which attends to all the inputs up to, and including, the current one.