__init__.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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_tf_available,
  19. is_tokenizers_available,
  20. is_torch_available,
  21. )
  22. _import_structure = {
  23. "configuration_dpr": ["DPRConfig"],
  24. "tokenization_dpr": [
  25. "DPRContextEncoderTokenizer",
  26. "DPRQuestionEncoderTokenizer",
  27. "DPRReaderOutput",
  28. "DPRReaderTokenizer",
  29. ],
  30. }
  31. try:
  32. if not is_tokenizers_available():
  33. raise OptionalDependencyNotAvailable()
  34. except OptionalDependencyNotAvailable:
  35. pass
  36. else:
  37. _import_structure["tokenization_dpr_fast"] = [
  38. "DPRContextEncoderTokenizerFast",
  39. "DPRQuestionEncoderTokenizerFast",
  40. "DPRReaderTokenizerFast",
  41. ]
  42. try:
  43. if not is_torch_available():
  44. raise OptionalDependencyNotAvailable()
  45. except OptionalDependencyNotAvailable:
  46. pass
  47. else:
  48. _import_structure["modeling_dpr"] = [
  49. "DPRContextEncoder",
  50. "DPRPretrainedContextEncoder",
  51. "DPRPreTrainedModel",
  52. "DPRPretrainedQuestionEncoder",
  53. "DPRPretrainedReader",
  54. "DPRQuestionEncoder",
  55. "DPRReader",
  56. ]
  57. try:
  58. if not is_tf_available():
  59. raise OptionalDependencyNotAvailable()
  60. except OptionalDependencyNotAvailable:
  61. pass
  62. else:
  63. _import_structure["modeling_tf_dpr"] = [
  64. "TFDPRContextEncoder",
  65. "TFDPRPretrainedContextEncoder",
  66. "TFDPRPretrainedQuestionEncoder",
  67. "TFDPRPretrainedReader",
  68. "TFDPRQuestionEncoder",
  69. "TFDPRReader",
  70. ]
  71. if TYPE_CHECKING:
  72. from .configuration_dpr import DPRConfig
  73. from .tokenization_dpr import (
  74. DPRContextEncoderTokenizer,
  75. DPRQuestionEncoderTokenizer,
  76. DPRReaderOutput,
  77. DPRReaderTokenizer,
  78. )
  79. try:
  80. if not is_tokenizers_available():
  81. raise OptionalDependencyNotAvailable()
  82. except OptionalDependencyNotAvailable:
  83. pass
  84. else:
  85. from .tokenization_dpr_fast import (
  86. DPRContextEncoderTokenizerFast,
  87. DPRQuestionEncoderTokenizerFast,
  88. DPRReaderTokenizerFast,
  89. )
  90. try:
  91. if not is_torch_available():
  92. raise OptionalDependencyNotAvailable()
  93. except OptionalDependencyNotAvailable:
  94. pass
  95. else:
  96. from .modeling_dpr import (
  97. DPRContextEncoder,
  98. DPRPretrainedContextEncoder,
  99. DPRPreTrainedModel,
  100. DPRPretrainedQuestionEncoder,
  101. DPRPretrainedReader,
  102. DPRQuestionEncoder,
  103. DPRReader,
  104. )
  105. try:
  106. if not is_tf_available():
  107. raise OptionalDependencyNotAvailable()
  108. except OptionalDependencyNotAvailable:
  109. pass
  110. else:
  111. from .modeling_tf_dpr import (
  112. TFDPRContextEncoder,
  113. TFDPRPretrainedContextEncoder,
  114. TFDPRPretrainedQuestionEncoder,
  115. TFDPRPretrainedReader,
  116. TFDPRQuestionEncoder,
  117. TFDPRReader,
  118. )
  119. else:
  120. import sys
  121. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)