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

feat(nlp): add basic nlp transformations #40

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

AlisherAmirbek
Copy link

No description provided.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are these files?



class NGrams(Transformation):
_name_ = "NGrams"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lowercase

class NGrams(Transformation):
_name_ = "NGrams"
@beartype
def __init__(self, n: int):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow to set other parameters



class Stemming(Transformation):
_name_ = "Stemming"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lowercase

@beartype
def __init__(self):
super().__init__()
self.stemmer = PorterStemmer()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow to choose other stemmers

@beartype
def __init__(self, max_features: int, ngram_range: tuple[int, int], stop_words: list[str] | None = None):
super().__init__()
self.vectorizer = TfidfVectorizer(max_features=max_features, ngram_range=ngram_range, stop_words=stop_words)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow to set all parameters


@beartype
def execute(self, data: StrArray) -> NumericArray:
return self.vectorizer.fit_transform(data).toarray()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't apply fit_transform on test data. should be separate fit & transform

ngram_range = tuple(ngram_range)

self.ngram_range = ngram_range
self.vectorizer = CountVectorizer(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow to set all parameters



class BagOfWords(Transformation):
_name_ = 'BagOfWords'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lowercase


@beartype
def execute(self, data: StrArray) -> np.ndarray:
return self.vectorizer.fit_transform(data).toarray()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't apply fit_transform on test data. should be separate fit & transform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants