私のシステムを実行しているときに、同じ出力を持ちます

Nedis:

私はその後、私はリストに私の答えを持って、予測一部を行っている、そして今、私は最大のものを持つようにしたい場合にのみ1答えを持ってしようとしています、私は成功した私のモデルを訓練してきた、感情検出分析を実施していますしかし、私は私が私のミスをしてください修正するために、すべての出力に同じ答えを持っています..缶誰かの助け。

ここに私のコードは次のとおりです。

        with open('output2.json', 'w') as f:
            json.dump(new_data, f)

selection1 = new_data['selection1']
#creating empty list to be able to create a dataframe
names = []
dates = []
commentss = []
labels = []
hotelname = []
for item in selection1:
    name = item['name']
    hotelname.append(name)
    #print ('>>>>>>>>>>>>>>>>>> ', name)
    Date = item['reviews']
    for d in Date:
        names.append(name)
        #convert date from 'january 12, 2020' to 2020-01-02
        date = pd.to_datetime(d['date']).strftime("%Y-%m-%d")
        #adding date to the empty list dates[]
        dates.append(date)
        #print('>>>>>>>>>>>>>>>>>> ', date)
    CommentID = item['reviews']
    for com in CommentID:
        comment = com['review']
        lcomment = comment.lower()  # converting all to lowercase
        result = re.sub(r'\d+', '', lcomment)  # remove numbers
        results = (result.translate(
        str.maketrans('', '', string.punctuation))).strip()  # remove punctuations and white spaces
        comments = remove_stopwords(results)
        commentss.append(comment)
        print('>>>>>>',comments)

    #add the words in comments that are already present in the keys of dictionary
        encoded_samples = [[word2id[word] for word in comments if word in word2id.keys()]]


    # Padding
        encoded_samples = keras.preprocessing.sequence.pad_sequences(encoded_samples, maxlen=max_words)

     # Make predictions
        label_probs, attentions = model_with_attentions.predict(encoded_samples)
        label_probs = {id2label[_id]: prob for (label, _id), prob in zip(label2id.items(), label_probs[0])}
        labels.append(label_probs)
       #Get word attentions using attenion vector
        print(label_probs)
        print(max(label_probs))

これが出力されます。

>>>>>> ['nice', 'welcoming', 'staff', 'however', 'improvements', 'made', 'regarding', 'servicesfacilities', 'provided', 'eg', 'room', 'service', 'arrived', 'evening', 'dinner', 'time', 'change', 'water', 'bottle', 'expecting', 'enter', 'room', 'absence', 'left', 'luggage', 'personal', 'belongings', 'opened', 'ingredients', 'gelatine', 'used', 'well', 'mentioned', 'near', 'cakes', 'served', 'dessert', 'porkbeef', 'gelatin', 'need', 'keep', 'asking', 'doubt', 'vegetarian', 'tagliatelle', 'rip', 'careful', 'booking', 'navasana', 'spa', 'told', 'bookings', 'hammam', 'made', 'least', 'one', 'day', 'advance', 'mentioned', 'elsewhere', 'bookings', 'hotel', 'told', 'staff', 'well', 'leave', 'next', 'day', 'noon', 'allowed', 'us', 'use', 'facility', 'warning', 'us', 'come', 'immediately', 'full', 'pm', 'rushed', 'hammam', 'surprise', 'one', 'even', 'pm', 'also', 'hammam', 'real', 'hammam', 'massage', 'offered', 'hammam', 'first', 'time', 'read', 'small', 'instructions', 'door', 'staff', 'useless', 'explain', 'properly', '“', 'li', 'neq', 'fini', 'toi…', 'alle', 'debrouille', 'salade', 'toi', 'meme', 'si', 'bruler', 'dans', 'la', 'chambre', 'chaude…', '”', 'also', 'ask', 'many', 'questions', 'possible', 'booking', 'massage', '’', 'go', 'name', 'bit', 'like', 'hammam', 'may', 'expect', 'experienced', 'booked', 'massage', 'based', 'name', 'also', 'done', 'staff', 'explain', 'massage', 'done', 'got', 'surprise', 'went', 'massage', 'change', 'expensive', 'massage', 'massage', 'worth', 'price', 'masseuse', 'played', 'hair', 'spreading', 'oil', 'front', 'proper', 'head', 'massage', 'wondered', 'trying', 'fool', 'someone', 'used', 'massage', 'spa', 'relaxation', 'room', 'massage', 'also', 'served', 'hot', 'green', 'tea', 'case', 'navasana', 'spa', 'shower', 'room', 'door', 'towel', 'water', 'overflowed', 'shower', 'cabin', 'good', 'wash', 'hair', 'could', 'ended', 'mini', 'swimming', 'pool', 'filled', 'shampoo', 'conditioner', 'bed', 'room', 'nice', 'comfortable', 'jacuzzi', 'lack', 'light', 'room', 'something', 'drops', 'take', 'mobile', 'phone', 'torch', 'look', 'electricity', 'toilet', 'reception', 'waited', 'minutes', 'one', 'solved', 'problem', 'electricity', 'mens', 'toilet', 'either', 'tourist', 'took', 'mobile', 'phone', 'torch', 'use', 'men', '’', 'toilet', 'enjoyed', 'stay', 'hotel', 'got', 'bad', 'service', 'lack', 'information', 'spa', 'information', 'ingredients', 'put', 'food', 'staff', 'spa', 'needs', 'proper', 'customer', 'care', 'training', 'productservices', 'offer', 'recall', 'name', 'staff', 'appreciated', 'cake', 'brought', 'us', 'celebrate', 'husbands', 'birthday', 'though', 'came', 'time', 'going', 'sleep', 'approx', 'pm', 'appreciated', 'effort', 'made', 'thank', 'staff', 'cake', 'come', 'early', 'upon', 'check', 'room', 'could', 'enjoyed', 'cake', 'moment', 'much', 'overall', 'good', 'hotel', 'improvements', 'made', 'keep', 'standard', 'since', 'beach', 'exactly', 'clean', 'swim', 'need', 'rely', 'facilities', 'offered', 'swimming', 'big', 'enough', 'accommodate', 'number', 'tourist', 'specially', 'find', 'kids', 'playing', 'balls', 'taking', 'spaces', 'finally', 'may', 'find', 'paying', 'nice', 'room', 'strolling', 'beach', 'good', 'thats', 'looking', 'good', 'like', 'activities', 'proper', 'facilities']
{'joy': 0.064426914, 'enjoy': 0.21253183, 'disgust': 0.010814132, 'happy': 0.09181011, 'sadness': 0.51131284, 'anger': 0.055588733, 'trust': 0.053515427}
trust
>>>>>> ['responding', 'great', 'hotel']
{'joy': 0.008053914, 'enjoy': 0.15135023, 'disgust': 0.00011693535, 'happy': 0.03629416, 'sadness': 0.7891963, 'anger': 0.009384074, 'trust': 0.0056044566}
trust
>>>>>> ['hotel', 'set', 'enchanting', 'cadre', 'although', 'requires', 'refurbishing', 'like', 'doors', 'drainage', 'system', 'service', 'excellent', 'top', 'management', 'mind', 'jarvin', 'utmost', 'please', 'guests', 'although', 'employees', 'require', 'training', 'grooming', 'food', 'varied', 'excellent', 'especially', 'mercado', 'would', 'recommend']
{'joy': 0.004336705, 'enjoy': 0.13266006, 'disgust': 3.9401904e-05, 'happy': 0.025243163, 'sadness': 0.829508, 'anger': 0.0053256354, 'trust': 0.0028870394}
trust
>>>>>> ['great', 'time']
{'joy': 0.003716217, 'enjoy': 0.124243096, 'disgust': 2.867168e-05, 'happy': 0.021728668, 'sadness': 0.8434635, 'anger': 0.0044140806, 'trust': 0.0024057592}
trust
>>>>>> ['suite', 'however', 'staff', 'main', 'bar', 'nice', 'spa', 'good', 'experience', 'therapeuts', 'talented', 'conclude', 'food', 'priority', 'dont', 'think', 'day', 'package', 'want', 'relax', 'good', 'time', 'kids', 'quite', 'good', 'deal']
{'joy': 0.0072312066, 'enjoy': 0.15095377, 'disgust': 0.00010101732, 'happy': 0.035764247, 'sadness': 0.7920288, 'anger': 0.008813921, 'trust': 0.0051070056}
trust

あなたが見ることができる、それはどこでも私の信頼」を与えている、しかし、私は、リストから最高スコアが表示されるようにしたい、私は私のコードで修正する必要が何をすべきか?

Shubhamシャルマ:

あなたは、使用しているmax辞書に機能をlabel_probs辞書でアルファベット順に最大のキーを返します。

所望の結果を達成するために、あなたがする必要があります、

交換してください:

print(max(label_probs))

と:

print(max(label_probs, key=lambda k: label_probs[k]))

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=16806&siteId=1