Skip to content

Commit bc16e6e

Browse files
No public description
PiperOrigin-RevId: 701795491
1 parent 1cdc3eb commit bc16e6e

8 files changed

+69
-76
lines changed

tensorflow_text/core/kernels/constrained_sequence_kernel.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ namespace {
5757

5858
// Validate that a given constraint tensor is the proper shape (dimension
5959
// 2, with shape [num_states + 1, num_states + 1].
60-
tensorflow::Status ValidateConstraintTensor(const Tensor &tensor,
61-
const int num_states,
62-
const bool use_start_end_states,
63-
const string &name) {
60+
absl::Status ValidateConstraintTensor(const Tensor &tensor,
61+
const int num_states,
62+
const bool use_start_end_states,
63+
const string &name) {
6464
if (tensor.shape().dims() != 2) {
6565
return InvalidArgument(
6666
tensorflow::strings::StrCat(name, " must be of rank 2"));

tensorflow_text/core/kernels/mst_op_kernels.cc

+5-6
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ class MaxSpanningTreeOpKernel : public tensorflow::OpKernel {
8989
// Solve the batch of MST problems in parallel. Set a high cycles per unit
9090
// to encourage finer sharding.
9191
constexpr int64 kCyclesPerUnit = 1000 * 1000 * 1000;
92-
std::vector<tensorflow::Status> statuses(batch_size);
92+
std::vector<absl::Status> statuses(batch_size);
9393
context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor(
9494
batch_size, kCyclesPerUnit, [&](int64 begin, int64 end) {
9595
for (int64 problem = begin; problem < end; ++problem) {
9696
statuses[problem] = RunSolver(problem, num_nodes_b, scores_bxmxm,
9797
max_scores_b, argmax_sources_bxm);
9898
}
9999
});
100-
for (const tensorflow::Status &status : statuses) {
100+
for (const absl::Status &status : statuses) {
101101
OP_REQUIRES_OK(context, status);
102102
}
103103
}
@@ -112,10 +112,9 @@ class MaxSpanningTreeOpKernel : public tensorflow::OpKernel {
112112
// at index |problem| in |num_nodes_b| and |scores_bxmxm|. On success, sets
113113
// the values at index |problem| in |max_scores_b| and |argmax_sources_bxm|.
114114
// On error, returns non-OK.
115-
tensorflow::Status RunSolver(int problem, BatchedSizes num_nodes_b,
116-
BatchedScores scores_bxmxm,
117-
BatchedMaxima max_scores_b,
118-
BatchedSources argmax_sources_bxm) const {
115+
absl::Status RunSolver(int problem, BatchedSizes num_nodes_b,
116+
BatchedScores scores_bxmxm, BatchedMaxima max_scores_b,
117+
BatchedSources argmax_sources_bxm) const {
119118
// Check digraph size overflow.
120119
const int32 num_nodes = num_nodes_b(problem);
121120
const int32 input_dim = argmax_sources_bxm.dimension(1);

tensorflow_text/core/kernels/mst_solver.h

+9-10
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class MstSolver {
9090
// error. Discards existing state; call AddArc() and AddRoot() to add arcs
9191
// and root selections. If |forest| is true, then this solves for a maximum
9292
// spanning forest (i.e., a set of disjoint trees that span the digraph).
93-
tensorflow::Status Init(bool forest, Index num_nodes);
93+
absl::Status Init(bool forest, Index num_nodes);
9494

9595
// Adds an arc from the |source| node to the |target| node with the |score|.
9696
// The |source| and |target| must be distinct node indices in [0,n), and the
@@ -116,10 +116,10 @@ class MstSolver {
116116
//
117117
// NB: If multiple spanning trees achieve the maximum score, |argmax| will be
118118
// set to one of the maximal trees, but it is unspecified which one.
119-
tensorflow::Status Solve(absl::Span<Index> argmax);
119+
absl::Status Solve(absl::Span<Index> argmax);
120120

121121
// Convience method
122-
tensorflow::Status Solve(std::vector<Index>* argmax) {
122+
absl::Status Solve(std::vector<Index> *argmax) {
123123
return Solve(absl::MakeSpan(argmax->data(), argmax->size()));
124124
}
125125

@@ -235,12 +235,12 @@ class MstSolver {
235235
// phase finds the best inbound arc for each node, contracting cycles as they
236236
// are formed. Stops when every node has selected an inbound arc and there
237237
// are no cycles.
238-
tensorflow::Status ContractionPhase();
238+
absl::Status ContractionPhase();
239239

240240
// Runs the expansion phase of the solver, or returns non-OK on error. This
241241
// phase expands each contracted node, breaks cycles, and populates |argmax|
242242
// with the maximum spanning tree.
243-
tensorflow::Status ExpansionPhase(absl::Span<Index> argmax);
243+
absl::Status ExpansionPhase(absl::Span<Index> argmax);
244244

245245
// If true, solve for a spanning forest instead of a spanning tree.
246246
bool forest_ = false;
@@ -303,7 +303,7 @@ class MstSolver {
303303
// Implementation details below.
304304

305305
template <class Index, class Score>
306-
tensorflow::Status MstSolver<Index, Score>::Init(bool forest, Index num_nodes) {
306+
absl::Status MstSolver<Index, Score>::Init(bool forest, Index num_nodes) {
307307
if (num_nodes <= 0) {
308308
return tensorflow::errors::InvalidArgument("Non-positive number of nodes: ",
309309
num_nodes);
@@ -374,7 +374,7 @@ Score MstSolver<Index, Score>::RootScore(Index root) const {
374374
}
375375

376376
template <class Index, class Score>
377-
tensorflow::Status MstSolver<Index, Score>::Solve(absl::Span<Index> argmax) {
377+
absl::Status MstSolver<Index, Score>::Solve(absl::Span<Index> argmax) {
378378
MaybePenalizeRootScoresForTree();
379379
TF_RETURN_IF_ERROR(ContractionPhase());
380380
TF_RETURN_IF_ERROR(ExpansionPhase(argmax));
@@ -510,7 +510,7 @@ void MstSolver<Index, Score>::ContractCycle(Index node) {
510510
}
511511

512512
template <class Index, class Score>
513-
tensorflow::Status MstSolver<Index, Score>::ContractionPhase() {
513+
absl::Status MstSolver<Index, Score>::ContractionPhase() {
514514
// Skip the artificial root since it has no inbound arcs.
515515
for (Index target = 1; target < num_current_nodes_; ++target) {
516516
// Find the maximum inbound arc for the current |target|, if any.
@@ -541,8 +541,7 @@ tensorflow::Status MstSolver<Index, Score>::ContractionPhase() {
541541
}
542542

543543
template <class Index, class Score>
544-
tensorflow::Status MstSolver<Index, Score>::ExpansionPhase(
545-
absl::Span<Index> argmax) {
544+
absl::Status MstSolver<Index, Score>::ExpansionPhase(absl::Span<Index> argmax) {
546545
if (argmax.size() < num_original_nodes_) {
547546
return tensorflow::errors::InvalidArgument(
548547
"Argmax array too small: ", num_original_nodes_,

tensorflow_text/core/kernels/sentence_breaking_kernels.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct ErrorOptions {
8585
bool error_on_malformatting = false;
8686
};
8787

88-
Status GetErrorOptions(OpKernelConstruction* context, ErrorOptions* out) {
88+
absl::Status GetErrorOptions(OpKernelConstruction* context, ErrorOptions* out) {
8989
*out = ErrorOptions();
9090

9191
string error_policy;

tensorflow_text/core/kernels/sentence_breaking_utils.cc

+15-15
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ using ::tensorflow::Status;
2828
namespace tensorflow {
2929
namespace text {
3030

31-
Status UnicodeUtil::GetOneUChar(const absl::string_view& input,
32-
bool* has_more_than_one_char,
33-
UChar32* result) const {
31+
absl::Status UnicodeUtil::GetOneUChar(const absl::string_view& input,
32+
bool* has_more_than_one_char,
33+
UChar32* result) const {
3434
UErrorCode status = U_ZERO_ERROR;
3535
const char* source = input.data();
3636
const char* limit = input.data() + input.length();
@@ -54,8 +54,8 @@ Status UnicodeUtil::GetOneUChar(const absl::string_view& input,
5454
return absl::OkStatus();
5555
}
5656

57-
Status UnicodeUtil::IsTerminalPunc(const absl::string_view& input,
58-
bool* result) const {
57+
absl::Status UnicodeUtil::IsTerminalPunc(const absl::string_view& input,
58+
bool* result) const {
5959
*result = false;
6060
const auto& ellipsis_status = IsEllipsis(input, result);
6161
// If there was a error decoding, or if we found an ellipsis, then return.
@@ -89,8 +89,8 @@ Status UnicodeUtil::IsTerminalPunc(const absl::string_view& input,
8989
return absl::OkStatus();
9090
}
9191

92-
Status UnicodeUtil::IsClosePunc(const absl::string_view& input,
93-
bool* result) const {
92+
absl::Status UnicodeUtil::IsClosePunc(const absl::string_view& input,
93+
bool* result) const {
9494
*result = false;
9595
if (input == "''") {
9696
*result = true;
@@ -128,8 +128,8 @@ Status UnicodeUtil::IsClosePunc(const absl::string_view& input,
128128
return absl::OkStatus();
129129
}
130130

131-
Status UnicodeUtil::IsOpenParen(const absl::string_view& input,
132-
bool* result) const {
131+
absl::Status UnicodeUtil::IsOpenParen(const absl::string_view& input,
132+
bool* result) const {
133133
*result = false;
134134
bool has_more_than_one_char = false;
135135
UChar32 char_value;
@@ -155,8 +155,8 @@ Status UnicodeUtil::IsOpenParen(const absl::string_view& input,
155155
return absl::OkStatus();
156156
}
157157

158-
Status UnicodeUtil::IsCloseParen(const absl::string_view& input,
159-
bool* result) const {
158+
absl::Status UnicodeUtil::IsCloseParen(const absl::string_view& input,
159+
bool* result) const {
160160
*result = false;
161161
bool has_more_than_one_char = false;
162162
UChar32 char_value;
@@ -183,8 +183,8 @@ Status UnicodeUtil::IsCloseParen(const absl::string_view& input,
183183
return absl::OkStatus();
184184
}
185185

186-
Status UnicodeUtil::IsPunctuationWord(const absl::string_view& input,
187-
bool* result) const {
186+
absl::Status UnicodeUtil::IsPunctuationWord(const absl::string_view& input,
187+
bool* result) const {
188188
*result = false;
189189
bool has_more_than_one_char = false;
190190
UChar32 char_value;
@@ -213,8 +213,8 @@ Status UnicodeUtil::IsPunctuationWord(const absl::string_view& input,
213213
return absl::OkStatus();
214214
}
215215

216-
Status UnicodeUtil::IsEllipsis(const absl::string_view& input,
217-
bool* result) const {
216+
absl::Status UnicodeUtil::IsEllipsis(const absl::string_view& input,
217+
bool* result) const {
218218
*result = false;
219219
if (input == "...") {
220220
*result = true;

tensorflow_text/core/kernels/sentence_breaking_utils.h

+10-15
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,29 @@ class UnicodeUtil {
3333
explicit UnicodeUtil(UConverter* converter) : converter_(converter) {}
3434

3535
// Returns true iff a string is terminal punctuation.
36-
::tensorflow::Status IsTerminalPunc(const absl::string_view& input,
37-
bool* result) const;
36+
absl::Status IsTerminalPunc(const absl::string_view& input,
37+
bool* result) const;
3838

3939
// Returns true iff a string is close punctuation (close quote or close
4040
// paren).
41-
::tensorflow::Status IsClosePunc(const absl::string_view& input,
42-
bool* result) const;
41+
absl::Status IsClosePunc(const absl::string_view& input, bool* result) const;
4342

4443
// Returns true iff a string is an open paren.
45-
::tensorflow::Status IsOpenParen(const absl::string_view& input,
46-
bool* result) const;
44+
absl::Status IsOpenParen(const absl::string_view& input, bool* result) const;
4745

4846
// Returns true iff a string is a close paren.
49-
::tensorflow::Status IsCloseParen(const absl::string_view& input,
50-
bool* result) const;
47+
absl::Status IsCloseParen(const absl::string_view& input, bool* result) const;
5148

5249
// Returns true iff a word is made of punctuation characters only.
53-
::tensorflow::Status IsPunctuationWord(const absl::string_view& input,
54-
bool* result) const;
50+
absl::Status IsPunctuationWord(const absl::string_view& input,
51+
bool* result) const;
5552

5653
// Returns true iff a string is an ellipsis token ("...").
57-
::tensorflow::Status IsEllipsis(const absl::string_view& input,
58-
bool* result) const;
54+
absl::Status IsEllipsis(const absl::string_view& input, bool* result) const;
5955

6056
private:
61-
::tensorflow::Status GetOneUChar(const absl::string_view&,
62-
bool* has_more_than_one_char,
63-
UChar32* result) const;
57+
absl::Status GetOneUChar(const absl::string_view&,
58+
bool* has_more_than_one_char, UChar32* result) const;
6459

6560
// not owned. mutable because UConverter contains some internal options and
6661
// buffer.

tensorflow_text/core/kernels/sentence_fragmenter.cc

+13-13
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ bool IsPeriodSeparatedAcronym(const Token &token) {
4343

4444
// Returns true iff the token can appear after a space in a sentence-terminal
4545
// token sequence.
46-
Status SpaceAllowedBeforeToken(const UnicodeUtil *util, const Token &token,
47-
bool *result) {
46+
absl::Status SpaceAllowedBeforeToken(const UnicodeUtil *util,
47+
const Token &token, bool *result) {
4848
const tstring &word = token.word();
4949
bool is_ellipsis = false;
5050
TF_RETURN_IF_ERROR(util->IsEllipsis(word, &is_ellipsis));
@@ -77,8 +77,8 @@ class SentenceFragmenter::FragmentBoundaryMatch {
7777

7878
// Follows the state transition for the token at the given index. Returns
7979
// true for success, or false if there was no valid transition.
80-
Status Advance(const UnicodeUtil *util, const Document &document, int index,
81-
bool *result) {
80+
absl::Status Advance(const UnicodeUtil *util, const Document &document,
81+
int index, bool *result) {
8282
const Token &token = document.tokens()[index];
8383
const tstring &word = token.word();
8484
bool no_transition = false;
@@ -176,7 +176,7 @@ class SentenceFragmenter::FragmentBoundaryMatch {
176176
int limit_index_ = -1;
177177
};
178178

179-
Status SentenceFragmenter::FindFragments(
179+
absl::Status SentenceFragmenter::FindFragments(
180180
std::vector<SentenceFragment> *result) {
181181
// Partition tokens into sentence fragments.
182182
for (int i_start = 0; i_start < document_->tokens().size();) {
@@ -215,7 +215,7 @@ Status SentenceFragmenter::FindFragments(
215215
// scan "!!!" looking for a fragment boundary. Since we failed to find one last
216216
// time, we'll fail again this time and therefore continue past "y" to find the
217217
// next boundary. We will not try to scan "!!!" a third time.
218-
Status SentenceFragmenter::FindNextFragmentBoundary(
218+
absl::Status SentenceFragmenter::FindNextFragmentBoundary(
219219
int i_start, SentenceFragmenter::FragmentBoundaryMatch *result) const {
220220
FragmentBoundaryMatch current_match;
221221
FragmentBoundaryMatch previous_match;
@@ -276,8 +276,8 @@ Status SentenceFragmenter::FindNextFragmentBoundary(
276276
// punctuation that turns out not to be a sentence boundary, e.g.,
277277
// "Yahoo! (known for search, etc.) blah", but this is not expected to happen
278278
// often.
279-
Status SentenceFragmenter::UpdateLatestOpenParenForFragment(int i_start,
280-
int i_end) {
279+
absl::Status SentenceFragmenter::UpdateLatestOpenParenForFragment(int i_start,
280+
int i_end) {
281281
for (int i = i_end; i > i_start; --i) {
282282
const auto &token = document_->tokens()[i - 1];
283283
bool is_open_paren = false;
@@ -293,7 +293,7 @@ Status SentenceFragmenter::UpdateLatestOpenParenForFragment(int i_start,
293293
return absl::OkStatus();
294294
}
295295

296-
Status SentenceFragmenter::FillInFragmentFields(
296+
absl::Status SentenceFragmenter::FillInFragmentFields(
297297
int i_start, const FragmentBoundaryMatch &match,
298298
SentenceFragment *fragment) const {
299299
// Set the fragment's boundaries.
@@ -343,7 +343,7 @@ Status SentenceFragmenter::FillInFragmentFields(
343343
//
344344
// We treat "!" as the first terminal punctuation mark; the ellipsis acts as
345345
// left context.
346-
Status SentenceFragmenter::GetAdjustedFirstTerminalPuncIndex(
346+
absl::Status SentenceFragmenter::GetAdjustedFirstTerminalPuncIndex(
347347
const FragmentBoundaryMatch &match, int *result) const {
348348
// Get terminal punctuation span.
349349
int i1 = match.first_terminal_punc_index();
@@ -385,7 +385,7 @@ Status SentenceFragmenter::GetAdjustedFirstTerminalPuncIndex(
385385
// true sentence boundary. The terminal punctuation mark must be unambiguous
386386
// (.!?), as ambiguous ones (ellipsis/emoticon) do not necessarily imply a
387387
// sentence boundary.
388-
Status SentenceFragmenter::HasUnattachableTerminalPunc(
388+
absl::Status SentenceFragmenter::HasUnattachableTerminalPunc(
389389
const FragmentBoundaryMatch &match, bool *result) const {
390390
*result = false;
391391
// Get terminal punctuation span.
@@ -415,8 +415,8 @@ Status SentenceFragmenter::HasUnattachableTerminalPunc(
415415
return absl::OkStatus();
416416
}
417417

418-
Status SentenceFragmenter::HasCloseParen(const FragmentBoundaryMatch &match,
419-
bool *result) const {
418+
absl::Status SentenceFragmenter::HasCloseParen(
419+
const FragmentBoundaryMatch &match, bool *result) const {
420420
*result = false;
421421
// Get close punctuation span.
422422
int i1 = match.first_close_punc_index();

tensorflow_text/core/kernels/sentence_fragmenter.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class SentenceFragmenter {
170170

171171
// Finds sentence fragments in the [start_, limit_) range of the associated
172172
// document.
173-
::tensorflow::Status FindFragments(std::vector<SentenceFragment> *result);
173+
absl::Status FindFragments(std::vector<SentenceFragment> *result);
174174

175175
private:
176176
// State for matching a fragment-boundary regexp against a token sequence.
@@ -180,33 +180,33 @@ class SentenceFragmenter {
180180
// Matches a fragment-boundary regexp against the tokens starting at
181181
// 'i_start'. Returns the longest match found; will be non-empty as long as
182182
// 'i_start' was not already at the end of the associated token range.
183-
::tensorflow::Status FindNextFragmentBoundary(
184-
int i_start, FragmentBoundaryMatch *result) const;
183+
absl::Status FindNextFragmentBoundary(int i_start,
184+
FragmentBoundaryMatch *result) const;
185185

186186
// Updates 'latest_open_paren_is_sentential_' for the tokens in the given
187187
// fragment.
188-
::tensorflow::Status UpdateLatestOpenParenForFragment(int i_start, int i_end);
188+
absl::Status UpdateLatestOpenParenForFragment(int i_start, int i_end);
189189

190190
// Populates a sentence fragment with the tokens from 'i_start' to the end
191191
// of the given FragmentBoundaryMatch.
192-
::tensorflow::Status FillInFragmentFields(int i_start,
193-
const FragmentBoundaryMatch &match,
194-
SentenceFragment *fragment) const;
192+
absl::Status FillInFragmentFields(int i_start,
193+
const FragmentBoundaryMatch &match,
194+
SentenceFragment *fragment) const;
195195

196196
// Returns the adjusted first terminal punctuation index in a
197197
// FragmentBoundaryMatch.
198-
::tensorflow::Status GetAdjustedFirstTerminalPuncIndex(
198+
absl::Status GetAdjustedFirstTerminalPuncIndex(
199199
const FragmentBoundaryMatch &match, int *result) const;
200200

201201
// Returns true iff a FragmentBoundaryMatch has an "unattachable" terminal
202202
// punctuation mark.
203-
::tensorflow::Status HasUnattachableTerminalPunc(
204-
const FragmentBoundaryMatch &match, bool *result) const;
203+
absl::Status HasUnattachableTerminalPunc(const FragmentBoundaryMatch &match,
204+
bool *result) const;
205205

206206
// Returns true iff a FragmentBoundaryMatch has a close paren in its closing
207207
// punctuation.
208-
::tensorflow::Status HasCloseParen(const FragmentBoundaryMatch &match,
209-
bool *result) const;
208+
absl::Status HasCloseParen(const FragmentBoundaryMatch &match,
209+
bool *result) const;
210210

211211
// Whether the latest open paren seen so far appears to be sentence-initial.
212212
// See UpdateLatestOpenParenForFragment() in the .cc file for details.

0 commit comments

Comments
 (0)