Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import logging
import os
import sys
from os.path import dirname
from underthesea.data import Sentence
from underthesea.models_lf.text_classifier import TextClassifier
from underthesea.model_fetcher import ModelFetcher, UTSModel
FORMAT = '%(message)s'
logging.basicConfig(format=FORMAT)
logger = logging.getLogger('underthesea')
sys.path.insert(0, dirname(dirname(__file__)))
model_path = ModelFetcher.get_model_path(UTSModel.tc_bank)
classifier = None
def classify(X):
global classifier
if not classifier:
if os.path.exists(model_path):
classifier = TextClassifier.load(model_path)
else:
logger.error(
f"Could not load model at {model_path}.\n"
f"Download model with \"underthesea download {UTSModel.tc_bank.value}\".")
sys.exit(1)
sentence = Sentence(X)
classifier.predict(sentence)
import logging
import os
import sys
from underthesea.data import Sentence
from underthesea.model_fetcher import ModelFetcher, UTSModel
from underthesea.models_lf.text_classifier import TextClassifier
from . import text_features
FORMAT = '%(message)s'
logging.basicConfig(format=FORMAT)
logger = logging.getLogger('underthesea')
sys.modules['text_features'] = text_features
model_path = ModelFetcher.get_model_path(UTSModel.sa_general)
classifier = None
def sentiment(text):
global classifier
if not classifier:
if os.path.exists(model_path):
classifier = TextClassifier.load(model_path)
else:
logger.error(
f"Could not load model at {model_path}.\n"
f"Download model with \"underthesea download {UTSModel.sa_general.value}\".")
sys.exit(1)
sentence = Sentence(text)
classifier.predict(sentence)
label = sentence.labels[0]
import logging
import os
import sys
from underthesea.data import Sentence
from underthesea.model_fetcher import ModelFetcher, UTSModel
from underthesea.models_lf.text_classifier import TextClassifier
from . import text_features
FORMAT = '%(message)s'
logging.basicConfig(format=FORMAT)
logger = logging.getLogger('underthesea')
sys.modules['text_features'] = text_features
model_path = ModelFetcher.get_model_path(UTSModel.sa_bank)
classifier = None
def sentiment(text):
global classifier
if not classifier:
if os.path.exists(model_path):
classifier = TextClassifier.load(model_path)
else:
logger.error(
f"Could not load model at {model_path}.\n"
f"Download model with \"underthesea download {UTSModel.sa_bank.value}\".")
sys.exit(1)
sentence = Sentence(text)
classifier.predict(sentence)
import os
import sys
from os.path import dirname
import logging
from underthesea.data import Sentence
from underthesea.model_fetcher import UTSModel, ModelFetcher
from underthesea.models_lf.text_classifier import TextClassifier
FORMAT = '%(message)s'
logging.basicConfig(format=FORMAT)
logger = logging.getLogger('underthesea')
sys.path.insert(0, dirname(dirname(__file__)))
model_path = ModelFetcher.get_model_path(UTSModel.tc_general)
classifier = None
def classify(X):
global classifier
if not classifier:
if os.path.exists(model_path):
classifier = TextClassifier.load(model_path)
else:
logger.error(
f"Could not load model at {model_path}.\n"
f"Download model with \"underthesea download {UTSModel.tc_general.value}\".")
sys.exit(1)
def list(all):
ModelFetcher.list(all)
def download(model):
ModelFetcher.download_model(model)