Commit ec21fb7b authored by Dero Gharibian's avatar Dero Gharibian Committed by Hongkun Yu
Browse files

Migrate from std::string to tensorflow::tstring. (#7830)

Note that during the transition period tstring is typedef'ed to
std::string.

See: https://github.com/tensorflow/community/pull/91
parent 2b21ab96
...@@ -209,14 +209,14 @@ class SkipgramWord2vecOp : public OpKernel { ...@@ -209,14 +209,14 @@ class SkipgramWord2vecOp : public OpKernel {
vocab_size_ = static_cast<int32>(1 + ordered.size()); vocab_size_ = static_cast<int32>(1 + ordered.size());
Tensor word(DT_STRING, TensorShape({vocab_size_})); Tensor word(DT_STRING, TensorShape({vocab_size_}));
Tensor freq(DT_INT32, TensorShape({vocab_size_})); Tensor freq(DT_INT32, TensorShape({vocab_size_}));
word.flat<string>()(0) = "UNK"; word.flat<tstring>()(0) = "UNK";
static const int32 kUnkId = 0; static const int32 kUnkId = 0;
std::unordered_map<string, int32> word_id; std::unordered_map<string, int32> word_id;
int64 total_counted = 0; int64 total_counted = 0;
for (std::size_t i = 0; i < ordered.size(); ++i) { for (std::size_t i = 0; i < ordered.size(); ++i) {
const auto& w = ordered[i].first; const auto& w = ordered[i].first;
auto id = i + 1; auto id = i + 1;
word.flat<string>()(id) = w; word.flat<tstring>()(id) = w;
auto word_count = ordered[i].second; auto word_count = ordered[i].second;
freq.flat<int32>()(id) = word_count; freq.flat<int32>()(id) = word_count;
total_counted += word_count; total_counted += word_count;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment