Giter Club home page Giter Club logo

simcse_unsup's People

Contributors

kwangka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

simcse_unsup's Issues

请教一个问题

请问下,train_unsup.py里的compute_loss,构造的是负样本的损失函数吗?

评测指标

你好,请问你的代码有在中文的句子相似度数据集上进行过评测吗

SimCSERetrieval.py 中encode_file() 存在不足

你好,看了你的代码受益匪浅,但是在代码SimCSERetrieval.py 中encode_file() 有一些问题如下:

  if len(texts) >= self.batch_size:
      vecs = self.encode_batch(texts)
      vecs = vecs / vecs.norm(dim=1, keepdim=True)
      all_texts.extend(texts)
      all_ids.extend(idxs)
      all_vecs.append(vecs.cpu())
      texts = []
      idxs = []

如果 fname中的样本数N, N%self.batch_size = d,那么会遗漏d个样本。
我在测试中使用样本数为:
N = 559
batch_size = 64
得到all_vecs.shape[0]=512

有监督部分的理解

请教一下,我看了simcse原作者代码,感觉有监督部分就是和sentence bert的multiNegativeRankingLoss基本一致,是这么理解吗

怎样实现随机输出

import torch
import torch.nn as nn
import torch.nn.functional as F
from transformers import BertTokenizer,BertModel,BertConfig

tokenizer = BertTokenizer.from_pretrained("bert-base-chinese")
batch_x = tokenizer(["**人民公安大学年硕士研究生目录及书目","**人民公安大学年硕士研究生目录及书目"], return_tensors="pt", padding=True, truncation=True, max_length=128)

class SimCSE(nn.Module):
    def __init__(self, pretrained="bert-base-chinese", pool_type="pooler", dropout_prob=0.3):
        super().__init__()
        conf = BertConfig.from_pretrained(pretrained)
        conf.attention_probs_dropout_prob = dropout_prob
        conf.hidden_dropout_prob = dropout_prob
        self.encoder = BertModel.from_pretrained(pretrained, config=conf)
        assert pool_type in ["cls", "pooler"], "invalid pool_type: %s" % pool_type
        self.pool_type = pool_type

    def forward(self, input_ids, attention_mask, token_type_ids):
        output = self.encoder(input_ids,
                              attention_mask=attention_mask,
                              token_type_ids=token_type_ids)
        if self.pool_type == "cls":
            output = output[0][:, 0]
        elif self.pool_type == "pooler":
            output = output[1]
        return output

model = SimCSE()
pred = model(input_ids = batch_x["input_ids"],attention_mask=batch_x["attention_mask"],token_type_ids=batch_x["token_type_ids"])

您好,我按照这样的思路输入两次,但是最后输出的pred[0]和pred[1]是完全一样的,所以想请教下您的随机输出是怎么实现的?

param name error

in test_unsup.py line 24
simcse.build_index(n_list=1024)
should be
simcse.build_index(nlist=1024)

LOSS is always 0.0000

您好,我直接运行代码,loss一直是0,您那儿出现这种情况了吗

训练参数设置

您好,我想请问一下参数设置问题,参数设置都是默认的吗,训练了多少个epoch才能达到你的测试结果呢?

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.