diff --git a/pythainlp/cli/benchmark.py b/pythainlp/cli/benchmark.py index b1b2cb7c4..68d59c10d 100644 --- a/pythainlp/cli/benchmark.py +++ b/pythainlp/cli/benchmark.py @@ -8,10 +8,8 @@ import json import os -import yaml from pythainlp import cli -from pythainlp.benchmarks import word_tokenization from pythainlp.tools import safe_print @@ -88,6 +86,14 @@ def __init__(self, name, argv): % (args.input_file, args.test_file, len(actual)) ) + try: + import yaml + from pythainlp.benchmarks import word_tokenization + except ImportError: + raise ImportError( + "Please install the extra dependencies `benchmarks` to use this command by running `pip install pythainlp[benchmarks]`" + ) + df_raw = word_tokenization.benchmark(expected, actual) columns = [ diff --git a/pythainlp/tools/misspell.py b/pythainlp/tools/misspell.py index c940d2929..a5fa84208 100644 --- a/pythainlp/tools/misspell.py +++ b/pythainlp/tools/misspell.py @@ -4,7 +4,8 @@ # SPDX-License-Identifier: Apache-2.0 from typing import List -import numpy as np +import math +import random THAI_CHARACTERS_WITHOUT_SHIFT = [ "ผปแอิืทมใฝ", @@ -126,10 +127,8 @@ def misspell(sentence: str, ratio: float = 0.05): # output: ภาษาไทยปรากฏครั้งแรกในกุทธศักราช 1727 """ - num_misspells = np.floor(len(sentence) * ratio).astype(int) - positions = np.random.choice( - len(sentence), size=num_misspells, replace=False - ) + num_misspells = math.floor(len(sentence) * ratio) + positions = random.sample(range(len(sentence)), k=num_misspells) # convert strings to array of characters misspelled = list(sentence) @@ -138,7 +137,7 @@ def misspell(sentence: str, ratio: float = 0.05): if potential_candidates is None: continue - candidate = np.random.choice(potential_candidates) + candidate = random.choice(potential_candidates) misspelled[pos] = candidate diff --git a/setup.py b/setup.py index 86dc13857..0b3951cd1 100644 --- a/setup.py +++ b/setup.py @@ -45,9 +45,6 @@ requirements = [ "backports.zoneinfo; python_version<'3.9'", "requests>=2.31", - PYYAML, - PANDAS, - NUMPY, "tzdata; sys_platform == 'win32'", ]