Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove include_original_token_probability key from typo noise config #93

Merged
merged 3 commits into from
Apr 19, 2023
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
1 change: 0 additions & 1 deletion src/pseudopeople/configuration/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ class Keys:
PROBABILITY = "probability"
CELL_PROBABILITY = "cell_probability"
TOKEN_PROBABILITY = "token_probability"
INCLUDE_ORIGINAL_TOKEN_PROBABILITY = "include_original_token_probability"
POSSIBLE_AGE_DIFFERENCES = "possible_age_differences"
ZIPCODE_DIGIT_PROBABILITIES = "digit_probabilities"
6 changes: 3 additions & 3 deletions src/pseudopeople/configuration/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _validate_noise_type_config(
parameter_config_validator = {
Keys.POSSIBLE_AGE_DIFFERENCES: _validate_possible_age_differences,
Keys.ZIPCODE_DIGIT_PROBABILITIES: _validate_zipcode_digit_probabilities,
}.get(parameter, _validate_standard_parameters)
}.get(parameter, _validate_probability)

_ = _get_default_config_node(
default_noise_type_config, parameter, "parameter", dataset, column, noise_type
Expand Down Expand Up @@ -161,10 +161,10 @@ def _validate_zipcode_digit_probabilities(
f"{len(noise_type_config)} probabilities ({noise_type_config})."
)
for value in noise_type_config:
_validate_standard_parameters(value, parameter, base_error_message)
_validate_probability(value, parameter, base_error_message)


def _validate_standard_parameters(
def _validate_probability(
noise_type_config: Union[int, float], parameter: str, base_error_message: str
) -> None:
if not isinstance(noise_type_config, (float, int)):
Expand Down
6 changes: 3 additions & 3 deletions src/pseudopeople/entity_types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Any, Callable, Dict
from typing import Any, Callable, Dict, Optional

import pandas as pd
from loguru import logger
Expand All @@ -25,7 +25,7 @@ class RowNoiseType:
"""

name: str
noise_function: Callable[[pd.DataFrame, ConfigTree, RandomnessStream], pd.DataFrame]
noise_function: Callable[[str, pd.DataFrame, ConfigTree, RandomnessStream], pd.DataFrame]
probability: float = 0.0

def __call__(
Expand Down Expand Up @@ -56,7 +56,7 @@ class ColumnNoiseType:

name: str
noise_function: Callable[[pd.Series, ConfigTree, RandomnessStream, Any], pd.Series]
probability: float = 0.01
probability: Optional[float] = 0.01
noise_level_scaling_function: Callable[[str], float] = lambda x: 1.0
additional_parameters: Dict[str, Any] = None

Expand Down
1 change: 0 additions & 1 deletion src/pseudopeople/noise_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class __NoiseTypes(NamedTuple):
additional_parameters={ # TODO: need to clarify these
Keys.CELL_PROBABILITY: 0.01,
Keys.TOKEN_PROBABILITY: 0.1,
Keys.INCLUDE_ORIGINAL_TOKEN_PROBABILITY: 0.1,
},
)

Expand Down
3 changes: 2 additions & 1 deletion src/pseudopeople/noise_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ def keyboard_corrupt(truth, corrupted_pr, addl_pr, rng):
return err

token_noise_level = configuration[Keys.TOKEN_PROBABILITY]
include_token_probability_level = configuration[Keys.INCLUDE_ORIGINAL_TOKEN_PROBABILITY]
# TODO: remove this hard-coding
include_token_probability_level = 0.1

rng = np.random.default_rng(seed=randomness_stream.seed)
column = column.astype(str)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_column_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ def test_generate_typographical_errors(dummy_dataset, column):
NOISE_TYPES.typographic.name: {
Keys.CELL_PROBABILITY: 0.1,
Keys.TOKEN_PROBABILITY: 0.1,
Keys.INCLUDE_ORIGINAL_TOKEN_PROBABILITY: 0.1,
},
},
},
Expand Down Expand Up @@ -598,7 +597,8 @@ def test_generate_typographical_errors(dummy_dataset, column):

# Check for expected string growth due to keeping original noised token
assert (check_noised.str.len() >= check_original.str.len()).all()
p_include_original_token = config[Keys.INCLUDE_ORIGINAL_TOKEN_PROBABILITY]
# TODO: remove this hard-coding
p_include_original_token = 0.1
p_token_does_not_increase_string_length = 1 - p_token_noise * p_include_original_token
p_strings_do_not_increase_length = (
p_token_does_not_increase_string_length**str_lengths
Expand Down