[Python] word/ sentence similarities

Discussão em 'Python' iniciado por Stack, Fevereiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to find if a given word/ set of words are similar to a definition.

    Example - Definition - "vegetarian User"

    Now, if I want to check a set of sentences like below

    sentences = ['vegetarian User',
    'user sometimes eats chicken',
    'user is vegetarian',
    'user only eats fruits',
    'user likes fish']


    I tried using some sentence transformer like below

    model = SentenceTransformer("all-mpnet-base-v2")
    embeddings = model.encode(sentences)
    similarities = model.similarity(embeddings,embeddings)
    print(similarities)


    But this is not giving me expected results.

    What is the best approach to achieve results like below?

    [False,True,True,False]


    Is it doable with nlp/ some other technique?

    Continue reading...

Compartilhe esta Página