MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / LoadFromFile

Method LoadFromFile

tensorflow/core/kernels/range_sampler.cc:284–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

282}
283
284Status FixedUnigramSampler::LoadFromFile(Env* env, const string& vocab_file,
285 float distortion) {
286 std::unique_ptr<RandomAccessFile> file;
287 TF_RETURN_IF_ERROR(env->NewRandomAccessFile(vocab_file, &file));
288
289 io::InputBuffer in(file.get(), 262144 /*bytes*/);
290 string line;
291 int32 word_id = weights_.size();
292 while (in.ReadLine(&line).ok()) {
293 // The vocabulary file should be in csv like format, with the last
294 // field the weight associated with the word.
295 std::vector<string> cols = str_util::Split(line, ',');
296 if (cols.empty()) continue;
297 // Skip entries that do not belong to this shard.
298 if (word_id % num_shards_ == shard_) {
299 float w = 0.0;
300 if (!strings::safe_strtof(cols.at(cols.size() - 1), &w)) {
301 return errors::InvalidArgument("Wrong vocabulary format at line: ",
302 line);
303 }
304 w = std::pow(w, distortion);
305 total_weight_ += w;
306 weights_.push_back(w);
307 }
308 ++word_id;
309 }
310 return Status::OK();
311}
312
313void FixedUnigramSampler::LoadFromUnigrams(const std::vector<float>& unigrams,
314 float distortion) {

Callers

nothing calls this directly

Calls 12

safe_strtofFunction · 0.85
InvalidArgumentFunction · 0.85
SplitClass · 0.70
powClass · 0.70
NewRandomAccessFileMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45
okMethod · 0.45
ReadLineMethod · 0.45
emptyMethod · 0.45
atMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected