|
| 1 | +# Copyright 2017-2025 John Snow Labs |
| 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 | +import unittest |
| 15 | + |
| 16 | +import pytest |
| 17 | + |
| 18 | +from sparknlp.annotator import * |
| 19 | +from test.util import SparkSessionForTest |
| 20 | + |
| 21 | + |
| 22 | +@pytest.mark.fast |
| 23 | +class NerDLApproachTestSpec(unittest.TestCase): |
| 24 | + def setUp(self): |
| 25 | + self.spark = SparkSessionForTest.spark |
| 26 | + |
| 27 | + def test_setters(self): |
| 28 | + ner_approach = ( |
| 29 | + NerDLApproach() |
| 30 | + .setLr(0.01) |
| 31 | + .setPo(0.005) |
| 32 | + .setBatchSize(16) |
| 33 | + .setDropout(0.01) |
| 34 | + .setGraphFolder("graph_folder") |
| 35 | + .setConfigProtoBytes([]) |
| 36 | + .setUseContrib(False) |
| 37 | + .setEnableMemoryOptimizer(True) |
| 38 | + .setIncludeConfidence(True) |
| 39 | + .setIncludeAllConfidenceScores(True) |
| 40 | + .setUseBestModel(True) |
| 41 | + .setPrefetchBatches(20) |
| 42 | + .setOptimizePartitioning(True) |
| 43 | + ) |
| 44 | + |
| 45 | + # Check param map |
| 46 | + param_map = ner_approach.extractParamMap() |
| 47 | + self.assertEqual(param_map[ner_approach.lr], 0.01) |
| 48 | + self.assertEqual(param_map[ner_approach.po], 0.005) |
| 49 | + self.assertEqual(param_map[ner_approach.batchSize], 16) |
| 50 | + self.assertEqual(param_map[ner_approach.dropout], 0.01) |
| 51 | + self.assertEqual(param_map[ner_approach.graphFolder], "graph_folder") |
| 52 | + self.assertEqual(param_map[ner_approach.configProtoBytes], []) |
| 53 | + self.assertEqual(param_map[ner_approach.useContrib], False) |
| 54 | + self.assertEqual(param_map[ner_approach.enableMemoryOptimizer], True) |
| 55 | + self.assertEqual(param_map[ner_approach.includeConfidence], True) |
| 56 | + self.assertEqual(param_map[ner_approach.includeAllConfidenceScores], True) |
| 57 | + self.assertEqual(param_map[ner_approach.useBestModel], True) |
| 58 | + self.assertEqual(param_map[ner_approach.prefetchBatches], 20) |
| 59 | + self.assertEqual(param_map[ner_approach.optimizePartitioning], True) |
0 commit comments