Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Language Order in OpusParallelCorpus #3620

Open
chelseagzr opened this issue Feb 21, 2025 · 0 comments · May be fixed by #3624
Open

[Bug]: Language Order in OpusParallelCorpus #3620

chelseagzr opened this issue Feb 21, 2025 · 0 comments · May be fixed by #3624
Labels
bug Something isn't working

Comments

@chelseagzr
Copy link

Describe the bug

When instantiating an OpusParallelCorpus with language pairs such as ("de", "en") or ("en", "de"), the resulting corpus consistently has German as the first language and English as the second language, regardless of the input order.

Upon reviewing the source code of OpusParallelCorpus, it appears that the following code:

if l1 > l2:
    l1, l2 = l2, l1

forces the languages to be ordered lexicographically based on their language codes. This results in German being treated as the first language in both ("de", "en") and ("en", "de").

To Reproduce

from flair.datasets import OpusParallelCorpus

corpus_de_en = OpusParallelCorpus(
    dataset="tatoeba",
    l1="de",
    l2="en",
    max_tokens_per_doc=512,
)

corpus_en_de = OpusParallelCorpus(
    dataset="tatoeba",
    l1="en",
    l2="de",
    max_tokens_per_doc=512,
)

# Both corpora consist of (German, English) pairs
print(corpus_de_en.train[0])
>> DataPair: 'Sentence[5]: "Ich muss schlafen gehen."' + 'Sentence[7]: "I have to go to sleep."'
print(corpus_en_de.train[0])
>> DataPair: 'Sentence[5]: "Ich muss schlafen gehen."' + 'Sentence[7]: "I have to go to sleep."'

Expected behavior

Sentence pairs in corpus_de_en are (German, English) while sentence pairs in corpus_en_de are (English, German)

Logs and Stack traces


Screenshots

No response

Additional Context

No response

Environment

Versions:

Flair

0.15.1

Pytorch

2.6.0+cu124

Transformers

4.49.0

GPU

False

@chelseagzr chelseagzr added the bug Something isn't working label Feb 21, 2025
@helpmefindaname helpmefindaname linked a pull request Feb 28, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant