第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用張量流的句子相似度

使用張量流的句子相似度

夢(mèng)里花落0921 2023-07-27 09:34:22
我試圖確定一個(gè)句子和其他句子之間的語(yǔ)義相似性,如下所示:import tensorflow as tfimport tensorflow_hub as hubimport numpy as npimport os, sysfrom sklearn.metrics.pairwise import cosine_similarity# get cosine similairty matrixdef cos_sim(input_vectors):    similarity = cosine_similarity(input_vectors)    return similarity# get topN similar sentencesdef get_top_similar(sentence, sentence_list, similarity_matrix, topN):    # find the index of sentence in list    index = sentence_list.index(sentence)    # get the corresponding row in similarity matrix    similarity_row = np.array(similarity_matrix[index, :])    # get the indices of top similar    indices = similarity_row.argsort()[-topN:][::-1]    return [sentence_list[i] for i in indices]module_url = "https://tfhub.dev/google/universal-sentence-encoder/2" #@param ["https://tfhub.dev/google/universal-sentence-encoder/2", "https://tfhub.dev/google/universal-sentence-encoder-large/3"]# Import the Universal Sentence Encoder's TF Hub moduleembed = hub.Module(module_url)# Reduce logging output.tf.logging.set_verbosity(tf.logging.ERROR)sentences_list = [    # phone related    'My phone is slow',    'My phone is not good',    'I need to change my phone. It does not work well',    'How is your phone?',    # age related    'What is your age?',    'How old are you?',    'I am 10 years old',    # weather related    'It is raining today',    'Would it be sunny tomorrow?',    'The summers are here.']with tf.Session() as session:  session.run([tf.global_variables_initializer(), tf.tables_initializer()])  sentences_embeddings = session.run(embed(sentences_list))similarity_matrix = cos_sim(np.array(sentences_embeddings))sentence = "It is raining today"top_similar = get_top_similar(sentence, sentences_list, similarity_matrix, 3)# printing the list using loop for x in range(len(top_similar)):     print(top_similar[x])#view raw
查看完整描述

1 回答

?
慕雪6442864

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

問(wèn)題的原因似乎是 TF2 不支持 hub 型號(hào)。


這很簡(jiǎn)單,但是您是否嘗試過(guò)禁用tensorflow版本2的行為?


import tensorflow.compat.v1 as tf

tf.disable_v2_behavior()

此命令將禁用 TensorFlow 2 行為,但仍然可能會(huì)出現(xiàn)一些與導(dǎo)入模塊和圖形相關(guān)的錯(cuò)誤。


然后嘗試下面的命令。


!pip install --upgrade tensorflow==1.15


import tensorflow as tf

print(tf.__version__)


查看完整回答
反對(duì) 回復(fù) 2023-07-27
  • 1 回答
  • 0 關(guān)注
  • 133 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)