Exemplo n.º 1
0
def classify(X):
    global classifier
    model_name = 'TC_GENERAL_V131'
    model_path = ModelFetcher.get_model_path(model_name)

    if not classifier:
        if not os.path.exists(model_path):
            ModelFetcher.download(model_name)
        classifier = TextClassifier.load(model_path)

    sentence = Sentence(X)
    classifier.predict(sentence)
    labels = sentence.labels
    return labels
Exemplo n.º 2
0
def sentiment(X):
    global classifier
    model_name = 'SA_BANK_V131'
    model_path = ModelFetcher.get_model_path(model_name)

    if not classifier:
        if not os.path.exists(model_path):
            ModelFetcher.download(model_name)
        classifier = TextClassifier.load(model_path)

    sentence = Sentence(X)
    classifier.predict(sentence)
    labels = sentence.labels
    if not labels:
        return None
    labels = [label.value for label in labels]
    return labels
Exemplo n.º 3
0
def sentiment(X):
    global classifier
    model_name = 'SA_GENERAL_V131'
    model_path = ModelFetcher.get_model_path(model_name)

    if not classifier:
        if not os.path.exists(model_path):
            ModelFetcher.download(model_name)
        classifier = TextClassifier.load(model_path)

    sentence = Sentence(X)
    classifier.predict(sentence)
    labels = sentence.labels
    try:
        label_map = {'POS': 'positive', 'NEG': 'negative'}
        label = label_map[labels[0]]
        return label
    except Exception:
        return None
Exemplo n.º 4
0
import logging
import os
import sys
from os.path import dirname
from underthesea.corpus.data import Sentence
from underthesea.models.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

sys.path.insert(0, dirname(dirname(__file__)))
classifier = None


def sentiment(X):
    global classifier
    model_name = 'SA_BANK_V131'
    model_path = ModelFetcher.get_model_path(model_name)

    if not classifier:
        if not os.path.exists(model_path):
            ModelFetcher.download(model_name)
        classifier = TextClassifier.load(model_path)

    sentence = Sentence(X)
Exemplo n.º 5
0
def remove_model(model):
    ModelFetcher.remove(model)
Exemplo n.º 6
0
def download_model(model):
    ModelFetcher.download(model)
Exemplo n.º 7
0
def list_model(all):
    ModelFetcher.list(all)
Exemplo n.º 8
0
import logging
import os
import sys
from languageflow.data import Sentence
from languageflow.models.text_classifier import TextClassifier
from underthesea.model_fetcher import ModelFetcher, UTSModel
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]