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

Function Eval

tensorflow/lite/models/smartreply/ops/normalize.cc:58–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56static const int32_t kMaxInputChars = 300;
57
58TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
59 tflite::StringRef input = tflite::GetString(GetInput(context, node, 0), 0);
60
61 string result(absl::AsciiStrToLower(absl::string_view(input.str, input.len)));
62 absl::StripAsciiWhitespace(&result);
63 // Do not remove commas, semi-colons or colons from the sentences as they can
64 // indicate the beginning of a new clause.
65 RE2::GlobalReplace(&result, kPunctuationsRegex, "");
66 RE2::GlobalReplace(&result, "\\s('t|'nt|n't|'d|'ll|'s|'m|'ve|'re)([\\s,;:/])",
67 "\\1\\2");
68 RE2::GlobalReplace(&result, "\\s('t|'nt|n't|'d|'ll|'s|'m|'ve|'re)$", "\\1");
69 for (auto iter = kRegexTransforms->begin(); iter != kRegexTransforms->end();
70 iter++) {
71 RE2::GlobalReplace(&result, iter->first, iter->second);
72 }
73
74 // Treat questions & interjections as special cases.
75 RE2::GlobalReplace(&result, "([?])+", "\\1");
76 RE2::GlobalReplace(&result, "([!])+", "\\1");
77 RE2::GlobalReplace(&result, "([^?!]+)([?!])", "\\1 \\2 ");
78 RE2::GlobalReplace(&result, "([?!])([?!])", "\\1 \\2");
79
80 RE2::GlobalReplace(&result, "[\\s,:;\\-&'\"]+$", "");
81 RE2::GlobalReplace(&result, "^[\\s,:;\\-&'\"]+", "");
82 absl::StripAsciiWhitespace(&result);
83
84 // Add start and end token.
85 // Truncate input to maximum allowed size.
86 if (result.length() <= kMaxInputChars) {
87 absl::StrAppend(&result, " ", kEndToken);
88 } else {
89 result = result.substr(0, kMaxInputChars);
90 }
91 result = absl::StrCat(kStartToken, " ", result);
92
93 tflite::DynamicBuffer buf;
94 buf.AddString(result.data(), result.length());
95 buf.WriteToTensorAsVector(GetOutput(context, node, 0));
96 return kTfLiteOk;
97}
98
99} // namespace normalize
100

Callers

nothing calls this directly

Calls 12

GetStringFunction · 0.85
GetInputFunction · 0.85
string_viewClass · 0.85
GetOutputFunction · 0.85
AddStringMethod · 0.80
WriteToTensorAsVectorMethod · 0.80
StrAppendFunction · 0.50
StrCatFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
lengthMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected