Skip to content

Commit

Permalink
Merge branch 'master' into ja-support
Browse files Browse the repository at this point in the history
  • Loading branch information
yannvgn committed Nov 1, 2019
2 parents a33e397 + 158d24e commit e5f9012
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 23 deletions.
59 changes: 50 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,57 @@
dist: xenial
language: python
python:
- "3.6"
- "3.7"
before_install:
- pip install poetry
jobs:
include:
- name: "Python 3.7 on Xenial Linux"
python: 3.7
before_install:
- python -m pip install --upgrade pip
- pip3 install poetry
- pip3 install torch==1.3.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
- name: "Python 3.6 on Xenial Linux"
python: 3.6
before_install:
- python -m pip install --upgrade pip
- pip3 install poetry
- pip3 install torch==1.3.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
- name: "Python 3.7 on macOS"
os: osx
osx_image: xcode11.2
language: shell
before_install:
- python3 -m pip install --upgrade pip
- pip3 install poetry
- pip3 install virtualenv
- virtualenv .env
- source .env/bin/activate
- pip3 install torch
- name: "Python 3.7 on Windows"
os: windows
language: shell
before_install:
- choco install python --version 3.7.0
- python -m pip install --upgrade pip
- pip3 install poetry
- poetry config settings.virtualenvs.create false
- pip3 install torch==1.3.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
env: PATH=/c/Python37:/c/Python37/Scripts:$PATH
- name: "Python 3.7 on Xenial Linux (wheel installation)"
python: 3.7
before_install:
- python -m pip install --upgrade pip
- pip3 install poetry
- pip3 install torch==1.3.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
install:
- poetry build
- pip3 install dist/laserembeddings-*.whl
- python -m laserembeddings download-models
script:
- python -c 'from laserembeddings import Laser; laser = Laser(); laser.embed_sentences(["test"], lang="en")'

install:
- if [[ `python --version` =~ 'Python 3.6' ]]; then pip install https://download.pytorch.org/whl/cpu/torch-1.1.0-cp36-cp36m-linux_x86_64.whl; fi
- if [[ `python --version` =~ 'Python 3.7' ]]; then pip install https://download.pytorch.org/whl/cpu/torch-1.1.0-cp37-cp37m-linux_x86_64.whl; fi
- poetry remove torch -n # fix: latest torch wheel (1.1.0.post2) not available for linux
- poetry install -n
- python -m laserembeddings download-models
- python3 -m laserembeddings download-models || python -m laserembeddings download-models

script:
- poetry run pylint laserembeddings
- poetry run pytest
36 changes: 26 additions & 10 deletions laserembeddings/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,53 @@
import urllib.request
import tarfile

IS_WIN = os.name == 'nt'


def non_win_string(s):
return s if not IS_WIN else ''


CONSOLE_CLEAR = non_win_string('\033[0;0m')
CONSOLE_BOLD = non_win_string('\033[0;1m')
CONSOLE_WAIT = non_win_string('⏳')
CONSOLE_DONE = non_win_string('✅')
CONSOLE_STARS = non_win_string('✨')
CONSOLE_ERROR = non_win_string('❌')


def print_usage():
print('Usage:')
print('')
print(
'\033[0;1mpython -m laserembeddings download-models [OUTPUT_DIRECTORY]\033[0;0m'
f'{CONSOLE_BOLD}python -m laserembeddings download-models [OUTPUT_DIRECTORY]{CONSOLE_CLEAR}'
)
print(
' Downloads LASER model files. If OUTPUT_DIRECTORY is omitted,'
'\n'
' the models will be placed into the \033[0;1mdata\033[0;0m directory of the module'
f' the models will be placed into the {CONSOLE_BOLD}data{CONSOLE_CLEAR} directory of the module'
)
print('')
print('\033[0;1mpython -m laserembeddings download-test-data\033[0;0m')
print(
f'{CONSOLE_BOLD}python -m laserembeddings download-test-data{CONSOLE_CLEAR}'
)
print(' downloads data needed to run the tests')
print('')


def download_file(url, dest):
print(f' Downloading {url}...', end='')
print(f'{CONSOLE_WAIT} Downloading {url}...', end='')
sys.stdout.flush()
urllib.request.urlretrieve(url, dest)
print(f'\r Downloaded {url} ')
print(f'\r{CONSOLE_DONE} Downloaded {url} ')


def extract_tar(tar, output_dir):
print(f' Extracting archive...', end='')
print(f'{CONSOLE_WAIT} Extracting archive...', end='')
sys.stdout.flush()
with tarfile.open(tar) as t:
t.extractall(output_dir)
print(f'\r Extracted archive ')
print(f'\r{CONSOLE_DONE} Extracted archive ')


def download_models(output_dir):
Expand All @@ -49,7 +65,7 @@ def download_models(output_dir):
os.path.join(output_dir, 'bilstm.93langs.2018-12-26.pt'))

print('')
print("✨ You\'re all set!")
print(f'{CONSOLE_STARS} You\'re all set!')


def download_and_extract_test_data(output_dir):
Expand All @@ -64,7 +80,7 @@ def download_and_extract_test_data(output_dir):
output_dir)

print('')
print("✨ Ready to test all that!")
print(f'{CONSOLE_STARS} Ready to test all that!')


def main():
Expand Down Expand Up @@ -92,7 +108,7 @@ def main():

if os.path.basename(repository_root) != 'laserembeddings':
print(
"❌ Looks like you're not running laserembeddings from its source code"
f"{CONSOLE_ERROR} Looks like you're not running laserembeddings from its source code"
)
print(
" → please checkout https://github.com/yannvgn/laserembedings.git"
Expand Down
6 changes: 3 additions & 3 deletions laserembeddings/laser.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ def __init__(self,
if bpe_codes is None:
if not os.path.isfile(self.DEFAULT_BPE_CODES_FILE):
raise FileNotFoundError(
'93langs.fcodes is missing, run "python -m laserembeddings download-models" to fix that 🔧'
'93langs.fcodes is missing, run "python -m laserembeddings download-models" to fix that'
)
bpe_codes = self.DEFAULT_BPE_CODES_FILE
if bpe_vocab is None:
if not os.path.isfile(self.DEFAULT_BPE_VOCAB_FILE):
raise FileNotFoundError(
'93langs.fvocab is missing, run "python -m laserembeddings download-models" to fix that 🔧'
'93langs.fvocab is missing, run "python -m laserembeddings download-models" to fix that'
)
bpe_vocab = self.DEFAULT_BPE_VOCAB_FILE
if encoder is None:
if not os.path.isfile(self.DEFAULT_ENCODER_FILE):
raise FileNotFoundError(
'bilstm.93langs.2018-12-26.pt is missing, run "python -m laserembeddings download-models" to fix that 🔧'
'bilstm.93langs.2018-12-26.pt is missing, run "python -m laserembeddings download-models" to fix that'
)
encoder = self.DEFAULT_ENCODER_FILE

Expand Down
2 changes: 1 addition & 1 deletion tests/test_laser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_similarity(test_data):

if not test_data:
raise FileNotFoundError(
'laserembeddings-test-data.npz is missing, run "python -m laserembeddings download-test-data" to fix that 🔧'
'laserembeddings-test-data.npz is missing, run "python -m laserembeddings download-test-data" to fix that'
)

report = os.path.join(os.path.dirname(os.path.realpath(__file__)),
Expand Down

0 comments on commit e5f9012

Please sign in to comment.