Git Product home page Git Product logo

Comments (2)

deven367 avatar deven367 commented on July 4, 2024 1

Thanks! I was able to resolve the issue :)

from declutr.

JohnGiorgi avatar JohnGiorgi commented on July 4, 2024

This typically happens because of an unsupported version of allennlp or transformers. I just tried the following in a colab notebook (following our embedding notebook) and it worked without issue:

!pip install -U "git+https://github.com/JohnGiorgi/DeCLUTR.git"

import torch
from declutr import Encoder

# This can be a path on disk to a model you have trained yourself OR
# the name of one of our pretrained models.
pretrained_model_or_path = "declutr-base"

# Prepare some text to embed
text = [
    "A smiling costumed woman is holding an umbrella.",
    "A happy woman in a fairy costume holds an umbrella.",
    "A soccer game with multiple males playing.",
    "Some men are playing a sport.",
]

# Embed the text
cuda_device = torch.cuda.current_device() if torch.cuda.is_available() else -1
encoder = Encoder(pretrained_model_or_path, cuda_device=cuda_device)
embeddings = encoder(text)

from scipy.spatial.distance import cosine

# Compute a semantic similarity via the cosine distance
semantic_sim = 1 - cosine(embeddings[0], embeddings[1])
print(semantic_sim)

If you don't need to use our Encoder object, you can use the model with sentence-transformer or transformers, in which case you can use the latest version of either library. See our embedding notebook.

from declutr.

Related Issues (20)

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.