Giter Club home page Giter Club logo

Comments (3)

BM-K avatar BM-K commented on July 29, 2024 3

학습된 파일이 다음과 같이 위치하도록 해주세요

output/training_sts/0_Transformer/result.pt

from kosentencebert-skt.

kdh4672 avatar kdh4672 commented on July 29, 2024
        from sentence_transformers import SentenceTransformer, util
        import numpy as np

        model_path = './output/training_sts'

        embedder = SentenceTransformer(model_path)

        # Corpus with example sentences
        corpus = ['한 남자가 음식을 먹는다.',
                '한 남자가 빵 한 조각을 먹는다.',
                '그 여자가 아이를 돌본다.',
                '한 남자가 말을 탄다.',
                '한 여자가 바이올린을 연주한다.',
                '두 남자가 수레를 숲 속으로 밀었다.',
                '한 남자가 담으로 싸인 땅에서 백마를 타고 있다.',
                '원숭이 한 마리가 드럼을 연주한다.',
                '치타 한 마리가 먹이 뒤에서 달리고 있다.']

        corpus_embeddings = embedder.encode(corpus, convert_to_tensor=True)

        # Query sentences:
        queries = ['한 남자가 파스타를 먹는다.',
                '고릴라 의상을 입은 누군가가 드럼을 연주하고 있다.',
                '치타가 들판을 가로 질러 먹이를 쫓는다.']

        # Find the closest 5 sentences of the corpus for each query sentence based on cosine similarity
        top_k = 5
        for query in queries:
                query_embedding = embedder.encode(query, convert_to_tensor=True)
                cos_scores = util.pytorch_cos_sim(query_embedding, corpus_embeddings)[0]
                cos_scores = cos_scores.cpu()

                #We use np.argpartition, to only partially sort the top_k results
                top_results = np.argpartition(-cos_scores, range(top_k))[0:top_k]

                print("\n\n======================\n\n")
                print("Query:", query)
                print("\nTop 5 most similar sentences in corpus:")

                for idx in top_results[0:top_k]:
                        print(corpus[idx].strip(), "(Score: %.4f)" % (cos_scores[idx]))
        

제가 사용한 코드입니다.

from kosentencebert-skt.

kdh4672 avatar kdh4672 commented on July 29, 2024

감사합니다 해결되었습니다!

from kosentencebert-skt.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.