• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow/core/framework/op.h"
17 #include "tensorflow/core/framework/shape_inference.h"
18 
19 namespace tensorflow {
20 REGISTER_OP("SkipGramGenerateCandidates")
21     .Input("input_tensor: T")
22     .Input("min_skips: int32")
23     .Input("max_skips: int32")
24     .Input("start: int32")
25     .Input("limit: int32")
26     .Input("emit_self_as_target: bool")
27     .Output("tokens: T")
28     .Output("labels: T")
29     .Attr("T: type")
30     // The seed attributes are needed by GuardedPhiloxRandom
31     .Attr("seed: int = 0")
32     .Attr("seed2: int = 0")
33     .SetIsStateful()
__anon1ca0b1550102(shape_inference::InferenceContext* c) 34     .SetShapeFn([](shape_inference::InferenceContext* c) {
35       shape_inference::ShapeHandle unused;
36       // input_tensor must be of rank-1.
37       TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &unused));
38       // All other args must be scalar.
39       TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 0, &unused));
40       TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 0, &unused));
41       TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 0, &unused));
42       TF_RETURN_IF_ERROR(c->WithRank(c->input(4), 0, &unused));
43 
44       // Due to possible randomness in selecting skips, we only know that the
45       // outputs will be of rank-1, but not their sizes.
46       c->set_output(0, c->Vector(c->UnknownDim()));
47       c->set_output(1, c->Vector(c->UnknownDim()));
48       return Status::OK();
49     })
50     .Doc(R"doc(
51 Generates skip-gram token and label paired Tensors from the input tensor.
52 See docs for the public-facing skip_gram_sample() Python op for more details.
53 )doc");
54 }  // namespace tensorflow
55