From 9b1ffd054e8211a3611d88f5332358d739be451d Mon Sep 17 00:00:00 2001 From: m-yoshinaka <49668018+m-yoshinaka@users.noreply.github.com> Date: Tue, 7 Apr 2020 18:04:29 +0900 Subject: [PATCH] fix code --- README.md | 4 ++-- run_sapphire.py | 6 ++++-- sapphire/setting.py | 11 ----------- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 762f9fa..044994c 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,9 @@ $ mv wiki-news-300d-1M-subword.bin model/ ### Interactive mode ``` -$ python run_sapphire.py +$ python run_sapphire.py model/wiki-news-300d-1M-subword.bin ``` -To stop SAPPHIRE, enter `exit` when inputting a sentence. +To stop SAPPHIRE, enter `EXIT` when inputting a sentence. ### Usage of the SAPPHIRE module ``` diff --git a/run_sapphire.py b/run_sapphire.py index b7f50d8..5c913ce 100644 --- a/run_sapphire.py +++ b/run_sapphire.py @@ -1,11 +1,13 @@ +import sys import fasttext from sapphire import Sapphire, setting def run_sapphire(): + fasttext_path = sys.argv[1] print(' * Loading pre-trained model ...', flush=True, end='') - model = fasttext.FastText.load_model(setting.FASTTEXT_PATH) + model = fasttext.FastText.load_model(fasttext_path) print(' * - completed') aligner = Sapphire(model) @@ -16,7 +18,7 @@ def run_sapphire(): while sentence_src == '': print('Input tokenized sentence (A)') sentence_src = input('> ') - if sentence_src == 'exit': + if sentence_src == 'EXIT': break sentence_trg = '' diff --git a/sapphire/setting.py b/sapphire/setting.py index 16dbd28..f717a8c 100644 --- a/sapphire/setting.py +++ b/sapphire/setting.py @@ -1,16 +1,5 @@ -import os -import sys - -FASTTEXT_PATH = 'model/wiki-news-300d-1M-subword.bin' - HUGARIAN = False # word alignment option (default: grow-diag-final) LAMBDA = 0.7 # threshold of word alignment candidate score DELTA = 0.9 # threshold of phrase alignment candidate score ALPHA = 0.05 # bias for length of phrase - -if os.path.exists(FASTTEXT_PATH): - MODEL_PATH = 'model/wiki-news-300d-1M-subword.bin' # path of pre-trained word embedding model (default: fastText) -else: - print('Input the path of your pre-trained word embedding model.') - MODEL_PATH = input('> ')