Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pythainlp/cli/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 = [
Expand Down
11 changes: 5 additions & 6 deletions pythainlp/tools/misspell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
"ผปแอิืทมใฝ",
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@
requirements = [
"backports.zoneinfo; python_version<'3.9'",
"requests>=2.31",
PYYAML,
PANDAS,
NUMPY,
"tzdata; sys_platform == 'win32'",
]

Expand Down
Loading