kwangka / simcse_unsup Goto Github PK
View Code? Open in Web Editor NEW中文无监督SimCSE Pytorch实现
License: MIT License
中文无监督SimCSE Pytorch实现
License: MIT License
你好,请教下 y_true = idxs + 1 - idxs % 2 * 2
是怎么来的,这一块构建数据和构建y_true 的时候没看懂
请问下,train_unsup.py里的compute_loss,构造的是负样本的损失函数吗?
''
你好,请问你的代码有在中文的句子相似度数据集上进行过评测吗
from datasets import load_dataset
这里报错,查了一下,没有datasets这个module
你好,看了你的代码受益匪浅,但是在代码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基本一致,是这么理解吗
你好,我想请问一下,test_unsup.py里面 simcse_model = "./model/batch-1400"是从哪来的
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]是完全一样的,所以想请教下您的随机输出是怎么实现的?
你好,
训练代码里面没有load_dataset接口啊
in test_unsup.py line 24
simcse.build_index(n_list=1024)
should be
simcse.build_index(nlist=1024)
您好,我直接运行代码,loss一直是0,您那儿出现这种情况了吗
您好,我想请问一下参数设置问题,参数设置都是默认的吗,训练了多少个epoch才能达到你的测试结果呢?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.