Closed Bug 1916064 Opened 2 years ago Closed 1 year ago

An Investigation Into Source-Text Splitting for Translations

Categories

(Firefox :: Translations, task, P3)

task

Tracking

()

RESOLVED FIXED

People

(Reporter: nordzilla, Unassigned)

References

Details

Purpose

This bug serves as a dedicated location for investigation and conversation regarding the optimal way to spit the source text that we translate in Firefox. At this time, there are no action items associated with this bug, however some may be added on pending further discussion.

This is relevant to CJK translations, because the current text segmenter used by Bergamot does not currently support CJK languages. However, I believe that there may be opportunities to improve our algorithms for all languages, not just for CJK.

Investigation

Relevant Links

Description

During my preliminary investigations to scope out work for ensuring that the Gecko Translations platform fully supports CJK language translations, I noticed some interesting behavior with regard to the way we split the source text that we feed to Bergamot for Translations. I think that our models' outputs could be improved by grouping relevant sentences together, providing a broader context for translation.

ssplit-cpp Modes

Our current implementation of Translations utilizes Bergamot, which segments its text using the non-CJK-compatible library ssplit-cpp.

ssplit-cpp includes options for three different modes:

-m,--mode TEXT:{w,s,p}=w    Split mode: s (one sentence per line), p (one paragraph per line), w (wrapped text).

At first, I was confused by this, because I assumed this mode applied to the way that the text would be formatted after splitting, but it, in fact, is the expectation of how the input text will be interpreted before splitting.

Consider the following input example, which I will use again in a later section:

The women in my book club are so kind! They are never angry. Actually, I am wrong, they are angry now.

They are really angry.

Mode Line Number Sentence Number Output
-p 1 1 1.1 The women in my book club are so kind!
1 2 1.2 They are never angry.
1 3 1.3 Actually, I am wrong, they are angry now.
2 1 2.1
3 1 3.1 They are really angry.
Mode Line Number Sentence Number Output
-s 1 1 1 The women in my book club are so kind! They are never angry. Actually, I am wrong, they are angry now.
2 1 2
3 1 3 They are really angry.

As shown above, the -p (paragraph) mode expects the input to be one paragraph per line, and it separates the paragraph into sub-sentences. The -s (sentence) mode expects one sentence per line, and it treats the entire first paragraph as a single sentence.

Currently, in Firefox, we are using the -p (paragraph) mode for input.


Experimenting With Other Modes in Firefox

I have noticed that with our current splitting, the translation models seem to treat each sentence as being in its own isolated context. That is to say that the -p (paragraph) mode of ssplit-cpp seems to feed Bergamot one sentence at a time for translation.

This leads to results such as the following:

Input (English)

The women in my book club are so kind! They are never angry. Actually, I am wrong, they are angry now.

They are really angry.

Output (Spanish)
Mode: -p

Las mujeres de mi club de lectura son tan amables. Nunca están enojados. En realidad, me equivoqué, ahora están enfadados.

Están muy enojados.

Pay particular attention to the way the word "angry" is translated, which is either "enojados" or "enfadados". (Both are valid translations for "angry" depending on the dialect of Spanish. It would be good to be consistent here, but the difference between es-ES Spanish and es-MX Spanish is beyond the scope of this discussion.) Importantly, note that the gender used in "enojados" and "enfadados" is the masculine form of the adjective, which is not correct to describe a group of women mentioned in the first sentence.

Observe what happens when we compile Firefox locally with Bergamot's ssplit mode set to -s, ultimately treating the entire first paragraph as one "sentence" input. (I suspect that this may be a technically incorrect way to provide input to the model, but it does provide better output in this case.)

Output (Spanish)
Mode: -s

Las mujeres de mi club de lectura son tan amables. Nunca están enojadas. En realidad, me equivoqué, están enojadas ahora.

Están muy enojados.

In this example, the entire first paragraph is translated much better, correctly using the feminine form of the verb "enojadas" to describe the group of women in the book club.

The model does, however, lose track of this context by the next paragraph, and goes back to defaulting to "enojados," which would only be used to describe a group of men, or a group consisting of people with different genders.

Drawbacks of Providing More Context To the Model

I have noticed, in some situations, that providing more context to the model, such as using -s (sentence) mode in the previous section, causes the model to drop entire sentences. Here is one such example, where we remove "Actually, I am wrong," from our example input:

Input (English)

The women in my book club are so kind! They are never angry. They are angry now.

They are really angry.

Output (Spanish)
Mode -p

Las mujeres de mi club de lectura son tan amables. Nunca están enojados. Ahora están enojados.

Están muy enojados.

Output (Spanish)
Mode -s

Las mujeres de mi club de lectura son tan amables, nunca están enfadadas.

Están muy enojados.

Note that while the -p (paragraph) mode output continues to use the wrong gender for the adjective "enojados," it does translate each sentence. The -s (sentence) mode output drops one of the sentences entirely.

Conclusions and Further Discussion

As I am looking into both improving our text segmentation to support CJK as well as moving the segmentation into Gecko and out of Bergamot itself, I think that we should consider how to best achieve the correct balance of how much context to provide to the models per paragraph of input.

It's not clear to me if further robustness training may be needed to prevent the models from dropping sentences, as shown above.

At this point I'd like to open this bug for further discussion to gain more insight into this exploration, because I lack some context into how text inputs are segmented while the models are being trained, and I suspect that feeding an entire paragraph as a single "sentence" is more of a hack than a real solution. But I do think that we can figure out a better way to achieve higher quality translations.

Flags: needinfo?(gtatum)
Flags: needinfo?(epavlov)

Great analysis, Erik! I don't have a strong opinion here. I looked at some samples of datasets on OPUS and it looks like most of the training examples are sentences. I see there are some multi sentence training examples in Paracrawl corpus though https://opus.nlpl.eu/sample/en&ru/ParaCrawl&v9/sample. So it's not clear to me what's the best course of action from the quality perspective. Maybe we can run some evaluation benchmarks for translation of documents.

You might want to do some archeology and look at the issues in bergamot-translator that mention splitting. You might find some insights about the related decision making: https://github.com/browsermt/bergamot-translator/issues?q=is%3Aissue+is%3Aopen+split. I suspect there were some reasons to do it this way.

I would also suggest asking the maintainers about this in a new issue. I'm not sure they'll respond though.

Flags: needinfo?(epavlov)
Priority: -- → P3

I'm not sure I have more to add here, cancelling my needinfo.

Flags: needinfo?(gtatum)
Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
No longer blocks: 1904415
See Also: → 1904415
You need to log in before you can comment on or make changes to this bug.