__init__.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. # Copyright 2020 The HuggingFace Team. 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. from typing import TYPE_CHECKING
  15. from ...utils import (
  16. OptionalDependencyNotAvailable,
  17. _LazyModule,
  18. is_flax_available,
  19. is_tensorflow_text_available,
  20. is_tf_available,
  21. is_tokenizers_available,
  22. is_torch_available,
  23. )
  24. _import_structure = {
  25. "configuration_bert": ["BertConfig", "BertOnnxConfig"],
  26. "tokenization_bert": ["BasicTokenizer", "BertTokenizer", "WordpieceTokenizer"],
  27. }
  28. try:
  29. if not is_tokenizers_available():
  30. raise OptionalDependencyNotAvailable()
  31. except OptionalDependencyNotAvailable:
  32. pass
  33. else:
  34. _import_structure["tokenization_bert_fast"] = ["BertTokenizerFast"]
  35. try:
  36. if not is_torch_available():
  37. raise OptionalDependencyNotAvailable()
  38. except OptionalDependencyNotAvailable:
  39. pass
  40. else:
  41. _import_structure["modeling_bert"] = [
  42. "BertForMaskedLM",
  43. "BertForMultipleChoice",
  44. "BertForNextSentencePrediction",
  45. "BertForPreTraining",
  46. "BertForQuestionAnswering",
  47. "BertForSequenceClassification",
  48. "BertForTokenClassification",
  49. "BertLayer",
  50. "BertLMHeadModel",
  51. "BertModel",
  52. "BertPreTrainedModel",
  53. "load_tf_weights_in_bert",
  54. ]
  55. try:
  56. if not is_tf_available():
  57. raise OptionalDependencyNotAvailable()
  58. except OptionalDependencyNotAvailable:
  59. pass
  60. else:
  61. _import_structure["modeling_tf_bert"] = [
  62. "TFBertEmbeddings",
  63. "TFBertForMaskedLM",
  64. "TFBertForMultipleChoice",
  65. "TFBertForNextSentencePrediction",
  66. "TFBertForPreTraining",
  67. "TFBertForQuestionAnswering",
  68. "TFBertForSequenceClassification",
  69. "TFBertForTokenClassification",
  70. "TFBertLMHeadModel",
  71. "TFBertMainLayer",
  72. "TFBertModel",
  73. "TFBertPreTrainedModel",
  74. ]
  75. try:
  76. if not is_tensorflow_text_available():
  77. raise OptionalDependencyNotAvailable()
  78. except OptionalDependencyNotAvailable:
  79. pass
  80. else:
  81. _import_structure["tokenization_bert_tf"] = ["TFBertTokenizer"]
  82. try:
  83. if not is_flax_available():
  84. raise OptionalDependencyNotAvailable()
  85. except OptionalDependencyNotAvailable:
  86. pass
  87. else:
  88. _import_structure["modeling_flax_bert"] = [
  89. "FlaxBertForCausalLM",
  90. "FlaxBertForMaskedLM",
  91. "FlaxBertForMultipleChoice",
  92. "FlaxBertForNextSentencePrediction",
  93. "FlaxBertForPreTraining",
  94. "FlaxBertForQuestionAnswering",
  95. "FlaxBertForSequenceClassification",
  96. "FlaxBertForTokenClassification",
  97. "FlaxBertModel",
  98. "FlaxBertPreTrainedModel",
  99. ]
  100. if TYPE_CHECKING:
  101. from .configuration_bert import BertConfig, BertOnnxConfig
  102. from .tokenization_bert import BasicTokenizer, BertTokenizer, WordpieceTokenizer
  103. try:
  104. if not is_tokenizers_available():
  105. raise OptionalDependencyNotAvailable()
  106. except OptionalDependencyNotAvailable:
  107. pass
  108. else:
  109. from .tokenization_bert_fast import BertTokenizerFast
  110. try:
  111. if not is_torch_available():
  112. raise OptionalDependencyNotAvailable()
  113. except OptionalDependencyNotAvailable:
  114. pass
  115. else:
  116. from .modeling_bert import (
  117. BertForMaskedLM,
  118. BertForMultipleChoice,
  119. BertForNextSentencePrediction,
  120. BertForPreTraining,
  121. BertForQuestionAnswering,
  122. BertForSequenceClassification,
  123. BertForTokenClassification,
  124. BertLayer,
  125. BertLMHeadModel,
  126. BertModel,
  127. BertPreTrainedModel,
  128. load_tf_weights_in_bert,
  129. )
  130. try:
  131. if not is_tf_available():
  132. raise OptionalDependencyNotAvailable()
  133. except OptionalDependencyNotAvailable:
  134. pass
  135. else:
  136. from .modeling_tf_bert import (
  137. TFBertEmbeddings,
  138. TFBertForMaskedLM,
  139. TFBertForMultipleChoice,
  140. TFBertForNextSentencePrediction,
  141. TFBertForPreTraining,
  142. TFBertForQuestionAnswering,
  143. TFBertForSequenceClassification,
  144. TFBertForTokenClassification,
  145. TFBertLMHeadModel,
  146. TFBertMainLayer,
  147. TFBertModel,
  148. TFBertPreTrainedModel,
  149. )
  150. try:
  151. if not is_tensorflow_text_available():
  152. raise OptionalDependencyNotAvailable()
  153. except OptionalDependencyNotAvailable:
  154. pass
  155. else:
  156. from .tokenization_bert_tf import TFBertTokenizer
  157. try:
  158. if not is_flax_available():
  159. raise OptionalDependencyNotAvailable()
  160. except OptionalDependencyNotAvailable:
  161. pass
  162. else:
  163. from .modeling_flax_bert import (
  164. FlaxBertForCausalLM,
  165. FlaxBertForMaskedLM,
  166. FlaxBertForMultipleChoice,
  167. FlaxBertForNextSentencePrediction,
  168. FlaxBertForPreTraining,
  169. FlaxBertForQuestionAnswering,
  170. FlaxBertForSequenceClassification,
  171. FlaxBertForTokenClassification,
  172. FlaxBertModel,
  173. FlaxBertPreTrainedModel,
  174. )
  175. else:
  176. import sys
  177. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)