import os os.environ['KMP_DUPLICATE_LIB_OK']='True' # 方法1 from modelscope.pipelines import pipeline from modelscope.utils.constant import Tasks # damo/nlp_corom_sentence-embedding_chinese-base-ecom # damo/nlp_corom_sentence-embedding_chinese-base # damo/nlp_corom_sentence-embedding_chinese-tiny model_id = "damo/nlp_corom_sentence-embedding_chinese-base-ecom" # model_id = "damo/nlp_gpt3_text-generation_chinese-base" pipeline_se = pipeline(Tasks.sentence_embedding, model=model_id, max_length=1024) # # 当输入包含“soure_sentence”与“sentences_to_compare”时,会输出source_sentence中首个句子与sentences_to_compare中每个句子的向量表示,以及source_sentence中首个句子与sentences_to_compare中每个句子的相似度。 sentences_to_compare = [ '''根据不同的季度、网红热点信息主动给用户推送热门景区和景点的游玩信息''', '''开发一个在线商品销售商城,提供旅游路线上的相关特产和旅游商品的查阅及下单功能''', '''推送相关旅游产品折扣信息以及景区景点举办的篝火晚会、烟花盛宴等活动内容,可通过线下报名参与。''' ] inputs = { "source_sentence": [ # '''模块功能:提供商家信息查询和种植区域查询等功能。功能描述:商家信息包括名称、地址、法人、联系方式、经营范围、投资规模等,种植区域主要是指丽水香茶种植区域的面积、位置、高程等信息,政府工作人员可根据多个查询条件完成上述信息的查询。''' '''展示乡村游中相关乡村举办的庆典活动,包含庆典举办时间、内容等''' ], "sentences_to_compare": sentences_to_compare } result = pipeline_se(input=inputs) print(result["scores"]) arr = result["scores"] max_value = max(arr) max_index = arr.index(max_value) print("最大值:", max_value) print("最相识内容:", sentences_to_compare[max_index]) # # #