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.

text_classification.py 1.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. /**
  3. * Copyright 2020 Tianshu AI Platform. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. * =============================================================
  17. */
  18. """
  19. from entrance.executor import classify_by_textcnn as classify
  20. def _init():
  21. print('init classify_obj')
  22. global classify_obj
  23. classify_obj = classify.TextCNNClassifier() # label_log
  24. def _classification(text_path_list, id_list, label_list):
  25. """Perform automatic text classification task."""
  26. textnum = len(text_path_list)
  27. batched_num = ((textnum - 1) // classify.BATCH_SIZE + 1) * classify.BATCH_SIZE
  28. for i in range(batched_num - textnum):
  29. text_path_list.append(text_path_list[0])
  30. id_list.append(id_list[0])
  31. annotations = classify_obj.inference(text_path_list, id_list, label_list) #
  32. return annotations[0:textnum]
  33. if __name__ == "__main__":
  34. test_len = 22
  35. _init()
  36. ans = _classification(["dubhe-dev/dataset/2738/origin/32_3_ts1607326726114630.txt"] * test_len, [1] * test_len,
  37. [111, 112])
  38. print(ans)
  39. print(len(ans))

一站式算法开发平台、高性能分布式深度学习框架、先进算法模型库、视觉模型炼知平台、数据可视化分析平台等一系列平台及工具,在模型高效分布式训练、数据处理和可视分析、模型炼知和轻量化等技术上形成独特优势,目前已在产学研等各领域近千家单位及个人提供AI应用赋能

Contributors (1)