Git Product home page Git Product logo

Comments (3)

thibault-formal avatar thibault-formal commented on June 6, 2024

Hi @orionw
If you only have a handful of documents, I guess you can just keep document representations in memory and directly compute dot products (i.e., ranking scores) with query vectors.

from splade.

orionw avatar orionw commented on June 6, 2024

Thanks @thibault-formal!

Sorry to ask a potentially naive question, but I want to make sure I am using SPLADE correctly. Is it valid to literally just take the dot product between the two representations or am I missing any important postprocessing steps in SPLADE?

E.g. is this correct to calculate the score by taking the simple dot product?

doc = "this is a test document"
q = "test document"

### from inference_splade.ipynb code ###
import torch
from transformers import AutoModelForMaskedLM, AutoTokenizer
from splade.models.transformer_rep import Splade
model_type_or_dir = "naver/splade-cocondenser-ensembledistil"
model = Splade(model_type_or_dir, agg="max")
model.eval()
tokenizer = AutoTokenizer.from_pretrained(model_type_or_dir)

with torch.no_grad():
    doc_rep = model(d_kwargs=tokenizer(doc, return_tensors="pt"))["d_rep"].squeeze()  
    #### new: compute the query representation ####
    q_rep = model(d_kwargs=tokenizer(q, return_tensors="pt"))["d_rep"].squeeze()  

#### new: compute the score ####
score = torch.dot(doc_rep, q_rep)

Thanks again for your time!

from splade.

thibault-formal avatar thibault-formal commented on June 6, 2024

hi @orionw ,
sorry for the late reply!
yes, it's perfectly correct

I close the issue -- feel free to re-open it!

best
Thibault

from splade.

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.