Skip to content

Commit

Permalink
Fixes a bug which prevented the fragmenter from being able to process…
Browse files Browse the repository at this point in the history
… tensors with a rank > 1.

PiperOrigin-RevId: 348670292
  • Loading branch information
broken committed Dec 22, 2020
1 parent c1239e7 commit d10d1cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def break_sentences_with_offsets(self, doc):
end: A int64 `RaggedTensor` of shape [batch, (num_sentences)]
where each entry is the exclusive ending byte offset of a sentence.
"""
if isinstance(doc, ragged_tensor.RaggedTensor):
if doc.shape.ndims > 1:
doc = ragged_tensor.RaggedTensor.from_tensor(doc)
doc = doc.flat_values

# Run sentence fragmenter op v2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class SentenceFragmenterTestCasesV2(test.TestCase, parameterized.TestCase):
b"Welcome to the U.S.", b"don't be surprised."
], [b"I.B.M.", b"yo"]],
),
dict(
test_description="Test when rank > 1.",
doc=[["Welcome to the U.S. don't be surprised."], ["I.B.M. yo"]],
expected_fragment_text=[[
b"Welcome to the U.S.", b"don't be surprised."
], [b"I.B.M.", b"yo"]],
),
dict(
test_description="Test semicolons",
doc=["Welcome to the US; don't be surprised."],
Expand Down

0 comments on commit d10d1cd

Please sign in to comment.