ManInTheMirror

须得荣辱不惊,

方可坚毅成道!

再,

此乃一薄情寡义之秋

独守义

孤痴情

是故孤独凄凉而悲楚

至竟春秋女子之事

大可不必太过挂怀

当是时唯女子最冷!

然涂鸦纵酒

也是豪放厥词

问心何属

念父知音

爱母至亲

恋自镜中人

俊逸青年

应笑我多情!

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13750068/viewspace-730765/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/13750068/viewspace-730765/

为下面的代码 添加 Hugging Face 国内镜像源 https://hf-mirror.com , 在代码中设置即可 : from sentence_transformers.cross_encoder import CrossEncoder # 1. Load a pretrained CrossEncoder model model = CrossEncoder("cross-encoder/stsb-distilroberta-base") # We want to compute the similarity between the query sentence... query = "A man is eating pasta." # ... and all sentences in the corpus corpus = [ "A man is eating food.", "A man is eating a piece of bread.", "The girl is carrying a baby.", "A man is riding a horse.", "A woman is playing violin.", "Two men pushed carts through the woods.", "A man is riding a white horse on an enclosed ground.", "A monkey is playing drums.", "A cheetah is running behind its prey.", ] # 2. We rank all sentences in the corpus for the query ranks = model.rank(query, corpus) # Print the scores print("Query: ", query) for rank in ranks: print(f"{rank['score']:.2f}\t{corpus[rank['corpus_id']]}") """ Query: A man is eating pasta. 0.67 A man is eating food. 0.34 A man is eating a piece of bread. 0.08 A man is riding a horse. 0.07 A man is riding a white horse on an enclosed ground. 0.01 The girl is carrying a baby. 0.01 Two men pushed carts through the woods. 0.01 A monkey is playing drums. 0.01 A woman is playing violin. 0.01 A cheetah is running behind its prey. """ # 3. Alternatively, you can also manually compute the score between two sentences import numpy as np sentence_combinations = [[query, sentence] for sentence in corpus] scores = model.predict(sentence_combinations) # Sort the scores in decreasing order to get the corpus indices ranked_indices = np.argsort(scores)[::-1] print("Scores:", scores) print("Indices:", ranked_indices) """ Scores: [0.6732372, 0.34102544, 0.00542465, 0.07569341, 0.00525378, 0.00536814, 0.06676237, 0.00534825, 0.00516717] Indices: [0 1 3 6 2 5 7 4 8] """
03-11
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值