-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
…ming transformations
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
No description provided.