You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_embedding.py 2.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  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. """ test_embedding """
  16. import numpy as np
  17. import pytest
  18. from mindspore.model_zoo.Bert_NEZHA import EmbeddingLookup, EmbeddingPostprocessor
  19. from mindspore import Tensor
  20. from mindspore import dtype as mstype
  21. from ..ut_filter import non_graph_engine
  22. @non_graph_engine
  23. def test_check_embedding_lookup_1():
  24. m = EmbeddingLookup(vocab_size=32000,
  25. embedding_size=768,
  26. embedding_shape=[1, 128, 768],
  27. use_one_hot_embeddings=False)
  28. m(Tensor(np.ones([128]), mstype.int32))
  29. @non_graph_engine
  30. def test_check_embedding_lookup_2():
  31. m = EmbeddingLookup(vocab_size=32000,
  32. embedding_size=768,
  33. embedding_shape=[1, 128, 768],
  34. use_one_hot_embeddings=True)
  35. m(Tensor(np.ones([128]), mstype.int32))
  36. @non_graph_engine
  37. def test_check_embedding_lookup_3():
  38. m = EmbeddingLookup(vocab_size=32000,
  39. embedding_size=768,
  40. embedding_shape=[1, 128, 768],
  41. use_one_hot_embeddings=True,
  42. initializer_range=0.01)
  43. m(Tensor(np.ones([128]), mstype.int32))
  44. @non_graph_engine
  45. def test_embedding_post_1():
  46. m = EmbeddingPostprocessor(embedding_size=768,
  47. embedding_shape=[1, 128, 768],
  48. use_token_type=True)
  49. m(Tensor(np.ones([128]), mstype.int32), Tensor(np.ones([1, 128, 768]), mstype.float32))
  50. @non_graph_engine
  51. def test_embedding_post_2():
  52. m = EmbeddingPostprocessor(embedding_size=768,
  53. embedding_shape=[1, 128, 768],
  54. use_token_type=True,
  55. initializer_range=0.3)
  56. m(Tensor(np.ones([128]), mstype.int32), Tensor(np.ones([1, 128, 768]), mstype.float32))

MindSpore is a new open source deep learning training/inference framework that could be used for mobile, edge and cloud scenarios.