__init__.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # Copyright 2022 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. is_vision_available,
  22. )
  23. _import_structure = {
  24. "configuration_layoutlmv3": [
  25. "LayoutLMv3Config",
  26. "LayoutLMv3OnnxConfig",
  27. ],
  28. "processing_layoutlmv3": ["LayoutLMv3Processor"],
  29. "tokenization_layoutlmv3": ["LayoutLMv3Tokenizer"],
  30. }
  31. try:
  32. if not is_tokenizers_available():
  33. raise OptionalDependencyNotAvailable()
  34. except OptionalDependencyNotAvailable:
  35. pass
  36. else:
  37. _import_structure["tokenization_layoutlmv3_fast"] = ["LayoutLMv3TokenizerFast"]
  38. try:
  39. if not is_torch_available():
  40. raise OptionalDependencyNotAvailable()
  41. except OptionalDependencyNotAvailable:
  42. pass
  43. else:
  44. _import_structure["modeling_layoutlmv3"] = [
  45. "LayoutLMv3ForQuestionAnswering",
  46. "LayoutLMv3ForSequenceClassification",
  47. "LayoutLMv3ForTokenClassification",
  48. "LayoutLMv3Model",
  49. "LayoutLMv3PreTrainedModel",
  50. ]
  51. try:
  52. if not is_tf_available():
  53. raise OptionalDependencyNotAvailable()
  54. except OptionalDependencyNotAvailable:
  55. pass
  56. else:
  57. _import_structure["modeling_tf_layoutlmv3"] = [
  58. "TFLayoutLMv3ForQuestionAnswering",
  59. "TFLayoutLMv3ForSequenceClassification",
  60. "TFLayoutLMv3ForTokenClassification",
  61. "TFLayoutLMv3Model",
  62. "TFLayoutLMv3PreTrainedModel",
  63. ]
  64. try:
  65. if not is_vision_available():
  66. raise OptionalDependencyNotAvailable()
  67. except OptionalDependencyNotAvailable:
  68. pass
  69. else:
  70. _import_structure["feature_extraction_layoutlmv3"] = ["LayoutLMv3FeatureExtractor"]
  71. _import_structure["image_processing_layoutlmv3"] = ["LayoutLMv3ImageProcessor"]
  72. if TYPE_CHECKING:
  73. from .configuration_layoutlmv3 import (
  74. LayoutLMv3Config,
  75. LayoutLMv3OnnxConfig,
  76. )
  77. from .processing_layoutlmv3 import LayoutLMv3Processor
  78. from .tokenization_layoutlmv3 import LayoutLMv3Tokenizer
  79. try:
  80. if not is_tokenizers_available():
  81. raise OptionalDependencyNotAvailable()
  82. except OptionalDependencyNotAvailable:
  83. pass
  84. else:
  85. from .tokenization_layoutlmv3_fast import LayoutLMv3TokenizerFast
  86. try:
  87. if not is_torch_available():
  88. raise OptionalDependencyNotAvailable()
  89. except OptionalDependencyNotAvailable:
  90. pass
  91. else:
  92. from .modeling_layoutlmv3 import (
  93. LayoutLMv3ForQuestionAnswering,
  94. LayoutLMv3ForSequenceClassification,
  95. LayoutLMv3ForTokenClassification,
  96. LayoutLMv3Model,
  97. LayoutLMv3PreTrainedModel,
  98. )
  99. try:
  100. if not is_tf_available():
  101. raise OptionalDependencyNotAvailable()
  102. except OptionalDependencyNotAvailable:
  103. pass
  104. else:
  105. from .modeling_tf_layoutlmv3 import (
  106. TFLayoutLMv3ForQuestionAnswering,
  107. TFLayoutLMv3ForSequenceClassification,
  108. TFLayoutLMv3ForTokenClassification,
  109. TFLayoutLMv3Model,
  110. TFLayoutLMv3PreTrainedModel,
  111. )
  112. try:
  113. if not is_vision_available():
  114. raise OptionalDependencyNotAvailable()
  115. except OptionalDependencyNotAvailable:
  116. pass
  117. else:
  118. from .feature_extraction_layoutlmv3 import LayoutLMv3FeatureExtractor
  119. from .image_processing_layoutlmv3 import LayoutLMv3ImageProcessor
  120. else:
  121. import sys
  122. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)