GithubHelp home page GithubHelp logo

Comments (3)

gongel avatar gongel commented on May 30, 2024

你好,请贴下代码。

from paddlenlp.

ZTurboX avatar ZTurboX commented on May 30, 2024

你好,请贴下代码。

`query_cls_embedding = self.get_pooled_embedding(
query_input_ids, query_token_type_ids, query_position_ids, query_attention_mask
)

    title_cls_embedding = self.get_pooled_embedding(
        title_input_ids, title_token_type_ids, title_position_ids, title_attention_mask
    )

    cosine_sim = paddle.matmul(query_cls_embedding, title_cls_embedding, transpose_y=True)

    # Subtract margin from all positive samples cosine_sim()
    margin_diag = paddle.full(shape=[query_cls_embedding.shape[0]], fill_value=self.margin, dtype=cosine_sim.dtype)

    cosine_sim = cosine_sim - paddle.diag(margin_diag)

    # Scale cosine to ease training converge
    cosine_sim *= self.scale

    labels = paddle.arange(0, query_cls_embedding.shape[0], dtype="int64")
    labels = paddle.reshape(labels, shape=[-1, 1])`

from paddlenlp.

w5688414 avatar w5688414 commented on May 30, 2024

也不是不可以,主要是query和title的向量一般已经normalize了,不需要除以分母

from paddlenlp.

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.