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

Only initialize counterfitted_GLOVE_embedding when needed, massively decreasing ram usage #609

Merged
merged 2 commits into from
Mar 20, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class ThoughtVector(SentenceEncoder):
word_embedding (textattack.shared.AbstractWordEmbedding): The word embedding to use
"""

def __init__(
self, embedding=WordEmbedding.counterfitted_GLOVE_embedding(), **kwargs
):
def __init__(self, embedding=None, **kwargs):
if embedding is None:
embedding = WordEmbedding.counterfitted_GLOVE_embedding()
if not isinstance(embedding, AbstractWordEmbedding):
raise ValueError(
"`embedding` object must be of type `textattack.shared.AbstractWordEmbedding`."
Expand Down
4 changes: 3 additions & 1 deletion textattack/constraints/semantics/word_embedding_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ class WordEmbeddingDistance(Constraint):

def __init__(
self,
embedding=WordEmbedding.counterfitted_GLOVE_embedding(),
embedding=None,
include_unknown_words=True,
min_cos_sim=None,
max_mse_dist=None,
cased=False,
compare_against_original=True,
):
super().__init__(compare_against_original)
if embedding is None:
embedding = WordEmbedding.counterfitted_GLOVE_embedding()
self.include_unknown_words = include_unknown_words
self.cased = cased

Expand Down
9 changes: 3 additions & 6 deletions textattack/transformations/word_swaps/word_swap_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ class WordSwapEmbedding(WordSwap):
>>> augmenter.augment(s)
"""

def __init__(
self,
max_candidates=15,
embedding=WordEmbedding.counterfitted_GLOVE_embedding(),
**kwargs
):
def __init__(self, max_candidates=15, embedding=None, **kwargs):
super().__init__(**kwargs)
if embedding is None:
embedding = WordEmbedding.counterfitted_GLOVE_embedding()
self.max_candidates = max_candidates
if not isinstance(embedding, AbstractWordEmbedding):
raise ValueError(
Expand Down