| 323 | |
| 324 | |
| 325 | def assert_rank(tensor, expected_rank, name=None): |
| 326 | if name is None: |
| 327 | name = tensor.name |
| 328 | |
| 329 | expected_rank_dict = {} |
| 330 | if isinstance(expected_rank, six.integer_types): |
| 331 | expected_rank_dict[expected_rank] = True |
| 332 | else: |
| 333 | for x in expected_rank: |
| 334 | expected_rank_dict[x] = True |
| 335 | |
| 336 | actual_rank = tensor.shape.ndims |
| 337 | if actual_rank not in expected_rank_dict: |
| 338 | scope_name = tf.get_variable_scope().name |
| 339 | raise ValueError( |
| 340 | "For the tensor `%s` in scope `%s`, the actual rank " |
| 341 | "`%d` (shape = %s) is not equal to the expected rank `%s`" % |
| 342 | (name, scope_name, actual_rank, str(tensor.shape), str(expected_rank))) |
| 343 | |
| 344 | def ft_bert(inputs, |
| 345 | encoder_args, |