How to use the underthesea.models_lf.text_classifier.TextClassifier 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 / sentiment / bank / __init__.py View on Github external
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)
    labels = sentence.labels
    return [label.value for label in labels]
github undertheseanlp / underthesea / underthesea / sentiment / general / __init__.py View on Github external
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]
    if label == "1":
        label = "negative"
    if label == "0":
        label = "positive"
    return label
github undertheseanlp / underthesea / underthesea / classification / vntc / __init__.py View on Github external
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)

    sentence = Sentence(X)
    classifier.predict(sentence)
    labels = sentence.labels
    return labels
github undertheseanlp / underthesea / underthesea / classification / bank / __init__.py View on Github external
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)
    labels = sentence.labels
    if not labels:
        return None
    return [label.value for label in labels]
github undertheseanlp / underthesea / underthesea / models_lf / text_classifier.py View on Github external
#     model_file = join(model_folder, "model.bin")
        #     classifier = TextClassifier(estimator=TEXT_CLASSIFIER_ESTIMATOR.FAST_TEXT)
        #     classifier.ft = fastText.load_model(model_file)
        #     return classifier

        if estimator == TEXT_CLASSIFIER_ESTIMATOR.SVC:
            classifier = TextClassifier(estimator=TEXT_CLASSIFIER_ESTIMATOR.SVC)
            classifier.svc = joblib.load(join(model_folder, "estimator.joblib"))
            x_transformer = joblib.load(join(model_folder, "x_transformer.joblib"))
            classifier.x_transformer = x_transformer
            y_transformer = joblib.load(join(model_folder, "y_transformer.joblib"))
            classifier.y_transformer = y_transformer
            return classifier

        if estimator == TEXT_CLASSIFIER_ESTIMATOR.PIPELINE:
            classifier = TextClassifier(estimator=TEXT_CLASSIFIER_ESTIMATOR.PIPELINE)
            if "multilabel" in metadata:
                if metadata["multilabel"]:
                    classifier.multilabel = True
                    classifier.y_encoder = joblib.load(join(model_folder, "y_encoder.joblib"))
            classifier.pipeline = joblib.load(join(model_folder, "pipeline.joblib"))

            return classifier
github undertheseanlp / underthesea / underthesea / models_lf / text_classifier.py View on Github external
if metadata['estimator'] == 'SVC':
            estimator = TEXT_CLASSIFIER_ESTIMATOR.SVC
        if metadata['estimator'] == 'FAST_TEXT':
            estimator = TEXT_CLASSIFIER_ESTIMATOR.FAST_TEXT
        if metadata['estimator'] == 'PIPELINE':
            estimator = TEXT_CLASSIFIER_ESTIMATOR.PIPELINE

        # GH-304: remove fasttext
        # if estimator == TEXT_CLASSIFIER_ESTIMATOR.FAST_TEXT:
        #     model_file = join(model_folder, "model.bin")
        #     classifier = TextClassifier(estimator=TEXT_CLASSIFIER_ESTIMATOR.FAST_TEXT)
        #     classifier.ft = fastText.load_model(model_file)
        #     return classifier

        if estimator == TEXT_CLASSIFIER_ESTIMATOR.SVC:
            classifier = TextClassifier(estimator=TEXT_CLASSIFIER_ESTIMATOR.SVC)
            classifier.svc = joblib.load(join(model_folder, "estimator.joblib"))
            x_transformer = joblib.load(join(model_folder, "x_transformer.joblib"))
            classifier.x_transformer = x_transformer
            y_transformer = joblib.load(join(model_folder, "y_transformer.joblib"))
            classifier.y_transformer = y_transformer
            return classifier

        if estimator == TEXT_CLASSIFIER_ESTIMATOR.PIPELINE:
            classifier = TextClassifier(estimator=TEXT_CLASSIFIER_ESTIMATOR.PIPELINE)
            if "multilabel" in metadata:
                if metadata["multilabel"]:
                    classifier.multilabel = True
                    classifier.y_encoder = joblib.load(join(model_folder, "y_encoder.joblib"))
            classifier.pipeline = joblib.load(join(model_folder, "pipeline.joblib"))

            return classifier