Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cosine similarity为什么会出现负值?用sentence_transformers的util.cos_sim()调用uer/sbert-base-chinese-nli #344

Open
peter65374 opened this issue Oct 27, 2022 · 0 comments

Comments

@peter65374
Copy link

跑个unit test的时候例句得到负值的cosine similarity,这个是怎么回事?是util.cos_sim函数的问题么?
image

        try:
            logger.info("START - 加载 Sen-SIMILARITY 模型")
            # model = SentenceTransformer('distiluse-base-multilingual-cased-v2')
            model = SentenceTransformer('uer/sbert-base-chinese-nli')  # uer model中文性能好很多。
            logger.info("FINISH - 加载 Sen-SIMILARITY 模型")
        except Exception as e:
            logger.warning("Exception thrown during Intialising pretrained model.", e)
       try:
            # Compute embedding for both lists
            embedding1 = model.encode(sentence1)
            embedding2 = model.encode(sentence2)

            #Compute cosine-similarities
            simcos = util.cos_sim(embedding1, embedding2)

            return simcos
        except Exception as e:
            logger.warning("Exception thrown during get similarity", e)
            return None`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant