0

我正在尝试使用节模型预测“兴奋”,在 colab 笔记本和 aws ec2 API 中使用了相同的函数。当我尝试预测这个词时,我在 colab 笔记本中获得了标签“正面”,而在 django 的应用程序 API 中获得了“中性”标签。

我在两个环境中都检查了 Stanza 版本,并且都在使用:

Name: stanza
Version: 1.2
Summary: A Python NLP Library for Many Human Languages, by the Stanford NLP Group
Home-page: https://github.com/stanfordnlp/stanza
Author: Stanford Natural Language Processing Group
Author-email: jebolton@stanford.edu
License: Apache License 2.0
Location: /usr/local/lib/python3.7/dist-packages
Requires: numpy, requests, tqdm, torch, protobuf
Required-by: 

但是,我不确定是否相同的一件事是文件夹 stanza_resources(如果两者的版本相同,这应该相同吗?)。

功能:

!pip3 install stanza

import stanza
stanza.download('en', package='ewt', processors='tokenize,sentiment,pos', verbose=True)
stanza.download('en', package='default', processors='tokenize,sentiment', verbose=True)
stanza.download(lang="en",package=None,processors={"pos":"combined"})

stNLP = stanza.Pipeline(processors='tokenize,sentiment,pos', lang='en', use_gpu=True)

def stanza_predict(text):
    '''
    :param text: text to be predicted
    :param verbose: 0 or 1. Verbosity mode. 0 = to predict text, 1 = to predict labels.
    :return: POSITIVE or NEGATIVE prediction
    '''
    data = stNLP(text)
    sentiment_map = {'0': 'NEGATIVE', '1': 'NEUTRAL', '2': 'POSITIVE'}
    #print(data)
    for sentence in data.sentences:
        pred_sentiment = sentence.sentiment

        if pred_sentiment == 0:
            pred = sentiment_map['0']
        elif pred_sentiment == 1:
            pred = sentiment_map['1']
        elif pred_sentiment == 2:
            pred = sentiment_map['2']

    return pred

# Expected output (as the colab notebook):
stanza_predict('excited')
output: 'POSITIVE'

具有不同预测和相同节版本的图像:

节

4

0 回答 0