亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

品類檢測。

品類檢測。

慕田峪9158850 2023-01-04 11:28:22
我已經使用此代碼進行類別檢測..import numpy as np# Words -> categorycategories = {word: key for key, words in data.items() for word in words}# Load the whole embedding matrixembeddings_index = {}with open('glove.6B.100d.txt', encoding="utf8") as f:  for line in f:    values = line.split()    word = values[0]    embed = np.array(values[1:], dtype=np.float32)    embeddings_index[word] = embedprint('Loaded %s word vectors.' % len(embeddings_index))# Embeddings for available wordsdata_embeddings = {key: value for key, value in embeddings_index.items() if key in categories.keys()}# Processing the querydef process(query):  query_embed = embeddings_index[query]  scores = {}  for word, embed in data_embeddings.items():    category = categories[word]    dist = query_embed.dot(embed)    dist /= len(data[category])    scores[category] = scores.get(category, 0) + dist  return scores# Testingprint(process('pizza'))輸出{'service': 6.385544379552205, 'ambiance': 3.5752111077308655, 'Food': 12.912149047851562}有沒有辦法讓我只獲得最準確的類別,比如食物??
查看完整描述

1 回答

?
藍山帝景

TA貢獻1843條經驗 獲得超7個贊

def process(query):

  query_embed = embeddings_index[query]

  scores = {}

  for word, embed in data_embeddings.items():

    category = categories[word]

    dist = query_embed.dot(embed)

    dist /= len(data[category])

    scores[category] = scores.get(category, 0) + dist

  return max(scores, key=scores.get)

你可以用max()這個。這將返回最大值的鍵名。


查看完整回答
反對 回復 2023-01-04
  • 1 回答
  • 0 關注
  • 79 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號