Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions tensorflow_addons/text/cc/kernels/skip_gram_kernels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,17 @@ class SkipGramGenerateCandidatesOp : public OpKernel {
OP_REQUIRES_OK(context, context->input("max_skips", &max_skips_tensor));
const int max_skips = *(max_skips_tensor->scalar<int>().data());

const Tensor& input_check = context->input(0);
OP_REQUIRES(
context, TensorShapeUtils::IsVector(input_check.shape()),
errors::InvalidArgument("input_tensor must be of rank 1"));

OP_REQUIRES(
context, min_skips >= 0 && max_skips >= 0,
errors::InvalidArgument("Both min_skips and max_skips must be >= 0."));
OP_REQUIRES(context, min_skips <= max_skips,
errors::InvalidArgument("min_skips must be <= max_skips."));
OP_REQUIRES(
context, min_skips <= max_skips,
errors::InvalidArgument("min_skips must be <= max_skips."));

const Tensor* start_tensor;
OP_REQUIRES_OK(context, context->input("start", &start_tensor));
Expand Down
14 changes: 5 additions & 9 deletions tensorflow_addons/text/python/skip_gram_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,11 @@ def test_skip_gram_sample_errors(self):
text.skip_gram_sample(input_tensor, min_skips=min_skips,
max_skips=max_skips)

#########################################

# FIXME: Why is this not failing?
# with self.assertRaises(ValueError):
# invalid_tensor = constant_op.constant([[b"the"], [b"quick"],
# [b"brown"]])
# text.skip_gram_sample(invalid_tensor)

#########################################
# Eager tensor must be rank 1
with self.assertRaises(errors.InvalidArgumentError):
invalid_tensor = constant_op.constant([[b"the"], [b"quick"],
[b"brown"]])
text.skip_gram_sample(invalid_tensor)

# vocab_freq_table must be provided if vocab_min_count,
# vocab_subsampling, or corpus_size is specified.
Expand Down