Giter Club home page Giter Club logo

word2word's Introduction

image image image image

word2word

Easy-to-use word translations for 3,564 language pairs.

This is the official code accompanying our LREC 2020 paper.

Summary

  • A large collection of freely & publicly available bilingual lexicons for 3,564 language pairs across 62 unique languages.
  • Easy-to-use Python interface for accessing top-k word translations and for building a new bilingual lexicon from a custom parallel corpus.
  • Constructed using a simple approach that yields bilingual lexicons with high coverage and competitive translation quality.

Usage

First, install the package using pip:

pip install word2word

OR

git clone https://github.com/kakaobrain/word2word
python setup.py install

Then, in Python, download the model and retrieve top-5 word translations of any given word to the desired language:

from word2word import Word2word
en2fr = Word2word("en", "fr")
print(en2fr("apple"))
# out: ['pomme', 'pommes', 'pommier', 'tartes', 'fleurs']

gif

Supported Languages

We provide top-k word-to-word translations across all available pairs from OpenSubtitles2018. This amounts to a total of 3,564 language pairs across 62 unique languages.

The full list is provided here.

Methodology

Our approach computes top-k word translations based on the co-occurrence statistics between cross-lingual word pairs in a parallel corpus. We additionally introduce a correction term that controls for any confounding effect coming from other source words within the same sentence. The resulting method is an efficient and scalable approach that allows us to construct large bilingual dictionaries from any given parallel corpus.

For more details, see the Methodology section of our paper.

Building a Bilingual Lexicon on a Custom Parallel Corpus

The word2word package also provides interface for building a custom bilingual lexicon using a different parallel corpus. Here, we show an example of building one from the Medline English-French dataset:

from word2word import Word2word

# custom parallel data: data/pubmed.en-fr.en, data/pubmed.en-fr.fr
my_en2fr = Word2word.make("en", "fr", "data/pubmed.en-fr")
# ...building...
print(my_en2fr("mitochondrial"))
# out: ['mitochondriale', 'mitochondriales', 'mitochondrial', 
#       'cytopathies', 'mitochondriaux']

When built from source, the bilingual lexicon can also be constructed from the command line as follows:

python make.py --lang1 en --lang2 fr --datapref data/pubmed.en-fr

In both cases, the custom lexicon (saved to datapref/ by default) can be re-loaded in Python:

from word2word import Word2word
my_en2fr = Word2word.load("en", "fr", "data/pubmed.en-fr")
# Loaded word2word custom bilingual lexicon from data/pubmed.en-fr/en-fr.pkl

Multiprocessing

In both the Python interface and the command line interface, make uses multiprocessing with 16 CPUs by default. The number of CPU workers can be adjusted by setting num_workers=N (Python) or --num_workers N (command line).

References

If you use word2word for research, please cite our paper:

@inproceedings{choe2020word2word,
 author = {Yo Joong Choe and Kyubyong Park and Dongwoo Kim},
 title = {word2word: A Collection of Bilingual Lexicons for 3,564 Language Pairs},
 booktitle = {Proceedings of the 12th International Conference on Language Resources and Evaluation (LREC 2020)},
 year = {2020}
}

All of our pre-computed bilingual lexicons were constructed from the publicly available OpenSubtitles2018 dataset:

@inproceedings{lison-etal-2018-opensubtitles2018,
    title = "{O}pen{S}ubtitles2018: Statistical Rescoring of Sentence Alignments in Large, Noisy Parallel Corpora",
    author = {Lison, Pierre  and
      Tiedemann, J{\"o}rg  and
      Kouylekov, Milen},
    booktitle = "Proceedings of the Eleventh International Conference on Language Resources and Evaluation ({LREC} 2018)",
    month = may,
    year = "2018",
    address = "Miyazaki, Japan",
    publisher = "European Language Resources Association (ELRA)",
    url = "https://www.aclweb.org/anthology/L18-1275",
}

Authors

Kyubyong Park, Dongwoo Kim, and YJ Choe

word2word's People

Contributors

kimdwkimdw avatar kyubyong avatar yjchoe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

word2word's Issues

Linux: Permission denied error

This command would generate permission denied error in linux if user doesn't have root privilege:
en2fr = Word2word("en", "fr")

PermissionError: [Errno 13] Permission denied: '/usr/share/word2word'

To fix this, change line 15 of utils.py from savedir = "/usr/share/word2word" to savedir = "/tmp/word2word"

This should make the program use user's home directory by default.

Python2 Support

For the ones that are still using Python2, I have prepared this version with small changes that enables Python2 support. The most important change is to support reading the Pickle protocol=3 in Python2. Then it works like a charm.
https://github.com/loretoparisi/word2word

$ python
Python 2.7.16 (default, Mar  4 2019, 09:01:38) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from word2word import Word2word
>>> en2fr = Word2word("en", "fr")
>>> print(en2fr("apple"))
[u'pomme', u'pommes', u'pommier', u'tartes', u'fleurs']

Invalid syntax

from word2word import Word2word
Traceback (most recent call last):
File "", line 1, in
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 664, in _load_unlocked
File "", line 634, in load_backward_compatible
File "C:\Users\Admin\AppData\Local\Programs\Python\Python35\lib\site-packages\word2word-1.0.0-py3.5.egg\word2word_init
.py", line 6, in
File "", line 969, in _find_and_load
File "", line 954, in _find_and_load_unlocked
File "", line 896, in _find_spec
File "", line 1136, in find_spec
File "", line 1112, in _get_spec
File "", line 1093, in _legacy_get_spec
File "", line 444, in spec_from_loader
File "", line 530, in spec_from_file_location
File "C:\Users\Admin\AppData\Local\Programs\Python\Python35\lib\site-packages\word2word-1.0.0-py3.5.egg\word2word\word2word.py", line 44
f"custom bilingual lexicon is only partially provided. "
^
SyntaxError: invalid syntax

kill:9 issue for large dataset

I am able to train and get result as expected for a medium size dataset. But when I increase the dataset, it gets killed after step 5, even if I increase the no of workers which is less than my cpu_count (e.g., 40<60). How to use large dataset for training in w2w? Any help is appreciated. Thanks.

Error while downloading the Data

en2fr = Word2word("en", "fr")
Downloading data ...
42% [............................... ] 3424256 / 8022400Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Admin\appdata\local\programs\python\Python36\lib\site-packages\word2word-1.0.0-py3.6.egg\word2word\word2word.py", line 50, in init
lang1, lang2, custom_savedir
File "C:\Users\Admin\appdata\local\programs\python\Python36\lib\site-packages\word2word-1.0.0-py3.6.egg\word2word\utils.py", line 55, in download_or_load
wget.download(url, fpath)
File "C:\Users\Admin\appdata\local\programs\python\Python36\lib\site-packages\wget-3.2-py3.6.egg\wget.py", line 526, in download
File "C:\Users\Admin\appdata\local\programs\python\Python36\lib\urllib\request.py", line 289, in urlretrieve
% (read, size), result)
urllib.error.ContentTooShortError: <urlopen error retrieval incomplete: got only 3420504 out of 8022400 bytes>

word2word.py의 106번째 라인에 대해

안녕하세요, word2word를 잘 사용하고 있는 한 학생입니다.
사용하다 한 가지 궁금한점이 생겨 질문드립니다.

lang1으로 ko, lang2로 en을 설정했을 때 강제로 lang1이 en, lang2가 ko로 바뀌는 현상을 발견했고,
word2word.py의 106번째 라인에 있는 아래와 같은 코드가 원인인 것이라 생각됩니다.

혹시 이 부분이 의도된 동작인지 궁금하여 issue를 남겨놓습니다.

감사합니다.

lang1, lang2 = sorted([lang1, lang2])

P@1

Hello, How is the P@1 on the Chinese-Spanish dictionary?

Training a new language pairs from scratch

Thanks for this amazing project. My main question is about training.
I have noticed that for Indian Languages, it is missing Marathi mr, and I wonder how to train the model from scratch, having the input parallel corpus, like open subtitles or others like Ted Talks or Tatoeba parallel sentences corpus.
In my case, for indian languages (and a transliteration task), my reference is IndicTrans, https://github.com/libindic/indic-trans
A minor question is about the w2w, PMI and CPE formulas. A great solution! This reminds me Peter Norvig's probabilistic spell checker, where the conditional probabilities are taken in account, while your CPE score makes the difference. Just my wonder :)
Thank you.

Complete installation is not explained

This is interesting project but complete installation is not explained at all.

In README, the author says "Then, in Python, download the model and retrieve top-k word translations of any given word to the desired language."

Where can I find the way how to download model ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.