Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cubert是否支持多分类? #17

Closed
xuqiang opened this issue May 22, 2019 · 6 comments · Fixed by #19
Closed

cubert是否支持多分类? #17

xuqiang opened this issue May 22, 2019 · 6 comments · Fixed by #19
Assignees
Labels
bug Something isn't working

Comments

@xuqiang
Copy link
Contributor

xuqiang commented May 22, 2019

bert做四分类任务,希望输出每个instance在4个分类上的概率,试了下cuBERT_LOGITS,发现结果和tf预测的结果不一致。问下cubert是否支持这个功能(每个instance在各个分类上的概率)?

@levyfan
Copy link
Contributor

levyfan commented May 23, 2019

支持的

@levyfan
Copy link
Contributor

levyfan commented May 23, 2019

可以把测试文件+模型发给我们看下

@xuqiang
Copy link
Contributor Author

xuqiang commented May 23, 2019

可以把测试文件+模型发给我们看下

方便留个联系方式吗?qq或者微信

测试程序是改了下 test/cuBERT_test.cpp

`

TEST_F(cuBertTest, compute) {
int max_batch_size = 32;
int batch_size = 1;
int seq_length = 32;
int num_label = 13;

int input_ids[batch_size * seq_length] = { 101, 5933, 3697, 6656, 4285, 2165, 7735, 6478, 2090, 3365, 8222, 102, 5933, 3697, 6656, 4285, 2165, 7735, 6478, 2090, 3365, 8222, 113, 2682, 2661, 114, 102, 0, 0, 0, 0, 0 };
int8_t input_mask[batch_size * seq_length] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
int8_t segment_ids[batch_size * seq_length] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
float logits[batch_size * num_label];
//random_input(input_ids, input_mask, segment_ids, batch_size * seq_length);

void* model = cuBERT_open("modelb.pb", max_batch_size, seq_length, 12, 12);
cuBERT_compute(model, batch_size, input_ids, input_mask, segment_ids, logits);
cuBERT_close(model);

for(int i = 0; i < num_label; ++i) {
    std::cout << i << " " << logits[i] << std::endl;
}

for(int i = 0; i < num_label; ++i) {
    std::cout << logits[i] << ", ";
}
std::cout << std::endl;

}
`

logits的值看着不对。

我看cubert的源代码,看着也不太能支持多分类

https://github.com/zhihu/cuBERT/blob/master/src/cuBERT/Bert.cpp#L51

this->_logits = static_cast<T *>(cuBERT::malloc(sizeof(T) * max_batch_size));

@levyfan
Copy link
Contributor

levyfan commented May 23, 2019

哦,这里可能是个 bug,少乘了 num_labels,包括下面拷贝也是

cuBERT::memcpyAsync(logits, _logits, sizeof(T) * batch_size, 2, streamId);

QQ: 372684992

@levyfan levyfan added the bug Something isn't working label May 23, 2019
@levyfan levyfan self-assigned this May 23, 2019
@xuqiang
Copy link
Contributor Author

xuqiang commented May 23, 2019

修了下这个问题,回头我发个pull request。

@xuqiang
Copy link
Contributor Author

xuqiang commented May 28, 2019

#20

@levyfan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants