__init__.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_layoutlm": ["LayoutLMConfig", "LayoutLMOnnxConfig"],
  24. "tokenization_layoutlm": ["LayoutLMTokenizer"],
  25. }
  26. try:
  27. if not is_tokenizers_available():
  28. raise OptionalDependencyNotAvailable()
  29. except OptionalDependencyNotAvailable:
  30. pass
  31. else:
  32. _import_structure["tokenization_layoutlm_fast"] = ["LayoutLMTokenizerFast"]
  33. try:
  34. if not is_torch_available():
  35. raise OptionalDependencyNotAvailable()
  36. except OptionalDependencyNotAvailable:
  37. pass
  38. else:
  39. _import_structure["modeling_layoutlm"] = [
  40. "LayoutLMForMaskedLM",
  41. "LayoutLMForSequenceClassification",
  42. "LayoutLMForTokenClassification",
  43. "LayoutLMForQuestionAnswering",
  44. "LayoutLMModel",
  45. "LayoutLMPreTrainedModel",
  46. ]
  47. try:
  48. if not is_tf_available():
  49. raise OptionalDependencyNotAvailable()
  50. except OptionalDependencyNotAvailable:
  51. pass
  52. else:
  53. _import_structure["modeling_tf_layoutlm"] = [
  54. "TFLayoutLMForMaskedLM",
  55. "TFLayoutLMForSequenceClassification",
  56. "TFLayoutLMForTokenClassification",
  57. "TFLayoutLMForQuestionAnswering",
  58. "TFLayoutLMMainLayer",
  59. "TFLayoutLMModel",
  60. "TFLayoutLMPreTrainedModel",
  61. ]
  62. if TYPE_CHECKING:
  63. from .configuration_layoutlm import LayoutLMConfig, LayoutLMOnnxConfig
  64. from .tokenization_layoutlm import LayoutLMTokenizer
  65. try:
  66. if not is_tokenizers_available():
  67. raise OptionalDependencyNotAvailable()
  68. except OptionalDependencyNotAvailable:
  69. pass
  70. else:
  71. from .tokenization_layoutlm_fast import LayoutLMTokenizerFast
  72. try:
  73. if not is_torch_available():
  74. raise OptionalDependencyNotAvailable()
  75. except OptionalDependencyNotAvailable:
  76. pass
  77. else:
  78. from .modeling_layoutlm import (
  79. LayoutLMForMaskedLM,
  80. LayoutLMForQuestionAnswering,
  81. LayoutLMForSequenceClassification,
  82. LayoutLMForTokenClassification,
  83. LayoutLMModel,
  84. LayoutLMPreTrainedModel,
  85. )
  86. try:
  87. if not is_tf_available():
  88. raise OptionalDependencyNotAvailable()
  89. except OptionalDependencyNotAvailable:
  90. pass
  91. else:
  92. from .modeling_tf_layoutlm import (
  93. TFLayoutLMForMaskedLM,
  94. TFLayoutLMForQuestionAnswering,
  95. TFLayoutLMForSequenceClassification,
  96. TFLayoutLMForTokenClassification,
  97. TFLayoutLMMainLayer,
  98. TFLayoutLMModel,
  99. TFLayoutLMPreTrainedModel,
  100. )
  101. else:
  102. import sys
  103. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)