How to use the underthesea.model_fetcher.ModelFetcher function in underthesea

To help you get started, we’ve selected a few underthesea examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github undertheseanlp / underthesea / underthesea / classification / bank / __init__.py View on Github external
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)
github undertheseanlp / underthesea / underthesea / sentiment / general / __init__.py View on Github external
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]
github undertheseanlp / underthesea / underthesea / sentiment / bank / __init__.py View on Github external
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)
github undertheseanlp / underthesea / underthesea / classification / vntc / __init__.py View on Github external
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)
github undertheseanlp / underthesea / underthesea / cli.py View on Github external
def download(model):
    ModelFetcher.download_model(model)