-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor project dependencies * Install latest pip and poetry
- Loading branch information
1 parent
c6fd216
commit 7a44be7
Showing
20 changed files
with
342 additions
and
1,682 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
import functools | ||
import os | ||
import pathlib | ||
from typing import Dict | ||
|
||
import joblib | ||
import pycrfsuite | ||
from sklearn.externals import joblib | ||
|
||
from maru.feature.extractor import IFeatureExtractor | ||
from maru.tag import Tag | ||
|
||
_get_path = functools.partial(os.path.join, os.path.dirname(__file__)) | ||
_DIRECTORY = pathlib.Path(__file__).parent.absolute() | ||
|
||
|
||
def load_extractor() -> IFeatureExtractor: | ||
return joblib.load(_get_path('extractor.joblib')) | ||
return joblib.load(_DIRECTORY / 'extractor.joblib') | ||
|
||
|
||
def load_tags() -> Dict[int, Tag]: | ||
return joblib.load(_get_path('tags.joblib')) | ||
return joblib.load(_DIRECTORY / 'tags.joblib') | ||
|
||
|
||
def load_tagger() -> pycrfsuite.Tagger: | ||
tagger = pycrfsuite.Tagger() | ||
tagger.open(_get_path('tagger.crfsuite')) | ||
tagger.open(str(_DIRECTORY / 'tagger.crfsuite')) | ||
return tagger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,37 @@ | ||
import functools | ||
import gzip | ||
import json | ||
import os | ||
import pathlib | ||
from typing import Dict | ||
|
||
import joblib | ||
import numpy | ||
from sklearn.externals import joblib | ||
|
||
from maru.feature.extractor import IFeatureExtractor | ||
from maru.feature.vocabulary import PositionalFeatureVocabulary | ||
from maru.tag import Tag | ||
|
||
_get_path = functools.partial(os.path.join, os.path.dirname(__file__)) | ||
_DIRECTORY = pathlib.Path(__file__).parent.absolute() | ||
|
||
|
||
def load_extractor() -> IFeatureExtractor: | ||
return joblib.load(_get_path('extractor.joblib')) | ||
return joblib.load(_DIRECTORY / 'extractor.joblib') | ||
|
||
|
||
def load_vocabulary() -> PositionalFeatureVocabulary: | ||
with open(_get_path('vocabulary.json'), encoding='utf8') as f: | ||
with (_DIRECTORY / 'vocabulary.json').open(encoding='utf8') as f: | ||
data = {int(index): mapping for index, mapping in json.load(f).items()} | ||
return PositionalFeatureVocabulary(data) | ||
|
||
|
||
def load_tags() -> Dict[int, Tag]: | ||
return joblib.load(_get_path('tags.joblib')) | ||
return joblib.load(_DIRECTORY / 'tags.joblib') | ||
|
||
|
||
def load_coefficients() -> numpy.array: | ||
return joblib.load(_get_path('coefficients.joblib')) | ||
with gzip.open(_DIRECTORY / 'coefficients.gz', 'rb') as data: | ||
return numpy.load(data) | ||
|
||
|
||
def load_intercept() -> numpy.array: | ||
return joblib.load(_get_path('intercept.joblib')) | ||
with gzip.open(_DIRECTORY / 'intercept.gz', 'rb') as data: | ||
return numpy.load(data) |
Git LFS file not shown
This file was deleted.
Oops, something went wrong.
Git LFS file not shown
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
import functools | ||
import json | ||
import os | ||
import pathlib | ||
from typing import Dict | ||
|
||
import keras | ||
import tensorflow | ||
from sklearn.externals import joblib | ||
import joblib | ||
import tensorflow.keras | ||
|
||
from maru.feature.extractor import IFeatureExtractor | ||
from maru.feature.vocabulary import FeatureVocabulary | ||
from maru.tag import Tag | ||
|
||
_get_path = functools.partial(os.path.join, os.path.dirname(__file__)) | ||
_DIRECTORY = pathlib.Path(__file__).parent.absolute() | ||
|
||
|
||
def load_extractor() -> IFeatureExtractor: | ||
return joblib.load(_get_path('extractor.joblib')) | ||
return joblib.load(_DIRECTORY / 'extractor.joblib') | ||
|
||
|
||
def load_tags() -> Dict[int, Tag]: | ||
return joblib.load(_get_path('tags.joblib')) | ||
return joblib.load(_DIRECTORY / 'tags.joblib') | ||
|
||
|
||
def load_tagger() -> keras.Model: | ||
def load_tagger() -> tensorflow.keras.Model: | ||
# this restrains tensorflow from allocating all of available GPU memory | ||
config = tensorflow.ConfigProto() | ||
config = tensorflow.compat.v1.ConfigProto() | ||
config.gpu_options.allow_growth = True | ||
|
||
keras.backend.set_session(tensorflow.Session(config=config)) | ||
tensorflow.compat.v1.keras.backend.set_session( | ||
tensorflow.compat.v1.Session(config=config) | ||
) | ||
|
||
return keras.models.load_model(_get_path('tagger.h5')) | ||
return tensorflow.keras.models.load_model(_DIRECTORY / 'tagger.h5') | ||
|
||
|
||
def load_char_vocabulary() -> FeatureVocabulary: | ||
with open(_get_path('char_vocabulary.json'), encoding='utf8') as f: | ||
with (_DIRECTORY / 'char_vocabulary.json').open(encoding='utf8') as f: | ||
return FeatureVocabulary(json.load(f)) | ||
|
||
|
||
def load_grammeme_vocabulary() -> FeatureVocabulary: | ||
with open(_get_path('grammeme_vocabulary.json'), encoding='utf8') as f: | ||
with (_DIRECTORY / 'grammeme_vocabulary.json').open(encoding='utf8') as f: | ||
return FeatureVocabulary(json.load(f)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.