Skip to content

Commit

Permalink
remove pysbd requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
shahules786 committed Jan 9, 2025
1 parent b23371b commit d757f6a
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 45 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dependencies = [
"appdirs",
"pydantic>=2",
"openai>1",
"pysbd>=0.3.4",
"diskcache>=5.6.3",
]
dynamic = ["version", "readme"]
Expand Down
26 changes: 1 addition & 25 deletions src/ragas/metrics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from enum import Enum

from pydantic import ValidationError
from pysbd import Segmenter
from tqdm import tqdm

from ragas._analytics import EvaluationEvent, _analytics_batcher
Expand All @@ -19,12 +18,7 @@
from ragas.losses import BinaryMetricLoss, MSELoss
from ragas.prompt import FewShotPydanticPrompt, PromptMixin
from ragas.run_config import RunConfig
from ragas.utils import (
RAGAS_SUPPORTED_LANGUAGE_CODES,
camel_to_snake,
deprecated,
get_metric_language,
)
from ragas.utils import camel_to_snake, deprecated, get_metric_language

if t.TYPE_CHECKING:
from langchain_core.callbacks import Callbacks
Expand Down Expand Up @@ -694,22 +688,4 @@ def from_discrete(
return verdict_agg


def get_segmenter(
language: str = "english", clean: bool = False, char_span: bool = False
):
"""
Get a sentence segmenter for a given language
"""
language = language.lower()
if language not in RAGAS_SUPPORTED_LANGUAGE_CODES:
raise ValueError(
f"Language '{language}' not supported. Supported languages: {RAGAS_SUPPORTED_LANGUAGE_CODES.keys()}"
)
return Segmenter(
language=RAGAS_SUPPORTED_LANGUAGE_CODES[language],
clean=clean,
char_span=char_span,
)


ensembler = Ensember()
10 changes: 1 addition & 9 deletions src/ragas/prompt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from langchain_core.prompt_values import StringPromptValue
from pydantic import BaseModel

from ragas.utils import RAGAS_SUPPORTED_LANGUAGE_CODES, camel_to_snake
from ragas.utils import camel_to_snake

if t.TYPE_CHECKING:
from langchain_core.callbacks import Callbacks
Expand All @@ -17,13 +17,6 @@
logger = logging.getLogger(__name__)


def _check_if_language_is_supported(language: str):
if language not in RAGAS_SUPPORTED_LANGUAGE_CODES:
raise ValueError(
f"Language '{language}' not supported. Supported languages: {RAGAS_SUPPORTED_LANGUAGE_CODES.keys()}"
)


class BasePrompt(ABC):
def __init__(
self,
Expand All @@ -34,7 +27,6 @@ def __init__(
if name is None:
self.name = camel_to_snake(self.__class__.__name__)

_check_if_language_is_supported(language)
self.language = language
self.original_hash = original_hash

Expand Down
2 changes: 0 additions & 2 deletions src/ragas/prompt/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import typing as t

from .base import _check_if_language_is_supported
from .pydantic_prompt import PydanticPrompt

if t.TYPE_CHECKING:
Expand Down Expand Up @@ -111,7 +110,6 @@ def load_prompts(self, path: str, language: t.Optional[str] = None):
"Language not specified, loading prompts for default language: %s",
language,
)
_check_if_language_is_supported(language)

loaded_prompts = {}
for prompt_name, prompt in self.get_prompts().items():
Expand Down
5 changes: 1 addition & 4 deletions src/ragas/prompt/pydantic_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ragas.callbacks import ChainType, new_group
from ragas.exceptions import RagasOutputParserException

from .base import BasePrompt, StringIO, _check_if_language_is_supported
from .base import BasePrompt, StringIO
from .utils import extract_json, get_all_strings, update_strings

if t.TYPE_CHECKING:
Expand Down Expand Up @@ -227,9 +227,6 @@ async def adapt(
Adapt the prompt to a new language.
"""

# throws ValueError if language is not supported
_check_if_language_is_supported(target_language)

# set the original hash, this is used to
# identify the original prompt object when loading from file
if self.original_hash is None:
Expand Down
4 changes: 0 additions & 4 deletions src/ragas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@
import numpy as np
import tiktoken
from datasets import Dataset
from pysbd.languages import LANGUAGE_CODES

if t.TYPE_CHECKING:
from ragas.metrics.base import Metric

DEBUG_ENV_VAR = "RAGAS_DEBUG"
RAGAS_SUPPORTED_LANGUAGE_CODES = {
v.__name__.lower(): k for k, v in LANGUAGE_CODES.items()
}


@lru_cache(maxsize=1)
Expand Down

0 comments on commit d757f6a

Please sign in to comment.